Completed
Push — master ( 2dfc11...abb8d8 )
by Dwain
05:00
created
includes/class-sensei-language-pack-manager.php 2 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 	 */
92 92
 	public static function has_language_pack_available( $locale = null ) {
93 93
 
94
-        if ( is_null( $locale ) ) {
94
+		if ( is_null( $locale ) ) {
95 95
 
96 96
 			$locale = get_locale();
97 97
 
@@ -109,11 +109,11 @@  discard block
 block discarded – undo
109 109
 
110 110
 		}
111 111
 
112
-        if( isset( $_GET['translation_updated'] ) && 5 ==  $_GET['translation_updated'] ){
112
+		if( isset( $_GET['translation_updated'] ) && 5 ==  $_GET['translation_updated'] ){
113 113
 
114
-            return false;
114
+			return false;
115 115
 
116
-        }
116
+		}
117 117
 
118 118
 		$version = get_option( 'woothemes_sensei_language_pack_version', array( '0', $locale ) );
119 119
 
Please login to merge, or discard this patch.
Spacing   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if ( ! defined( 'ABSPATH' ) ) {
3
+if ( ! defined('ABSPATH')) {
4 4
 	exit; // Exit if accessed directly
5 5
 }
6 6
 
@@ -28,8 +28,8 @@  discard block
 block discarded – undo
28 28
 	 * Initialize the language pack manager
29 29
 	 */
30 30
 	public function __construct() {
31
-		add_action( 'update_option_WPLANG', array( $this, 'updated_language_option' ), 10, 2 );
32
-		add_filter( 'admin_init', array( $this, 'language_package_actions' ), 10 );
31
+		add_action('update_option_WPLANG', array($this, 'updated_language_option'), 10, 2);
32
+		add_filter('admin_init', array($this, 'language_package_actions'), 10);
33 33
 	}
34 34
 
35 35
 	/**
@@ -39,8 +39,8 @@  discard block
 block discarded – undo
39 39
 	 *
40 40
 	 * @return string
41 41
 	 */
42
-	public static function get_package_uri( $locale ) {
43
-		return self::$repo . Sensei()->version . '/packages/' . $locale . '.zip';
42
+	public static function get_package_uri($locale) {
43
+		return self::$repo.Sensei()->version.'/packages/'.$locale.'.zip';
44 44
 	}
45 45
 
46 46
 	/**
@@ -50,8 +50,8 @@  discard block
 block discarded – undo
50 50
 	 *
51 51
 	 * @return string
52 52
 	 */
53
-	protected static function get_settings_uri( $action ) {
54
-		return wp_nonce_url( admin_url( 'admin.php?page=woothemes-sensei-settings&action=' . $action ), 'language_pack', '_sensei_language_nonce' );
53
+	protected static function get_settings_uri($action) {
54
+		return wp_nonce_url(admin_url('admin.php?page=woothemes-sensei-settings&action='.$action), 'language_pack', '_sensei_language_nonce');
55 55
 	}
56 56
 
57 57
 	/**
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 	 * @return string
61 61
 	 */
62 62
 	public static function get_install_uri() {
63
-		return self::get_settings_uri( 'language_pack_install' );
63
+		return self::get_settings_uri('language_pack_install');
64 64
 	}
65 65
 
66 66
 	/**
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 	 * @return string
70 70
 	 */
71 71
 	public static function get_dismiss_uri() {
72
-		return self::get_settings_uri( 'dismiss_language_pack_notice' );
72
+		return self::get_settings_uri('dismiss_language_pack_notice');
73 73
 	}
74 74
 
75 75
 	/**
@@ -78,8 +78,8 @@  discard block
 block discarded – undo
78 78
 	 * @param string $old
79 79
 	 * @param string $new
80 80
 	 */
81
-	public function updated_language_option( $old, $new ) {
82
-		self::has_language_pack_available( $new );
81
+	public function updated_language_option($old, $new) {
82
+		self::has_language_pack_available($new);
83 83
 	}
84 84
 
85 85
 	/**
@@ -89,42 +89,42 @@  discard block
 block discarded – undo
89 89
 	 *
90 90
 	 * @return bool
91 91
 	 */
92
-	public static function has_language_pack_available( $locale = null ) {
92
+	public static function has_language_pack_available($locale = null) {
93 93
 
94
-        if ( is_null( $locale ) ) {
94
+        if (is_null($locale)) {
95 95
 
96 96
 			$locale = get_locale();
97 97
 
98 98
 		}
99 99
 
100
-		if ( 'en_US' === $locale ) {
100
+		if ('en_US' === $locale) {
101 101
 
102 102
 			return false;
103 103
 
104 104
 		}
105 105
 
106
-		if ( 'yes' === get_option( 'sensei_needs_language_pack_install' ) ) {
106
+		if ('yes' === get_option('sensei_needs_language_pack_install')) {
107 107
 
108 108
 			return true;
109 109
 
110 110
 		}
111 111
 
112
-        if( isset( $_GET['translation_updated'] ) && 5 ==  $_GET['translation_updated'] ){
112
+        if (isset($_GET['translation_updated']) && 5 == $_GET['translation_updated']) {
113 113
 
114 114
             return false;
115 115
 
116 116
         }
117 117
 
118
-		$version = get_option( 'woothemes_sensei_language_pack_version', array( '0', $locale ) );
118
+		$version = get_option('woothemes_sensei_language_pack_version', array('0', $locale));
119 119
 
120
-		if ( ! is_array( $version ) || version_compare( $version[0], Sensei()->version, '<' ) || $version[1] !== $locale ) {
121
-			if ( self::check_if_language_pack_exists( $locale ) ) {
122
-				update_option( 'sensei_needs_language_pack_install', 'yes' );
120
+		if ( ! is_array($version) || version_compare($version[0], Sensei()->version, '<') || $version[1] !== $locale) {
121
+			if (self::check_if_language_pack_exists($locale)) {
122
+				update_option('sensei_needs_language_pack_install', 'yes');
123 123
 
124 124
 				return true;
125 125
 			} else {
126 126
 				// Updated the woothemes_sensei_language_pack_version to avoid searching translations for this release again
127
-				self::update_language_pack_version( $locale );
127
+				self::update_language_pack_version($locale);
128 128
 			}
129 129
 		}
130 130
 
@@ -137,10 +137,10 @@  discard block
 block discarded – undo
137 137
 	 *
138 138
 	 * @return bool
139 139
 	 */
140
-	public static function check_if_language_pack_exists( $locale ) {
141
-		$response = wp_safe_remote_get( self::get_package_uri( $locale ), array( 'timeout' => 60 ) );
140
+	public static function check_if_language_pack_exists($locale) {
141
+		$response = wp_safe_remote_get(self::get_package_uri($locale), array('timeout' => 60));
142 142
 
143
-		if ( ! is_wp_error( $response ) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 ) {
143
+		if ( ! is_wp_error($response) && $response['response']['code'] >= 200 && $response['response']['code'] < 300) {
144 144
 			return true;
145 145
 		} else {
146 146
 			return false;
@@ -152,12 +152,12 @@  discard block
 block discarded – undo
152 152
 	 *
153 153
 	 * @param string $locale
154 154
 	 */
155
-	public static function update_language_pack_version( $locale ) {
155
+	public static function update_language_pack_version($locale) {
156 156
 		// Update the language pack version
157
-		update_option( 'woothemes_sensei_language_pack_version', array( Sensei()->version, $locale ) );
157
+		update_option('woothemes_sensei_language_pack_version', array(Sensei()->version, $locale));
158 158
 
159 159
 		// Remove the translation upgrade notice
160
-		update_option( 'sensei_needs_language_pack_install', 'no' );
160
+		update_option('sensei_needs_language_pack_install', 'no');
161 161
 	}
162 162
 
163 163
 	/**
@@ -166,17 +166,17 @@  discard block
 block discarded – undo
166 166
 	public function language_package_actions() {
167 167
 		if (
168 168
 			is_admin()
169
-			&& current_user_can( 'update_plugins' )
170
-			&& isset( $_GET['page'] )
169
+			&& current_user_can('update_plugins')
170
+			&& isset($_GET['page'])
171 171
 			&& 'woothemes-sensei-settings' === $_GET['page']
172
-			&& isset( $_GET['action'] )
172
+			&& isset($_GET['action'])
173 173
 		) {
174 174
 
175
-			if ( 'language_pack_install' === $_GET['action'] ) {
175
+			if ('language_pack_install' === $_GET['action']) {
176 176
 				$this->language_pack_install();
177 177
 			}
178 178
 
179
-			if ( 'dismiss_language_pack_notice' ) {
179
+			if ('dismiss_language_pack_notice') {
180 180
 				$this->dismiss_language_pack_notice();
181 181
 			}
182 182
 		}
@@ -186,66 +186,66 @@  discard block
 block discarded – undo
186 186
 	 * Install language pack.
187 187
 	 */
188 188
 	protected function language_pack_install() {
189
-		$url          = wp_nonce_url( admin_url( 'admin.php?page=woothemes-sensei-settings&action=language_pack_install' ), 'language_install' );
190
-		$settings_url = admin_url( 'admin.php?page=woothemes-sensei-settings' );
189
+		$url          = wp_nonce_url(admin_url('admin.php?page=woothemes-sensei-settings&action=language_pack_install'), 'language_install');
190
+		$settings_url = admin_url('admin.php?page=woothemes-sensei-settings');
191 191
 		$locale       = get_locale();
192 192
 
193
-		if ( ! isset( $_REQUEST['_sensei_language_nonce'] ) && wp_verify_nonce( $_REQUEST['_sensei_language_nonce'], 'language_pack' ) ) {
194
-			wp_redirect( add_query_arg( array( 'translation_updated' => 2 ), $settings_url ) );
193
+		if ( ! isset($_REQUEST['_sensei_language_nonce']) && wp_verify_nonce($_REQUEST['_sensei_language_nonce'], 'language_pack')) {
194
+			wp_redirect(add_query_arg(array('translation_updated' => 2), $settings_url));
195 195
 			exit;
196 196
 		}
197 197
 
198
-		if ( 'en_US' === $locale || ! self::check_if_language_pack_exists( $locale ) ) {
199
-			wp_redirect( add_query_arg( array( 'translation_updated' => 3 ), $settings_url ) );
198
+		if ('en_US' === $locale || ! self::check_if_language_pack_exists($locale)) {
199
+			wp_redirect(add_query_arg(array('translation_updated' => 3), $settings_url));
200 200
 			exit;
201 201
 		}
202 202
 
203
-		if ( false === ( $creds = request_filesystem_credentials( $url, '', false, false, null ) ) ) {
204
-			wp_redirect( add_query_arg( array( 'translation_updated' => 4 ), $settings_url ) );
203
+		if (false === ($creds = request_filesystem_credentials($url, '', false, false, null))) {
204
+			wp_redirect(add_query_arg(array('translation_updated' => 4), $settings_url));
205 205
 			exit;
206 206
 		}
207 207
 
208
-		if ( ! WP_Filesystem( $creds ) ) {
209
-			request_filesystem_credentials( $url, '', true, false, null );
208
+		if ( ! WP_Filesystem($creds)) {
209
+			request_filesystem_credentials($url, '', true, false, null);
210 210
 
211
-			wp_redirect( add_query_arg( array( 'translation_updated' => 4 ), $settings_url ) );
211
+			wp_redirect(add_query_arg(array('translation_updated' => 4), $settings_url));
212 212
 			exit;
213 213
 		}
214 214
 
215 215
 		// Download the language pack
216
-		$response = wp_safe_remote_get( self::get_package_uri( $locale ), array( 'timeout' => 60 ) );
217
-		if ( ! is_wp_error( $response ) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 ) {
216
+		$response = wp_safe_remote_get(self::get_package_uri($locale), array('timeout' => 60));
217
+		if ( ! is_wp_error($response) && $response['response']['code'] >= 200 && $response['response']['code'] < 300) {
218 218
 			global $wp_filesystem;
219 219
 
220 220
 			$upload_dir = wp_upload_dir();
221
-			$file       = trailingslashit( $upload_dir['path'] ) . $locale . '.zip';
221
+			$file       = trailingslashit($upload_dir['path']).$locale.'.zip';
222 222
 
223 223
 			// Save the zip file
224
-			if ( ! $wp_filesystem->put_contents( $file, $response['body'], FS_CHMOD_FILE ) ) {
225
-				wp_redirect( add_query_arg( array( 'translation_updated' => 4 ), $settings_url ) );
224
+			if ( ! $wp_filesystem->put_contents($file, $response['body'], FS_CHMOD_FILE)) {
225
+				wp_redirect(add_query_arg(array('translation_updated' => 4), $settings_url));
226 226
 				exit;
227 227
 			}
228 228
 
229 229
 			// Unzip the file to wp-content/languages/plugins directory
230
-			$dir   = trailingslashit( WP_LANG_DIR ) . 'plugins/';
231
-			$unzip = unzip_file( $file, $dir );
232
-			if ( true !== $unzip ) {
233
-				wp_redirect( add_query_arg( array( 'translation_updated' => 4 ), $settings_url ) );
230
+			$dir   = trailingslashit(WP_LANG_DIR).'plugins/';
231
+			$unzip = unzip_file($file, $dir);
232
+			if (true !== $unzip) {
233
+				wp_redirect(add_query_arg(array('translation_updated' => 4), $settings_url));
234 234
 				exit;
235 235
 			}
236 236
 
237 237
 			// Delete the package file
238
-			$wp_filesystem->delete( $file );
238
+			$wp_filesystem->delete($file);
239 239
 
240 240
 			// Update version and remove notice
241
-			self::update_language_pack_version( $locale );
241
+			self::update_language_pack_version($locale);
242 242
 
243 243
 			// Redirect and show a success message
244
-			wp_redirect( add_query_arg( array( 'translation_updated' => 1 ), $settings_url ) );
244
+			wp_redirect(add_query_arg(array('translation_updated' => 1), $settings_url));
245 245
 			exit;
246 246
 		} else {
247 247
 			// Don't have a valid package for the current language!
248
-			wp_redirect( add_query_arg( array( 'translation_updated' => 5 ), $settings_url ) );
248
+			wp_redirect(add_query_arg(array('translation_updated' => 5), $settings_url));
249 249
 			exit;
250 250
 		}
251 251
 	}
@@ -254,38 +254,38 @@  discard block
 block discarded – undo
254 254
 	 * Hide language pack notice.
255 255
 	 */
256 256
 	protected function dismiss_language_pack_notice() {
257
-		if ( ! isset( $_REQUEST['_sensei_language_nonce'] ) && wp_verify_nonce( $_REQUEST['_sensei_language_nonce'], 'language_pack' ) ) {
258
-			wp_die( __( 'Cheatin&#8217; huh?', 'woothemes-sensei' ) );
257
+		if ( ! isset($_REQUEST['_sensei_language_nonce']) && wp_verify_nonce($_REQUEST['_sensei_language_nonce'], 'language_pack')) {
258
+			wp_die(__('Cheatin&#8217; huh?', 'woothemes-sensei'));
259 259
 		}
260 260
 
261 261
 		// Update version and remove notice
262
-		self::update_language_pack_version( get_locale() );
262
+		self::update_language_pack_version(get_locale());
263 263
 	}
264 264
 
265 265
 	/**
266 266
 	 * Language pack messages
267 267
 	 */
268 268
 	public static function messages() {
269
-		if ( empty( $_GET['translation_updated'] ) ) {
269
+		if (empty($_GET['translation_updated'])) {
270 270
 			return;
271 271
 		}
272 272
 
273
-		switch ( $_GET['translation_updated'] ) {
273
+		switch ($_GET['translation_updated']) {
274 274
 			case 2 :
275
-				echo '<div class="error"><p>' . __( 'Failed to install/update the translation:', 'woothemes-sensei' ) . ' ' . __( 'Seems you don\'t have permission to do this!', 'woothemes-sensei' ) . '</p></div>';
275
+				echo '<div class="error"><p>'.__('Failed to install/update the translation:', 'woothemes-sensei').' '.__('Seems you don\'t have permission to do this!', 'woothemes-sensei').'</p></div>';
276 276
 				break;
277 277
 			case 3 :
278
-				echo '<div class="error"><p>' . __( 'Failed to install/update the translation:', 'woothemes-sensei' ) . ' ' . __( 'There is no translation available for your language!', 'woothemes-sensei' ) . '</p></div>';
278
+				echo '<div class="error"><p>'.__('Failed to install/update the translation:', 'woothemes-sensei').' '.__('There is no translation available for your language!', 'woothemes-sensei').'</p></div>';
279 279
 				break;
280 280
 			case 4 :
281
-				echo '<div class="error"><p>' . __( 'Failed to install/update the translation:', 'woothemes-sensei' ) . ' ' . sprintf( __( 'An authentication error occurred while updating the translation. Please try again or configure your %sUpgrade Constants%s.', 'woothemes-sensei' ), '<a href="http://codex.wordpress.org/Editing_wp-config.php#WordPress_Upgrade_Constants">', '</a>' ) . '</p></div>';
281
+				echo '<div class="error"><p>'.__('Failed to install/update the translation:', 'woothemes-sensei').' '.sprintf(__('An authentication error occurred while updating the translation. Please try again or configure your %sUpgrade Constants%s.', 'woothemes-sensei'), '<a href="http://codex.wordpress.org/Editing_wp-config.php#WordPress_Upgrade_Constants">', '</a>').'</p></div>';
282 282
 				break;
283 283
 			case 5 :
284
-				echo '<div class="error"><p>' . __( 'Failed to install/update the translation:', 'woothemes-sensei' ) . ' ' . __( 'Sorry but there is no translation available for your language =/', 'woothemes-sensei' ) . '</p></div>';
284
+				echo '<div class="error"><p>'.__('Failed to install/update the translation:', 'woothemes-sensei').' '.__('Sorry but there is no translation available for your language =/', 'woothemes-sensei').'</p></div>';
285 285
 				break;
286 286
 
287 287
 			default :
288
-				echo '<div class="updated"><p>' . __( 'Translations installed/updated successfully!', 'woothemes-sensei' ) . '</p></div>';
288
+				echo '<div class="updated"><p>'.__('Translations installed/updated successfully!', 'woothemes-sensei').'</p></div>';
289 289
 				break;
290 290
 		}
291 291
 	}
Please login to merge, or discard this patch.
includes/class-sensei.php 2 patches
Indentation   +1328 added lines, -1328 removed lines patch added patch discarded remove patch
@@ -14,1347 +14,1347 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class Sensei_Main {
16 16
 
17
-    /**
18
-     * @var string
19
-     * Reference to the main plugin file
20
-     */
21
-    private $file;
22
-
23
-    /**
24
-     * @var Sensei_Main $_instance to the the main and only instance of the Sensei class.
25
-     * @since 1.8.0
26
-     */
27
-    protected static $_instance = null;
28
-
29
-    /**
30
-     * Main reference to the plugins current version
31
-     */
32
-    public $version;
33
-
34
-    /**
35
-     * Public token, referencing for the text domain.
36
-     */
37
-    public $token = 'woothemes-sensei';
38
-
39
-    /**
40
-     * Plugin url and path for use when access resources.
41
-     */
42
-    public $plugin_url;
43
-    public $plugin_path;
44
-    public $template_url;
45
-
46
-    /**
47
-     * @var Sensei_PostTypes
48
-     * All Sensei sub classes. Currently used to access functionality contained within
49
-     * within Sensei sub classes e.g. Sensei()->course->all_courses()
50
-     */
51
-    public $post_types;
52
-
53
-    /**
54
-     * @var WooThemes_Sensei_Settings
55
-     */
56
-    public $settings;
57
-
58
-    /**
59
-     * @var WooThemes_Sensei_Course_Results
60
-     */
61
-    public $course_results;
62
-
63
-    /**
64
-     * @var Sensei_Updates
65
-     */
66
-    public $updates;
67
-    /**
68
-     * @var WooThemes_Sensei_Course
69
-     */
70
-    public $course;
71
-
72
-    /**
73
-     * @var WooThemes_Sensei_Lesson
74
-     */
75
-    public $lesson;
76
-
77
-    /**
78
-     * @var WooThemes_Sensei_Quiz
79
-     */
80
-    public $quiz;
81
-
82
-    /**
83
-     * @var WooThemes_Sensei_Question
84
-     */
85
-    public $question;
86
-
87
-    /**
88
-     * @var WooThemes_Sensei_Admin
89
-     */
90
-    public $admin;
91
-
92
-    /**
93
-     * @var WooThemes_Sensei_Frontend
94
-     */
95
-    public $frontend;
96
-
97
-    /**
98
-     * @var Sensei_Notices
99
-     */
100
-    public $notices;
101
-
102
-    /**
103
-     * @var WooThemes_Sensei_Grading
104
-     */
105
-    public $grading;
106
-
107
-    /**
108
-     * @var WooThemes_Sensei_Emails
109
-     */
110
-    public $emails;
111
-
112
-    /**
113
-     * @var WooThemes_Sensei_Learner_Profiles
114
-     */
115
-    public $learner_profiles;
116
-
117
-    /**
118
-     * @var Sensei_Teacher
119
-     */
120
-    public $teacher;
121
-
122
-    /**
123
-     * @var WooThemes_Sensei_Learners
124
-     */
125
-    public $learners;
126
-
127
-    /**
128
-     * @var array
129
-     * Global instance for access to the permissions message shown
130
-     * when users do not have the right privileges to access resources.
131
-     */
132
-    public $permissions_message;
133
-
134
-    /**
135
-     * @var Sensei_Core_Modules Sensei Modules functionality
136
-     */
137
-    public $modules;
138
-
139
-    /**
140
-     * @var Sensei_Analysis
141
-     */
142
-    public $analysis;
143
-
144
-    /**
145
-     * Constructor method.
146
-     * @param  string $file The base file of the plugin.
147
-     * @since  1.0.0
148
-     */
149
-    public function __construct ( $file ) {
150
-
151
-        // Setup object data
152
-        $this->file = $file;
153
-        $this->plugin_url = trailingslashit( plugins_url( '', $plugin = $file ) );
154
-        $this->plugin_path = trailingslashit( dirname( $file ) );
155
-        $this->template_url	= apply_filters( 'sensei_template_url', 'sensei/' );
156
-        $this->permissions_message = array( 'title' => __( 'Permission Denied', 'woothemes-sensei' ), 'message' => __( 'Unfortunately you do not have permissions to access this page.', 'woothemes-sensei' ) );
157
-
158
-        // Initialize the core Sensei functionality
159
-        $this->init();
160
-
161
-        // Installation
162
-        if ( is_admin() && ! defined( 'DOING_AJAX' ) ) $this->install();
163
-
164
-        // Run this on activation.
165
-        register_activation_hook( $this->file, array( $this, 'activation' ) );
166
-
167
-        // Image Sizes
168
-        $this->init_image_sizes();
169
-
170
-        // Force WooCommerce Required Settings
171
-        $this->set_woocommerce_functionality();
172
-
173
-        // load all hooks
174
-        $this->load_hooks();
175
-
176
-    } // End __construct()
177
-
178
-    /**
179
-     * Load the foundations of Sensei.
180
-     * @since 1.9.0
181
-     */
182
-    protected function init(){
183
-
184
-        // Localisation
185
-        $this->load_plugin_textdomain();
186
-        add_action( 'init', array( $this, 'load_localisation' ), 0 );
187
-
188
-        // load the shortcode loader into memory, so as to listen to all for
189
-        // all shortcodes on the front end
190
-        new Sensei_Shortcode_Loader();
191
-
192
-    }
193
-
194
-    /**
195
-     * Global Sensei Instance
196
-     *
197
-     * Ensure that only one instance of the main Sensei class can be loaded.
198
-     *
199
-     * @since 1.8.0
200
-     * @static
201
-     * @see WC()
202
-     * @return WooThemes_Sensei Instance.
203
-     */
204
-    public static function instance() {
17
+	/**
18
+	 * @var string
19
+	 * Reference to the main plugin file
20
+	 */
21
+	private $file;
22
+
23
+	/**
24
+	 * @var Sensei_Main $_instance to the the main and only instance of the Sensei class.
25
+	 * @since 1.8.0
26
+	 */
27
+	protected static $_instance = null;
28
+
29
+	/**
30
+	 * Main reference to the plugins current version
31
+	 */
32
+	public $version;
33
+
34
+	/**
35
+	 * Public token, referencing for the text domain.
36
+	 */
37
+	public $token = 'woothemes-sensei';
38
+
39
+	/**
40
+	 * Plugin url and path for use when access resources.
41
+	 */
42
+	public $plugin_url;
43
+	public $plugin_path;
44
+	public $template_url;
45
+
46
+	/**
47
+	 * @var Sensei_PostTypes
48
+	 * All Sensei sub classes. Currently used to access functionality contained within
49
+	 * within Sensei sub classes e.g. Sensei()->course->all_courses()
50
+	 */
51
+	public $post_types;
52
+
53
+	/**
54
+	 * @var WooThemes_Sensei_Settings
55
+	 */
56
+	public $settings;
57
+
58
+	/**
59
+	 * @var WooThemes_Sensei_Course_Results
60
+	 */
61
+	public $course_results;
62
+
63
+	/**
64
+	 * @var Sensei_Updates
65
+	 */
66
+	public $updates;
67
+	/**
68
+	 * @var WooThemes_Sensei_Course
69
+	 */
70
+	public $course;
71
+
72
+	/**
73
+	 * @var WooThemes_Sensei_Lesson
74
+	 */
75
+	public $lesson;
76
+
77
+	/**
78
+	 * @var WooThemes_Sensei_Quiz
79
+	 */
80
+	public $quiz;
81
+
82
+	/**
83
+	 * @var WooThemes_Sensei_Question
84
+	 */
85
+	public $question;
86
+
87
+	/**
88
+	 * @var WooThemes_Sensei_Admin
89
+	 */
90
+	public $admin;
91
+
92
+	/**
93
+	 * @var WooThemes_Sensei_Frontend
94
+	 */
95
+	public $frontend;
96
+
97
+	/**
98
+	 * @var Sensei_Notices
99
+	 */
100
+	public $notices;
101
+
102
+	/**
103
+	 * @var WooThemes_Sensei_Grading
104
+	 */
105
+	public $grading;
106
+
107
+	/**
108
+	 * @var WooThemes_Sensei_Emails
109
+	 */
110
+	public $emails;
111
+
112
+	/**
113
+	 * @var WooThemes_Sensei_Learner_Profiles
114
+	 */
115
+	public $learner_profiles;
116
+
117
+	/**
118
+	 * @var Sensei_Teacher
119
+	 */
120
+	public $teacher;
121
+
122
+	/**
123
+	 * @var WooThemes_Sensei_Learners
124
+	 */
125
+	public $learners;
126
+
127
+	/**
128
+	 * @var array
129
+	 * Global instance for access to the permissions message shown
130
+	 * when users do not have the right privileges to access resources.
131
+	 */
132
+	public $permissions_message;
133
+
134
+	/**
135
+	 * @var Sensei_Core_Modules Sensei Modules functionality
136
+	 */
137
+	public $modules;
138
+
139
+	/**
140
+	 * @var Sensei_Analysis
141
+	 */
142
+	public $analysis;
143
+
144
+	/**
145
+	 * Constructor method.
146
+	 * @param  string $file The base file of the plugin.
147
+	 * @since  1.0.0
148
+	 */
149
+	public function __construct ( $file ) {
150
+
151
+		// Setup object data
152
+		$this->file = $file;
153
+		$this->plugin_url = trailingslashit( plugins_url( '', $plugin = $file ) );
154
+		$this->plugin_path = trailingslashit( dirname( $file ) );
155
+		$this->template_url	= apply_filters( 'sensei_template_url', 'sensei/' );
156
+		$this->permissions_message = array( 'title' => __( 'Permission Denied', 'woothemes-sensei' ), 'message' => __( 'Unfortunately you do not have permissions to access this page.', 'woothemes-sensei' ) );
157
+
158
+		// Initialize the core Sensei functionality
159
+		$this->init();
160
+
161
+		// Installation
162
+		if ( is_admin() && ! defined( 'DOING_AJAX' ) ) $this->install();
163
+
164
+		// Run this on activation.
165
+		register_activation_hook( $this->file, array( $this, 'activation' ) );
166
+
167
+		// Image Sizes
168
+		$this->init_image_sizes();
169
+
170
+		// Force WooCommerce Required Settings
171
+		$this->set_woocommerce_functionality();
172
+
173
+		// load all hooks
174
+		$this->load_hooks();
175
+
176
+	} // End __construct()
177
+
178
+	/**
179
+	 * Load the foundations of Sensei.
180
+	 * @since 1.9.0
181
+	 */
182
+	protected function init(){
183
+
184
+		// Localisation
185
+		$this->load_plugin_textdomain();
186
+		add_action( 'init', array( $this, 'load_localisation' ), 0 );
187
+
188
+		// load the shortcode loader into memory, so as to listen to all for
189
+		// all shortcodes on the front end
190
+		new Sensei_Shortcode_Loader();
191
+
192
+	}
193
+
194
+	/**
195
+	 * Global Sensei Instance
196
+	 *
197
+	 * Ensure that only one instance of the main Sensei class can be loaded.
198
+	 *
199
+	 * @since 1.8.0
200
+	 * @static
201
+	 * @see WC()
202
+	 * @return WooThemes_Sensei Instance.
203
+	 */
204
+	public static function instance() {
205 205
 
206
-        if ( is_null( self::$_instance ) ) {
206
+		if ( is_null( self::$_instance ) ) {
207 207
 
208
-            //Sensei requires a reference to the main Sensei plugin file
209
-            $sensei_main_plugin_file = dirname ( dirname( __FILE__ ) ) . '/woothemes-sensei.php';
208
+			//Sensei requires a reference to the main Sensei plugin file
209
+			$sensei_main_plugin_file = dirname ( dirname( __FILE__ ) ) . '/woothemes-sensei.php';
210 210
 
211
-            self::$_instance = new self( $sensei_main_plugin_file  );
211
+			self::$_instance = new self( $sensei_main_plugin_file  );
212 212
 
213
-            // load the global class objects needed throughout Sensei
214
-            self::$_instance->initialize_global_objects();
213
+			// load the global class objects needed throughout Sensei
214
+			self::$_instance->initialize_global_objects();
215 215
 
216
-        }
216
+		}
217 217
 
218
-        return self::$_instance;
218
+		return self::$_instance;
219 219
 
220
-    } // end instance()
220
+	} // end instance()
221 221
 
222
-    /**
223
-     * This function is linked into the activation
224
-     * hook to reset flush the urls to ensure Sensei post types show up.
225
-     *
226
-     * @since 1.9.0
227
-     *
228
-     * @param $plugin
229
-     */
230
-    public static function activation_flush_rules( $plugin ){
222
+	/**
223
+	 * This function is linked into the activation
224
+	 * hook to reset flush the urls to ensure Sensei post types show up.
225
+	 *
226
+	 * @since 1.9.0
227
+	 *
228
+	 * @param $plugin
229
+	 */
230
+	public static function activation_flush_rules( $plugin ){
231 231
 
232
-        if( strpos( $plugin, '/woothemes-sensei.php' ) > 0  ){
232
+		if( strpos( $plugin, '/woothemes-sensei.php' ) > 0  ){
233 233
 
234
-            flush_rewrite_rules(true);
234
+			flush_rewrite_rules(true);
235 235
 
236
-        }
236
+		}
237 237
 
238
-    }
238
+	}
239 239
 
240
-    /**
241
-     * Cloning is forbidden.
242
-     * @since 1.8.0
243
-     */
244
-    public function __clone() {
245
-        _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'woothemes-sensei' ), '1.8' );
246
-    }
240
+	/**
241
+	 * Cloning is forbidden.
242
+	 * @since 1.8.0
243
+	 */
244
+	public function __clone() {
245
+		_doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'woothemes-sensei' ), '1.8' );
246
+	}
247 247
 
248
-    /**
249
-     * Unserializing instances of this class is forbidden.
250
-     * @since 1.8.0
251
-     */
252
-    public function __wakeup() {
253
-        _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'woothemes-sensei' ), '1.8' );
254
-    }
248
+	/**
249
+	 * Unserializing instances of this class is forbidden.
250
+	 * @since 1.8.0
251
+	 */
252
+	public function __wakeup() {
253
+		_doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'woothemes-sensei' ), '1.8' );
254
+	}
255 255
 
256
-    /**
257
-     * Load the properties for the main Sensei object
258
-     *
259
-     * @since 1.9.0
260
-     */
261
-    public function initialize_global_objects(){
256
+	/**
257
+	 * Load the properties for the main Sensei object
258
+	 *
259
+	 * @since 1.9.0
260
+	 */
261
+	public function initialize_global_objects(){
262 262
 
263
-        // Setup post types.
264
-        $this->post_types = new Sensei_PostTypes();
263
+		// Setup post types.
264
+		$this->post_types = new Sensei_PostTypes();
265 265
 
266
-        // Lad the updates class
267
-        $this->updates = new Sensei_Updates( $this );
266
+		// Lad the updates class
267
+		$this->updates = new Sensei_Updates( $this );
268 268
 
269
-        // Setup settings
270
-        $this->settings = new Sensei_Settings();
269
+		// Setup settings
270
+		$this->settings = new Sensei_Settings();
271 271
 
272
-        // Load Course Results Class
273
-        $this->course_results = new Sensei_Course_Results();
272
+		// Load Course Results Class
273
+		$this->course_results = new Sensei_Course_Results();
274 274
 
275
-        // Load the teacher role
276
-        $this->teacher = new Sensei_Teacher();
275
+		// Load the teacher role
276
+		$this->teacher = new Sensei_Teacher();
277 277
 
278
-        // Add the Course class
279
-        $this->course = $this->post_types->course;
278
+		// Add the Course class
279
+		$this->course = $this->post_types->course;
280 280
 
281
-        // Add the lesson class
282
-        $this->lesson = $this->post_types->lesson;
281
+		// Add the lesson class
282
+		$this->lesson = $this->post_types->lesson;
283 283
 
284
-        // Add the question class
285
-        $this->question = $this->post_types->question;
284
+		// Add the question class
285
+		$this->question = $this->post_types->question;
286 286
 
287
-        //Add the quiz class
288
-        $this->quiz = $this->post_types->quiz;
287
+		//Add the quiz class
288
+		$this->quiz = $this->post_types->quiz;
289 289
 
290
-        // load the modules class after all plugsin are loaded
291
-        add_action( 'plugins_loaded', array( $this, 'load_modules_class' ) );
290
+		// load the modules class after all plugsin are loaded
291
+		add_action( 'plugins_loaded', array( $this, 'load_modules_class' ) );
292 292
 
293
-        // Load Learner Management Functionality
294
-        $this->learners = new Sensei_Learner_Management( $this->file );
293
+		// Load Learner Management Functionality
294
+		$this->learners = new Sensei_Learner_Management( $this->file );
295 295
 
296
-        // Differentiate between administration and frontend logic.
297
-        if ( is_admin() ) {
296
+		// Differentiate between administration and frontend logic.
297
+		if ( is_admin() ) {
298 298
 
299
-            // Load Admin Welcome class
300
-            new Sensei_Welcome();
299
+			// Load Admin Welcome class
300
+			new Sensei_Welcome();
301 301
 
302
-            // Load Admin Class
303
-            $this->admin = new Sensei_Admin( $this->file );
302
+			// Load Admin Class
303
+			$this->admin = new Sensei_Admin( $this->file );
304 304
 
305
-            // Load Analysis Reports
306
-            $this->analysis = new Sensei_Analysis( $this->file );
305
+			// Load Analysis Reports
306
+			$this->analysis = new Sensei_Analysis( $this->file );
307 307
 
308
-        } else {
308
+		} else {
309 309
 
310
-            // Load Frontend Class
311
-            $this->frontend = new Sensei_Frontend();
310
+			// Load Frontend Class
311
+			$this->frontend = new Sensei_Frontend();
312 312
 
313
-            // Load notice Class
314
-            $this->notices = new Sensei_Notices();
313
+			// Load notice Class
314
+			$this->notices = new Sensei_Notices();
315 315
 
316
-            // Load built in themes support integration
317
-            new Sensei_Theme_Integration_Loader();
316
+			// Load built in themes support integration
317
+			new Sensei_Theme_Integration_Loader();
318 318
 
319 319
 
320
-        }
320
+		}
321 321
 
322
-        // Load Grading Functionality
323
-        $this->grading = new Sensei_Grading( $this->file );
322
+		// Load Grading Functionality
323
+		$this->grading = new Sensei_Grading( $this->file );
324 324
 
325
-        // Load Email Class
326
-        $this->emails = new Sensei_Emails( $this->file );
325
+		// Load Email Class
326
+		$this->emails = new Sensei_Emails( $this->file );
327 327
 
328
-        // Load Learner Profiles Class
329
-        $this->learner_profiles = new Sensei_Learner_Profiles();
328
+		// Load Learner Profiles Class
329
+		$this->learner_profiles = new Sensei_Learner_Profiles();
330 330
 
331
-    }
331
+	}
332 332
 
333
-    /**
334
-     * Initialize all Sensei hooks
335
-     *
336
-     * @since 1.9.0
337
-     */
338
-    public function load_hooks(){
339
-
340
-        add_action( 'widgets_init', array( $this, 'register_widgets' ) );
341
-        add_action( 'after_setup_theme', array( $this, 'ensure_post_thumbnails_support' ) );
342
-
343
-        // WooCommerce Payment Actions
344
-        add_action( 'woocommerce_payment_complete' , array( $this, 'sensei_woocommerce_complete_order' ) );
345
-        add_action( 'woocommerce_thankyou' , array( $this, 'sensei_woocommerce_complete_order' ) );
346
-        add_action( 'woocommerce_order_status_completed' , array( $this, 'sensei_woocommerce_complete_order' ) );
347
-        add_action( 'woocommerce_order_status_processing' , array( $this, 'sensei_woocommerce_complete_order' ) );
348
-        add_action( 'woocommerce_order_status_cancelled' , array( $this, 'sensei_woocommerce_cancel_order' ) );
349
-        add_action( 'woocommerce_order_status_refunded' , array( $this, 'sensei_woocommerce_cancel_order' ) );
350
-        add_action( 'subscriptions_activated_for_order', array( $this, 'sensei_activate_subscription' ) );
351
-
352
-        // WooCommerce Subscriptions Actions
353
-        add_action( 'reactivated_subscription', array( $this, 'sensei_woocommerce_reactivate_subscription' ), 10, 2 );
354
-        add_action( 'subscription_expired' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 );
355
-        add_action( 'subscription_end_of_prepaid_term' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 );
356
-        add_action( 'cancelled_subscription' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 );
357
-        add_action( 'subscription_put_on-hold' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 );
358
-
359
-        // Add Email link to course orders
360
-        add_action( 'woocommerce_email_after_order_table', array( $this, 'sensei_woocommerce_email_course_details' ), 10, 1 );
361
-
362
-        // Filter comment counts
363
-        add_filter( 'wp_count_comments', array( $this, 'sensei_count_comments' ), 10, 2 );
364
-
365
-        add_action( 'body_class', array( $this, 'body_class' ) );
366
-
367
-        // Check for and activate JetPack LaTeX support
368
-        add_action( 'plugins_loaded', array( $this, 'jetpack_latex_support'), 200 ); // Runs after Jetpack has loaded it's modules
369
-
370
-        // check flush the rewrite rules if the option sensei_flush_rewrite_rules option is 1
371
-        add_action( 'init', array( $this, 'flush_rewrite_rules'), 101 );
372
-
373
-    }
374
-
375
-    /**
376
-     * Run Sensei updates.
377
-     * @access  public
378
-     * @since   1.1.0
379
-     * @return  void
380
-     */
381
-    public function run_updates() {
382
-        // Run updates if administrator
383
-        if ( current_user_can( 'manage_options' ) || current_user_can( 'manage_sensei' ) ) {
384
-
385
-            $this->updates->update();
386
-
387
-        } // End If Statement
388
-    } // End run_updates()
389
-
390
-
391
-
392
-    /**
393
-     * Setup required WooCommerce settings.
394
-     * @access  public
395
-     * @since   1.1.0
396
-     * @return  void
397
-     */
398
-    public function set_woocommerce_functionality() {
399
-        // Disable guest checkout if a course is in the cart as we need a valid user to store data for
400
-        add_filter( 'pre_option_woocommerce_enable_guest_checkout', array( $this, 'disable_guest_checkout' ) );
401
-
402
-        // Mark orders with virtual products as complete rather then stay processing
403
-        add_filter( 'woocommerce_payment_complete_order_status', array( $this, 'virtual_order_payment_complete' ), 10, 2 );
404
-
405
-    } // End set_woocommerce_functionality()
406
-
407
-    /**
408
-     * Disable guest checkout if a course product is in the cart
409
-     * @param  boolean $guest_checkout Current guest checkout setting
410
-     * @return boolean                 Modified guest checkout setting
411
-     */
412
-    public function disable_guest_checkout( $guest_checkout ) {
413
-        global $woocommerce;
414
-
415
-        if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
416
-
417
-            if( isset( $woocommerce->cart->cart_contents ) && count( $woocommerce->cart->cart_contents ) > 0 ) {
418
-                foreach( $woocommerce->cart->cart_contents as $cart_key => $product ) {
419
-                    if( isset( $product['product_id'] ) ) {
420
-                        $args = array(
421
-                            'posts_per_page' => -1,
422
-                            'post_type' => 'course',
423
-                            'meta_query' => array(
424
-                                array(
425
-                                    'key' => '_course_woocommerce_product',
426
-                                    'value' => $product['product_id']
427
-                                )
428
-                            )
429
-                        );
430
-                        $posts = get_posts( $args );
431
-                        if( $posts && count( $posts ) > 0 ) {
432
-                            foreach( $posts as $course ) {
433
-                                $guest_checkout = '';
434
-                                break;
435
-                            }
436
-                        }
437
-                    }
438
-                }
439
-            }
440
-        }
441
-
442
-        return $guest_checkout;
443
-    }
444
-
445
-    /**
446
-     * Change order status with virtual products to completed
447
-     * @since  1.1.0
448
-     * @param string $order_status
449
-     * @param int $order_id
450
-     * @return string
451
-     **/
452
-    public function virtual_order_payment_complete( $order_status, $order_id ) {
453
-        $order = new WC_Order( $order_id );
454
-        if ( ! isset ( $order ) ) return '';
455
-        if ( $order_status == 'wc-processing' && ( $order->post_status == 'wc-on-hold' || $order->post_status == 'wc-pending' || $order->post_status == 'wc-failed' ) ) {
456
-            $virtual_order = true;
457
-
458
-            if ( count( $order->get_items() ) > 0 ) {
459
-                foreach( $order->get_items() as $item ) {
460
-                    if ( $item['product_id'] > 0 ) {
461
-                        $_product = $order->get_product_from_item( $item );
462
-                        if ( ! $_product->is_virtual() ) {
463
-                            $virtual_order = false;
464
-                            break;
465
-                        } // End If Statement
466
-                    } // End If Statement
467
-                } // End For Loop
468
-            } // End If Statement
469
-
470
-            // virtual order, mark as completed
471
-            if ( $virtual_order ) {
472
-                return 'completed';
473
-            } // End If Statement
474
-        } // End If Statement
475
-        return $order_status;
476
-    }
477
-
478
-    /**
479
-     * Register the widgets.
480
-     * @access public
481
-     * @since  1.0.0
482
-     * @return void
483
-     */
484
-    public function register_widgets () {
485
-        // Widget List (key => value is filename => widget class).
486
-        $widget_list = apply_filters( 'sensei_registered_widgets_list', array( 	'course-component' 	=> 'Course_Component',
487
-                'lesson-component' 	=> 'Lesson_Component',
488
-                'course-categories' => 'Course_Categories',
489
-                'category-courses' 	=> 'Category_Courses' )
490
-        );
491
-        foreach ( $widget_list as $key => $value ) {
492
-            if ( file_exists( $this->plugin_path . 'widgets/widget-woothemes-sensei-' . $key  . '.php' ) ) {
493
-                require_once( $this->plugin_path . 'widgets/widget-woothemes-sensei-' . $key  . '.php' );
494
-                register_widget( 'WooThemes_Sensei_' . $value . '_Widget' );
495
-            }
496
-        } // End For Loop
497
-
498
-        do_action( 'sensei_register_widgets' );
499
-
500
-    } // End register_widgets()
501
-
502
-    /**
503
-     * Load the plugin's localisation file.
504
-     * @access public
505
-     * @since  1.0.0
506
-     * @return void
507
-     */
508
-    public function load_localisation () {
509
-        load_plugin_textdomain( 'woothemes-sensei', false, dirname( plugin_basename( $this->file ) ) . '/lang/' );
510
-    } // End load_localisation()
511
-
512
-    /**
513
-     * Load the plugin textdomain from the main WordPress "languages" folder.
514
-     * @access  public
515
-     * @since   1.0.0
516
-     * @return  void
517
-     */
518
-    public function load_plugin_textdomain () {
519
-        $domain = 'woothemes-sensei';
520
-        // The "plugin_locale" filter is also used in load_plugin_textdomain()
521
-        $locale = apply_filters( 'plugin_locale', get_locale(), $domain );
522
-        load_textdomain( $domain, WP_LANG_DIR . '/' . $domain . '/' . $domain . '-' . $locale . '.mo' );
523
-        load_plugin_textdomain( $domain, FALSE, dirname( plugin_basename( $this->file ) ) . '/lang/' );
524
-    } // End load_plugin_textdomain()
525
-
526
-    /**
527
-     * Run on activation.
528
-     * @access public
529
-     * @since  1.0.0
530
-     * @return void
531
-     */
532
-    public function activation () {
533
-        $this->register_plugin_version();
534
-    } // End activation()
535
-
536
-
537
-    /**
538
-     * Register activation hooks.
539
-     * @access public
540
-     * @since  1.0.0
541
-     * @return void
542
-     */
543
-    public function install () {
544
-        register_activation_hook( $this->file, array( $this, 'activate_sensei' ) );
545
-        register_activation_hook( $this->file, 'flush_rewrite_rules' );
546
-    } // End install()
547
-
548
-
549
-    /**
550
-     * Run on activation of the plugin.
551
-     * @access public
552
-     * @since  1.0.0
553
-     * @return void
554
-     */
555
-    public function activate_sensei () {
556
-        update_option( 'skip_install_sensei_pages', 0 );
557
-        update_option( 'sensei_installed', 1 );
558
-    } // End activate_sensei()
559
-
560
-    /**
561
-     * Register the plugin's version.
562
-     * @access public
563
-     * @since  1.0.0
564
-     * @return void
565
-     */
566
-    private function register_plugin_version () {
567
-        if ( $this->version != '' ) {
568
-
569
-            // Check previous version to see if forced updates must run
570
-            // $old_version = get_option( 'woothemes-sensei-version', false );
571
-            // if( $old_version && version_compare( $old_version, '1.7.0', '<' )  ) {
572
-            // 	update_option( 'woothemes-sensei-force-updates', $this->version );
573
-            // } else {
574
-            // 	delete_option( 'woothemes-sensei-force-updates' );
575
-            // }
576
-
577
-            update_option( 'woothemes-sensei-version', $this->version );
578
-        }
579
-    } // End register_plugin_version()
580
-
581
-    /**
582
-     * Ensure that "post-thumbnails" support is available for those themes that don't register it.
583
-     * @access  public
584
-     * @since   1.0.1
585
-     * @return  void
586
-     */
587
-    public function ensure_post_thumbnails_support () {
588
-        if ( ! current_theme_supports( 'post-thumbnails' ) ) { add_theme_support( 'post-thumbnails' ); }
589
-    } // End ensure_post_thumbnails_support()
590
-
591
-
592
-    /**
593
-     * template_loader function.
594
-     *
595
-     * @access public
596
-     * @param mixed $template
597
-     * @return void
598
-     * @deprecated
599
-     */
600
-    public function template_loader ( $template = '' ) {
601
-
602
-        _deprecated_function( 'Sensei()->template_loader', '1.9.0', 'Use Sensei_Templates::template_loader( $template ) instead' );
603
-        Sensei_Templates::template_loader( $template );
604
-
605
-    } // End template_loader()
606
-
607
-    /**
608
-     * Determine the relative path to the plugin's directory.
609
-     * @access public
610
-     * @since  1.0.0
611
-     * @return string $sensei_plugin_path
612
-     */
613
-    public function plugin_path () {
614
-
615
-        if ( $this->plugin_path ) {
616
-
617
-            $sensei_plugin_path =  $this->plugin_path;
618
-
619
-        }else{
620
-
621
-            $sensei_plugin_path = plugin_dir_path( __FILE__ );
622
-
623
-        }
624
-
625
-        return $sensei_plugin_path;
626
-
627
-    } // End plugin_path()
628
-
629
-
630
-    /**
631
-     * Retrieve the ID of a specified page setting.
632
-     * @access public
633
-     * @since  1.0.0
634
-     * @param  string $page
635
-     * @return int
636
-     */
637
-    public function get_page_id ( $page ) {
638
-        $page = apply_filters( 'sensei_get_' . esc_attr( $page ) . '_page_id', get_option( 'sensei_' . esc_attr( $page ) . '_page_id' ) );
639
-        return ( $page ) ? $page : -1;
640
-    } // End get_page_id()
641
-
642
-
643
-    /**
644
-     * If WooCommerce is activated and the customer has purchased the course, update Sensei to indicate that they are taking the course.
645
-     * @access public
646
-     * @since  1.0.0
647
-     * @param  int 			$course_id  (default: 0)
648
-     * @param  array/Object $order_user (default: array()) Specific user's data.
649
-     * @return bool|int
650
-     */
651
-    public function woocommerce_course_update ( $course_id = 0, $order_user = array()  ) {
652
-        global $current_user;
653
-
654
-        if ( ! isset( $current_user ) || !$current_user->ID > 0 ) return false;
655
-
656
-        $data_update = false;
657
-
658
-        // Get the product ID
659
-        $wc_post_id = get_post_meta( intval( $course_id ), '_course_woocommerce_product', true );
660
-
661
-        // Check if in the admin
662
-        if ( is_admin() ) {
663
-            $user_login = $order_user['user_login'];
664
-            $user_email = $order_user['user_email'];
665
-            $user_url = $order_user['user_url'];
666
-            $user_id = $order_user['ID'];
667
-        } else {
668
-            $user_login = $current_user->user_login;
669
-            $user_email = $current_user->user_email;
670
-            $user_url = $current_user->user_url;
671
-            $user_id = $current_user->ID;
672
-        } // End If Statement
673
-
674
-        // This doesn't appear to be purely WooCommerce related. Should it be in a separate function?
675
-        $course_prerequisite_id = (int) get_post_meta( $course_id, '_course_prerequisite', true );
676
-        if( 0 < absint( $course_prerequisite_id ) ) {
677
-            $prereq_course_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, intval( $user_id ) );
678
-            if ( ! $prereq_course_complete ) {
679
-                // Remove all course user meta
680
-                return Sensei_Utils::sensei_remove_user_from_course( $course_id, $user_id );
681
-            }
682
-        }
683
-
684
-        $is_user_taking_course = Sensei_Utils::user_started_course( intval( $course_id ), intval( $user_id ) );
685
-
686
-        if( ! $is_user_taking_course ) {
687
-
688
-            if ( Sensei_WC::is_woocommerce_active() && Sensei_Utils::sensei_customer_bought_product( $user_email, $user_id, $wc_post_id ) && ( 0 < $wc_post_id ) ) {
689
-
690
-                $activity_logged = Sensei_Utils::user_start_course( intval( $user_id), intval( $course_id ) );
691
-
692
-                $is_user_taking_course = false;
693
-                if ( true == $activity_logged ) {
694
-                    $is_user_taking_course = true;
695
-                } // End If Statement
696
-            } // End If Statement
697
-        }
698
-
699
-        return $is_user_taking_course;
700
-    } // End woocommerce_course_update()
701
-
702
-
703
-    /**
704
-     * check_user_permissions function.
705
-     *
706
-     * @access public
707
-     * @param string $page (default: '')
708
-     *
709
-     * @return bool
710
-     */
711
-    public function check_user_permissions ( $page = '' ) {
712
-        // REFACTOR
713
-        global $current_user, $post;
714
-
715
-        // if use is not logged in
716
-        // skipped for single lesson
717
-        if ( empty( $current_user->caps ) && Sensei()->settings->get('access_permission')
718
-            && 'lesson-single' !=  $page ){
719
-            $this->permissions_message['title'] = __('Restricted Access', 'woothemes-sensei' );
720
-            $this->permissions_message['message'] = sprintf( __('You must be logged in to view this %s'), get_post_type() );
721
-            return false;
722
-        }
723
-
724
-
725
-        // Get User Meta
726
-        get_currentuserinfo();
727
-
728
-        $user_allowed = false;
729
-
730
-        switch ( $page ) {
731
-            case 'course-single':
732
-                // check for prerequisite course or lesson,
733
-                $course_prerequisite_id = (int) get_post_meta( $post->ID, '_course_prerequisite', true);
734
-                $update_course = $this->woocommerce_course_update( $post->ID );
735
-                // Count completed lessons
736
-                if ( 0 < absint( $course_prerequisite_id ) ) {
737
-
738
-                    $prerequisite_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, $current_user->ID );
739
-
740
-                }
741
-                else {
742
-                    $prerequisite_complete = true;
743
-                } // End If Statement
744
-                // Handles restrictions
745
-                if ( !$prerequisite_complete && 0 < absint( $course_prerequisite_id ) ) {
746
-                    $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' );
747
-                    $course_link = '<a href="' . esc_url( get_permalink( $course_prerequisite_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>';
748
-                    $this->permissions_message['message'] = sprintf( __('Please complete the previous %1$s before taking this course.', 'woothemes-sensei' ), $course_link );
749
-                } else {
750
-                    $user_allowed = true;
751
-                } // End If Statement
752
-                break;
753
-            case 'lesson-single':
754
-                // Check for WC purchase
755
-                $lesson_course_id = get_post_meta( $post->ID, '_lesson_course',true );
756
-
757
-                $update_course = $this->woocommerce_course_update( $lesson_course_id );
758
-                $is_preview = Sensei_Utils::is_preview_lesson( $post->ID );
759
-
760
-                if ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) {
761
-                    $user_allowed = true;
762
-                } elseif( $this->access_settings() && false == $is_preview ) {
763
-
764
-                    $user_allowed = true;
765
-
766
-                } else {
767
-                    $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' );
768
-                    $course_link = '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>';
769
-                    $wc_post_id = get_post_meta( $lesson_course_id, '_course_woocommerce_product',true );
770
-                    if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) {
771
-                        if ( $is_preview ) {
772
-                            $this->permissions_message['message'] = sprintf( __('This is a preview lesson. Please purchase the %1$s to access all lessons.', 'woothemes-sensei' ), $course_link );
773
-                        } else {
774
-                            $this->permissions_message['message'] =  sprintf( __('Please purchase the %1$s before starting this Lesson.', 'woothemes-sensei' ), $course_link );
775
-                        }
776
-                    } else {
777
-                        if ( $is_preview ) {
778
-                            $this->permissions_message['message'] = sprintf( __('This is a preview lesson. Please sign up for the %1$s to access all lessons.', 'woothemes-sensei' ), $course_link );
779
-                        } else {
780
-                            /** This filter is documented in class-woothemes-sensei-frontend.php */
781
-                            $this->permissions_message['message'] =  sprintf( __( 'Please sign up for the %1$s before starting the lesson.', 'woothemes-sensei' ), $course_link );
782
-                        }
783
-                    } // End If Statement
784
-                } // End If Statement
785
-                break;
786
-            case 'quiz-single':
787
-                $lesson_id = get_post_meta( $post->ID, '_quiz_lesson',true );
788
-                $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course',true );
789
-
790
-                $update_course = $this->woocommerce_course_update( $lesson_course_id );
791
-                if ( ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) || sensei_all_access() ) {
792
-
793
-                    // Check for prerequisite lesson for this quiz
794
-                    $lesson_prerequisite_id = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true);
795
-                    $user_lesson_prerequisite_complete = Sensei_Utils::user_completed_lesson( $lesson_prerequisite_id, $current_user->ID);
796
-
797
-                    // Handle restrictions
798
-                    if( sensei_all_access() ) {
799
-                        $user_allowed = true;
800
-                    } else {
801
-                        if ( 0 < absint( $lesson_prerequisite_id ) && ( !$user_lesson_prerequisite_complete ) ) {
802
-                            $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' );
803
-                            $lesson_link = '<a href="' . esc_url( get_permalink( $lesson_prerequisite_id ) ) . '">' . __( 'lesson', 'woothemes-sensei' ) . '</a>';
804
-                            $this->permissions_message['message'] = sprintf( __('Please complete the previous %1$s before taking this Quiz.', 'woothemes-sensei' ), $lesson_link );
805
-                        } else {
806
-                            $user_allowed = true;
807
-                        } // End If Statement
808
-                    } // End If Statement
809
-                } elseif( $this->access_settings() ) {
810
-                    // Check if the user has started the course
811
-
812
-                    if ( is_user_logged_in() && ! Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) && ( isset( $this->settings->settings['access_permission'] ) && ( true == $this->settings->settings['access_permission'] ) ) ) {
813
-
814
-                        $user_allowed = false;
815
-                        $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' );
816
-                        $course_link = '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>';
817
-                        $wc_post_id = get_post_meta( $lesson_course_id, '_course_woocommerce_product',true );
818
-                        if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) {
819
-                            $this->permissions_message['message'] = sprintf( __('Please purchase the %1$s before starting this Quiz.', 'woothemes-sensei' ), $course_link );
820
-                        } else {
821
-                            $this->permissions_message['message'] = sprintf( __('Please sign up for the %1$s before starting this Quiz.', 'woothemes-sensei' ), $course_link );
822
-                        } // End If Statement
823
-                    } else {
824
-                        $user_allowed = true;
825
-                    } // End If Statement
826
-                } else {
827
-                    $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' );
828
-                    $course_link = '<a href="' . esc_url( get_permalink( get_post_meta( get_post_meta( $post->ID, '_quiz_lesson', true ), '_lesson_course', true ) ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>';
829
-                    $this->permissions_message['message'] = sprintf( __('Please sign up for the %1$s before taking this Quiz.', 'woothemes-sensei' ), $course_link );
830
-                } // End If Statement
831
-                break;
832
-            default:
833
-                $user_allowed = true;
834
-                break;
835
-
836
-        } // End Switch Statement
837
-
838
-        /**
839
-         * filter the permissions message shown on sensei post types.
840
-         *
841
-         * @since 1.8.7
842
-         *
843
-         * @param array $permissions_message{
844
-         *
845
-         *   @type string $title
846
-         *   @type string $message
847
-         *
848
-         * }
849
-         * @param string $post_id
850
-         */
851
-        $this->permissions_message = apply_filters( 'sensei_permissions_message', $this->permissions_message, $post->ID );
852
-
853
-
854
-        if( sensei_all_access() || Sensei_Utils::is_preview_lesson( $post->ID ) ) {
855
-            $user_allowed = true;
856
-        }
857
-
858
-        return apply_filters( 'sensei_access_permissions', $user_allowed );
859
-    } // End get_placeholder_image()
860
-
861
-
862
-    /**
863
-     * Check if visitors have access permission. If the "access_permission" setting is active, do a log in check.
864
-     * @since  1.0.0
865
-     * @access public
866
-     * @return bool
867
-     */
868
-    public function access_settings () {
869
-
870
-        if( sensei_all_access() ) return true;
871
-
872
-        if ( isset( $this->settings->settings['access_permission'] ) && ( true == $this->settings->settings['access_permission'] ) ) {
873
-            if ( is_user_logged_in() ) {
874
-                return true;
875
-            } else {
876
-                return false;
877
-            } // End If Statement
878
-        } else {
879
-            return true;
880
-        } // End If Statement
881
-    } // End access_settings()
882
-
883
-    /**
884
-     * sensei_woocommerce_complete_order description
885
-     * @since   1.0.3
886
-     * @access  public
887
-     * @param   int $order_id WC order ID
888
-     * @return  void
889
-     */
890
-    public function sensei_woocommerce_complete_order ( $order_id = 0 ) {
891
-        $order_user = array();
892
-        // Check for WooCommerce
893
-        if ( Sensei_WC::is_woocommerce_active() && ( 0 < $order_id ) ) {
894
-            // Get order object
895
-            $order = new WC_Order( $order_id );
896
-            $user = get_user_by( 'id', $order->get_user_id() );
897
-            $order_user['ID'] = $user->ID;
898
-            $order_user['user_login'] = $user->user_login;
899
-            $order_user['user_email'] = $user->user_email;
900
-            $order_user['user_url'] = $user->user_url;
901
-            // Run through each product ordered
902
-            if ( 0 < sizeof( $order->get_items() ) ) {
903
-                foreach( $order->get_items() as $item ) {
904
-                    $product_type = '';
905
-                    if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
906
-                        $item_id = $item['variation_id'];
907
-                        $product_type = 'variation';
908
-                    } else {
909
-                        $item_id = $item['product_id'];
910
-                    } // End If Statement
911
-                    $_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type );
912
-                    // Get courses that use the WC product
913
-                    $courses = $this->post_types->course->get_product_courses( $_product->id );
914
-                    // Loop and update those courses
915
-                    foreach ( $courses as $course_item ) {
916
-                        $update_course = $this->woocommerce_course_update( $course_item->ID, $order_user );
917
-                    } // End For Loop
918
-                } // End For Loop
919
-            } // End If Statement
920
-            // Add meta to indicate that payment has been completed successfully
921
-            update_post_meta( $order_id, 'sensei_payment_complete', '1' );
922
-        } // End If Statement
923
-    } // End sensei_woocommerce_complete_order()
924
-
925
-    /**
926
-     * Runs when an order is cancelled.
927
-     * @since   1.2.0
928
-     * @access  public
929
-     * @param   integer $order_id order ID
930
-     * @return  void
931
-     */
932
-    public function sensei_woocommerce_cancel_order ( $order_id ) {
933
-
934
-        // Get order object
935
-        $order = new WC_Order( $order_id );
936
-
937
-        // Run through each product ordered
938
-        if ( 0 < sizeof( $order->get_items() ) ) {
939
-
940
-            // Get order user
941
-            $user_id = $order->__get( 'user_id' );
942
-
943
-            foreach( $order->get_items() as $item ) {
944
-
945
-                $product_type = '';
946
-                if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
947
-                    $item_id = $item['variation_id'];
948
-                    $product_type = 'variation';
949
-                } else {
950
-                    $item_id = $item['product_id'];
951
-                } // End If Statement
952
-                $_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type );
953
-
954
-                // Get courses that use the WC product
955
-                $courses = array();
956
-                $courses = $this->post_types->course->get_product_courses( $item_id );
957
-
958
-                // Loop and update those courses
959
-                foreach ($courses as $course_item){
960
-                    // Check and Remove course from courses user meta
961
-                    $dataset_changes = Sensei_Utils::sensei_remove_user_from_course( $course_item->ID, $user_id );
962
-                } // End For Loop
963
-            } // End For Loop
964
-        } // End If Statement
965
-    } // End sensei_woocommerce_cancel_order()
966
-
967
-    /**
968
-     * Runs when an subscription is cancelled or expires.
969
-     * @since   1.3.3
970
-     * @access  public
971
-     * @param   integer $user_id User ID
972
-     * @param   integer $subscription_key Subscription Unique Key
973
-     * @return  void
974
-     */
975
-    public function sensei_woocommerce_subscription_ended( $user_id, $subscription_key ) {
976
-        $subscription = WC_Subscriptions_Manager::get_users_subscription( $user_id, $subscription_key );
977
-        self::sensei_woocommerce_cancel_order( $subscription['order_id'] );
978
-    }
979
-
980
-    /**
981
-     * Runs when an subscription is re-activated after suspension.
982
-     * @since   1.3.3
983
-     * @access  public
984
-     * @param   integer $user_id User ID
985
-     * @param   integer $subscription_key Subscription Unique Key
986
-     * @return  void
987
-     */
988
-    public function sensei_woocommerce_reactivate_subscription( $user_id, $subscription_key ) {
989
-        $subscription = WC_Subscriptions_Manager::get_users_subscription( $user_id, $subscription_key );
990
-        $order = new WC_Order( $subscription['order_id'] );
991
-        $user = get_user_by( 'id', $order->get_user_id() );
992
-        $order_user = array();
993
-        $order_user['ID'] = $user->ID;
994
-        $order_user['user_login'] = $user->user_login;
995
-        $order_user['user_email'] = $user->user_email;
996
-        $order_user['user_url'] = $user->user_url;
997
-        $courses = $this->post_types->course->get_product_courses( $subscription['product_id'] );
998
-        foreach ( $courses as $course_item ){
999
-            $update_course = $this->woocommerce_course_update( $course_item->ID, $order_user );
1000
-        } // End For Loop
1001
-    } // End sensei_woocommerce_reactivate_subscription
1002
-
1003
-    /**
1004
-     * Returns the WooCommerce Product Object
1005
-     *
1006
-     * The code caters for pre and post WooCommerce 2.2 installations.
1007
-     *
1008
-     * @since   1.1.1
1009
-     * @access  public
1010
-     * @param   integer $wc_product_id Product ID or Variation ID
1011
-     * @param   string  $product_type  '' or 'variation'
1012
-     * @return   WC_Product $wc_product_object
1013
-     */
1014
-    public function sensei_get_woocommerce_product_object ( $wc_product_id = 0, $product_type = '' ) {
1015
-
1016
-        $wc_product_object = false;
1017
-        if ( 0 < intval( $wc_product_id ) ) {
1018
-
1019
-            // Get the product
1020
-            if ( function_exists( 'wc_get_product' ) ) {
1021
-
1022
-                $wc_product_object = wc_get_product( $wc_product_id ); // Post WC 2.3
1023
-
1024
-            } elseif ( function_exists( 'get_product' ) ) {
1025
-
1026
-                $wc_product_object = get_product( $wc_product_id ); // Post WC 2.0
1027
-
1028
-            } else {
1029
-
1030
-                // Pre WC 2.0
1031
-                if ( 'variation' == $product_type || 'subscription_variation' == $product_type ) {
1032
-
1033
-                    $wc_product_object = new WC_Product_Variation( $wc_product_id );
1034
-
1035
-                } else {
1036
-
1037
-                    $wc_product_object = new WC_Product( $wc_product_id );
1038
-
1039
-                } // End If Statement
1040
-
1041
-            } // End If Statement
1042
-
1043
-        } // End If Statement
1044
-
1045
-        return $wc_product_object;
1046
-
1047
-    } // End sensei_get_woocommerce_product_object()
1048
-
1049
-    /**
1050
-     * load_class loads in class files
1051
-     * @since   1.2.0
1052
-     * @access  public
1053
-     * @return  void
1054
-     */
1055
-    public function load_class ( $class_name = '' ) {
1056
-        if ( '' != $class_name && '' != $this->token ) {
1057
-            require_once( 'class-' . esc_attr( $this->token ) . '-' . esc_attr( $class_name ) . '.php' );
1058
-        } // End If Statement
1059
-    } // End load_class()
1060
-
1061
-    /**
1062
-     * sensei_activate_subscription runs when a subscription product is purchased
1063
-     * @since   1.2.0
1064
-     * @access  public
1065
-     * @param   integer $order_id order ID
1066
-     * @return  void
1067
-     */
1068
-    public function sensei_activate_subscription(  $order_id = 0 ) {
1069
-        if ( 0 < intval( $order_id ) ) {
1070
-            $order = new WC_Order( $order_id );
1071
-            $user = get_user_by('id', $order->user_id);
1072
-            $order_user['ID'] = $user->ID;
1073
-            $order_user['user_login'] = $user->user_login;
1074
-            $order_user['user_email'] = $user->user_email;
1075
-            $order_user['user_url'] = $user->user_url;
1076
-            // Run through each product ordered
1077
-            if (sizeof($order->get_items())>0) {
1078
-                foreach($order->get_items() as $item) {
1079
-                    $product_type = '';
1080
-                    if (isset($item['variation_id']) && $item['variation_id'] > 0) {
1081
-                        $item_id = $item['variation_id'];
1082
-                        $product_type = 'subscription_variation';
1083
-                    } else {
1084
-                        $item_id = $item['product_id'];
1085
-                    } // End If Statement
1086
-                    $_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type );
1087
-                    // Get courses that use the WC product
1088
-                    $courses = array();
1089
-                    if ( $product_type == 'subscription_variation' ) {
1090
-                        $courses = $this->post_types->course->get_product_courses( $item_id );
1091
-                    } // End If Statement
1092
-                    // Loop and update those courses
1093
-                    foreach ($courses as $course_item){
1094
-                        $update_course = $this->woocommerce_course_update( $course_item->ID, $order_user );
1095
-                    } // End For Loop
1096
-                } // End For Loop
1097
-            } // End If Statement
1098
-        } // End If Statement
1099
-    } // End sensei_activate_subscription()
1100
-
1101
-    /**
1102
-     * sensei_woocommerce_email_course_details adds detail to email
1103
-     * @since   1.4.5
1104
-     * @access  public
1105
-     * @param   WC_Order $order
1106
-     * @return  void
1107
-     */
1108
-    public function sensei_woocommerce_email_course_details( $order ) {
1109
-        global $woocommerce;
1110
-
1111
-        // exit early if not wc-completed or wc-processing
1112
-        if( 'wc-completed' != $order->post_status
1113
-            && 'wc-processing' != $order->post_status  ) {
1114
-            return;
1115
-        }
1116
-
1117
-        $order_items = $order->get_items();
1118
-        $order_id = $order->id;
1119
-
1120
-        //If object have items go through them all to find course
1121
-        if ( 0 < sizeof( $order_items ) ) {
1122
-
1123
-            $course_details_html =  '<h2>' . __( 'Course details', 'woothemes-sensei' ) . '</h2>';
1124
-            $order_contains_courses = false;
1125
-
1126
-
1127
-            foreach ( $order_items as $item ) {
1128
-
1129
-                $product_type = '';
1130
-                if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
1131
-                    // If item has variation_id then its from variation
1132
-                    $item_id = $item['variation_id'];
1133
-                    $product_type = 'variation';
1134
-                } else {
1135
-                    // If not its real product set its id to item_id
1136
-                    $item_id = $item['product_id'];
1137
-                } // End If Statement
1138
-
1139
-                $user_id = get_post_meta( $order_id, '_customer_user', true );
1140
-
1141
-                if( $user_id ) {
1142
-
1143
-                    // Get all courses for product
1144
-                    $args = array(
1145
-                        'posts_per_page' => -1,
1146
-                        'post_type' => 'course',
1147
-                        'meta_query' => array(
1148
-                            array(
1149
-                                'key' => '_course_woocommerce_product',
1150
-                                'value' => $item_id
1151
-                            )
1152
-                        ),
1153
-                        'orderby' => 'menu_order date',
1154
-                        'order' => 'ASC',
1155
-                    );
1156
-                    $courses = get_posts( $args );
1157
-
1158
-                    if( $courses && count( $courses ) > 0 ) {
1159
-
1160
-                        foreach( $courses as $course ) {
1161
-
1162
-                            $title = $course->post_title;
1163
-                            $permalink = get_permalink( $course->ID );
1164
-                            $order_contains_courses = true;
1165
-                            $course_details_html .=  '<p><strong>' . sprintf( __( 'View course: %1$s', 'woothemes-sensei' ), '</strong><a href="' . esc_url( $permalink ) . '">' . $title . '</a>' ) . '</p>';
1166
-                        }
1167
-
1168
-
1169
-                    } // end if has courses
1170
-
1171
-                } // end if $userPid
1172
-
1173
-            } // end for each order item
1174
-
1175
-            // Output Course details
1176
-            if( $order_contains_courses ){
1177
-
1178
-                echo $course_details_html;
1179
-
1180
-            }
1181
-
1182
-
1183
-        } // end if  order items not empty
1184
-
1185
-    } // end func email course details
1186
-
1187
-    /**
1188
-     * Filtering wp_count_comments to ensure that Sensei comments are ignored
1189
-     * @since   1.4.0
1190
-     * @access  public
1191
-     * @param  array   $comments
1192
-     * @param  integer $post_id
1193
-     * @return array
1194
-     */
1195
-    public function sensei_count_comments( $comments, $post_id ) {
1196
-        global $wpdb;
1197
-
1198
-        $post_id = (int) $post_id;
1199
-
1200
-        $count = wp_cache_get("comments-{$post_id}", 'counts');
1201
-
1202
-        if ( false !== $count ) {
1203
-            return $count;
1204
-        }
1205
-
1206
-        $statuses = array( '' ); // Default to the WP normal comments
1207
-        $stati = $wpdb->get_results( "SELECT comment_type FROM {$wpdb->comments} GROUP BY comment_type", ARRAY_A );
1208
-        foreach ( (array) $stati AS $status ) {
1209
-            if ( 'sensei_' != substr($status['comment_type'], 0, 7 ) ) {
1210
-                $statuses[] = $status['comment_type'];
1211
-            }
1212
-        }
1213
-        $where = "WHERE comment_type IN ('" . join("', '", array_unique( $statuses ) ) . "')";
1214
-
1215
-        if ( $post_id > 0 )
1216
-            $where .= $wpdb->prepare( " AND comment_post_ID = %d", $post_id );
1217
-
1218
-        $count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A );
1219
-
1220
-        $total = 0;
1221
-        $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash', 'post-trashed' => 'post-trashed');
1222
-        foreach ( (array) $count as $row ) {
1223
-            // Don't count post-trashed toward totals
1224
-            if ( 'post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'] )
1225
-                $total += $row['num_comments'];
1226
-            if ( isset( $approved[$row['comment_approved']] ) )
1227
-                $stats[$approved[$row['comment_approved']]] = $row['num_comments'];
1228
-        }
1229
-
1230
-        $stats['total_comments'] = $total;
1231
-        foreach ( $approved as $key ) {
1232
-            if ( empty($stats[$key]) )
1233
-                $stats[$key] = 0;
1234
-        }
1235
-
1236
-        $stats = (object) $stats;
1237
-        wp_cache_set("comments-{$post_id}", $stats, 'counts');
1238
-
1239
-        return $stats;
1240
-    }
1241
-
1242
-    /**
1243
-     * Init images.
1244
-     *
1245
-     * @since 1.4.5
1246
-     * @access public
1247
-     * @return void
1248
-     */
1249
-    public function init_image_sizes() {
1250
-        $course_archive_thumbnail 	= $this->get_image_size( 'course_archive_image' );
1251
-        $course_single_thumbnail	= $this->get_image_size( 'course_single_image' );
1252
-        $lesson_archive_thumbnail 	= $this->get_image_size( 'lesson_archive_image' );
1253
-        $lesson_single_thumbnail	= $this->get_image_size( 'lesson_single_image' );
1254
-
1255
-        add_image_size( 'course_archive_thumbnail', $course_archive_thumbnail['width'], $course_archive_thumbnail['height'], $course_archive_thumbnail['crop'] );
1256
-        add_image_size( 'course_single_thumbnail', $course_single_thumbnail['width'], $course_single_thumbnail['height'], $course_single_thumbnail['crop'] );
1257
-        add_image_size( 'lesson_archive_thumbnail', $lesson_archive_thumbnail['width'], $lesson_archive_thumbnail['height'], $lesson_archive_thumbnail['crop'] );
1258
-        add_image_size( 'lesson_single_thumbnail', $lesson_single_thumbnail['width'], $lesson_single_thumbnail['height'], $lesson_single_thumbnail['crop'] );
1259
-    }
1260
-
1261
-    /**
1262
-     * Get an image size.
1263
-     *
1264
-     * Variable is filtered by sensei_get_image_size_{image_size}
1265
-     *
1266
-     * @since 1.4.5
1267
-     * @access public
1268
-     * @param mixed $image_size
1269
-     * @return string
1270
-     */
1271
-    public function get_image_size( $image_size ) {
1272
-
1273
-        // Only return sizes we define in settings
1274
-        if ( ! in_array( $image_size, array( 'course_archive_image', 'course_single_image', 'lesson_archive_image', 'lesson_single_image' ) ) )
1275
-            return apply_filters( 'sensei_get_image_size_' . $image_size, '' );
1276
-
1277
-        if( ! isset( $this->settings->settings[ $image_size . '_width' ] ) ) {
1278
-            $this->settings->settings[ $image_size . '_width' ] = false;
1279
-        }
1280
-        if( ! isset( $this->settings->settings[ $image_size . '_height' ] ) ) {
1281
-            $this->settings->settings[ $image_size . '_height' ] = false;
1282
-        }
1283
-        if( ! isset( $this->settings->settings[ $image_size . '_hard_crop' ] ) ) {
1284
-            $this->settings->settings[ $image_size . '_hard_crop' ] = false;
1285
-        }
1286
-
1287
-        $size = array_filter( array(
1288
-            'width' => $this->settings->settings[ $image_size . '_width' ],
1289
-            'height' => $this->settings->settings[ $image_size . '_height' ],
1290
-            'crop' => $this->settings->settings[ $image_size . '_hard_crop' ]
1291
-        ) );
1292
-
1293
-        $size['width'] 	= isset( $size['width'] ) ? $size['width'] : '100';
1294
-        $size['height'] = isset( $size['height'] ) ? $size['height'] : '100';
1295
-        $size['crop'] 	= isset( $size['crop'] ) ? $size['crop'] : 0;
1296
-
1297
-        return apply_filters( 'sensei_get_image_size_' . $image_size, $size );
1298
-    }
1299
-
1300
-    public function body_class( $classes ) {
1301
-        if( is_sensei() ) {
1302
-            $classes[] = 'sensei';
1303
-        }
1304
-        return $classes;
1305
-    }
1306
-
1307
-    /**
1308
-     * Checks that the Jetpack Beautiful Maths module has been activated to support LaTeX within question titles and answers
1309
-     *
1310
-     * @return null
1311
-     * @since 1.7.0
1312
-     */
1313
-    public function jetpack_latex_support() {
1314
-        if ( function_exists( 'latex_markup') ) {
1315
-            add_filter( 'sensei_question_title', 'latex_markup' );
1316
-            add_filter( 'sensei_answer_text', 'latex_markup' );
1317
-        }
1318
-    }
1319
-
1320
-    /**
1321
-     * Load the module functionality.
1322
-     *
1323
-     * This function is hooked into plugins_loaded to avoid conflicts with
1324
-     * the retired modules extension.
1325
-     *
1326
-     * @since 1.8.0
1327
-     */
1328
-    public function load_modules_class(){
1329
-        global $sensei_modules;
1330
-
1331
-        if( !class_exists( 'Sensei_Modules' )
1332
-            &&  'Sensei_Modules' != get_class( $sensei_modules ) ) {
1333
-
1334
-            //Load the modules class
1335
-            require_once( 'class-sensei-modules.php');
1336
-            Sensei()->modules = new Sensei_Core_Modules( $this->file );
1337
-
1338
-        }else{
1339
-            // fallback for people still using the modules extension.
1340
-            global $sensei_modules;
1341
-            Sensei()->modules = $sensei_modules;
1342
-            add_action( 'admin_notices', array( $this, 'disable_sensei_modules_extension'), 30 );
1343
-        }
1344
-    }
1345
-
1346
-    /**
1347
-     * Tell the user to that the modules extension is no longer needed.
1348
-     *
1349
-     * @since 1.8.0
1350
-     */
1351
-    public function disable_sensei_modules_extension(){ ?>
333
+	/**
334
+	 * Initialize all Sensei hooks
335
+	 *
336
+	 * @since 1.9.0
337
+	 */
338
+	public function load_hooks(){
339
+
340
+		add_action( 'widgets_init', array( $this, 'register_widgets' ) );
341
+		add_action( 'after_setup_theme', array( $this, 'ensure_post_thumbnails_support' ) );
342
+
343
+		// WooCommerce Payment Actions
344
+		add_action( 'woocommerce_payment_complete' , array( $this, 'sensei_woocommerce_complete_order' ) );
345
+		add_action( 'woocommerce_thankyou' , array( $this, 'sensei_woocommerce_complete_order' ) );
346
+		add_action( 'woocommerce_order_status_completed' , array( $this, 'sensei_woocommerce_complete_order' ) );
347
+		add_action( 'woocommerce_order_status_processing' , array( $this, 'sensei_woocommerce_complete_order' ) );
348
+		add_action( 'woocommerce_order_status_cancelled' , array( $this, 'sensei_woocommerce_cancel_order' ) );
349
+		add_action( 'woocommerce_order_status_refunded' , array( $this, 'sensei_woocommerce_cancel_order' ) );
350
+		add_action( 'subscriptions_activated_for_order', array( $this, 'sensei_activate_subscription' ) );
351
+
352
+		// WooCommerce Subscriptions Actions
353
+		add_action( 'reactivated_subscription', array( $this, 'sensei_woocommerce_reactivate_subscription' ), 10, 2 );
354
+		add_action( 'subscription_expired' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 );
355
+		add_action( 'subscription_end_of_prepaid_term' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 );
356
+		add_action( 'cancelled_subscription' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 );
357
+		add_action( 'subscription_put_on-hold' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 );
358
+
359
+		// Add Email link to course orders
360
+		add_action( 'woocommerce_email_after_order_table', array( $this, 'sensei_woocommerce_email_course_details' ), 10, 1 );
361
+
362
+		// Filter comment counts
363
+		add_filter( 'wp_count_comments', array( $this, 'sensei_count_comments' ), 10, 2 );
364
+
365
+		add_action( 'body_class', array( $this, 'body_class' ) );
366
+
367
+		// Check for and activate JetPack LaTeX support
368
+		add_action( 'plugins_loaded', array( $this, 'jetpack_latex_support'), 200 ); // Runs after Jetpack has loaded it's modules
369
+
370
+		// check flush the rewrite rules if the option sensei_flush_rewrite_rules option is 1
371
+		add_action( 'init', array( $this, 'flush_rewrite_rules'), 101 );
372
+
373
+	}
374
+
375
+	/**
376
+	 * Run Sensei updates.
377
+	 * @access  public
378
+	 * @since   1.1.0
379
+	 * @return  void
380
+	 */
381
+	public function run_updates() {
382
+		// Run updates if administrator
383
+		if ( current_user_can( 'manage_options' ) || current_user_can( 'manage_sensei' ) ) {
384
+
385
+			$this->updates->update();
386
+
387
+		} // End If Statement
388
+	} // End run_updates()
389
+
390
+
391
+
392
+	/**
393
+	 * Setup required WooCommerce settings.
394
+	 * @access  public
395
+	 * @since   1.1.0
396
+	 * @return  void
397
+	 */
398
+	public function set_woocommerce_functionality() {
399
+		// Disable guest checkout if a course is in the cart as we need a valid user to store data for
400
+		add_filter( 'pre_option_woocommerce_enable_guest_checkout', array( $this, 'disable_guest_checkout' ) );
401
+
402
+		// Mark orders with virtual products as complete rather then stay processing
403
+		add_filter( 'woocommerce_payment_complete_order_status', array( $this, 'virtual_order_payment_complete' ), 10, 2 );
404
+
405
+	} // End set_woocommerce_functionality()
406
+
407
+	/**
408
+	 * Disable guest checkout if a course product is in the cart
409
+	 * @param  boolean $guest_checkout Current guest checkout setting
410
+	 * @return boolean                 Modified guest checkout setting
411
+	 */
412
+	public function disable_guest_checkout( $guest_checkout ) {
413
+		global $woocommerce;
414
+
415
+		if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
416
+
417
+			if( isset( $woocommerce->cart->cart_contents ) && count( $woocommerce->cart->cart_contents ) > 0 ) {
418
+				foreach( $woocommerce->cart->cart_contents as $cart_key => $product ) {
419
+					if( isset( $product['product_id'] ) ) {
420
+						$args = array(
421
+							'posts_per_page' => -1,
422
+							'post_type' => 'course',
423
+							'meta_query' => array(
424
+								array(
425
+									'key' => '_course_woocommerce_product',
426
+									'value' => $product['product_id']
427
+								)
428
+							)
429
+						);
430
+						$posts = get_posts( $args );
431
+						if( $posts && count( $posts ) > 0 ) {
432
+							foreach( $posts as $course ) {
433
+								$guest_checkout = '';
434
+								break;
435
+							}
436
+						}
437
+					}
438
+				}
439
+			}
440
+		}
441
+
442
+		return $guest_checkout;
443
+	}
444
+
445
+	/**
446
+	 * Change order status with virtual products to completed
447
+	 * @since  1.1.0
448
+	 * @param string $order_status
449
+	 * @param int $order_id
450
+	 * @return string
451
+	 **/
452
+	public function virtual_order_payment_complete( $order_status, $order_id ) {
453
+		$order = new WC_Order( $order_id );
454
+		if ( ! isset ( $order ) ) return '';
455
+		if ( $order_status == 'wc-processing' && ( $order->post_status == 'wc-on-hold' || $order->post_status == 'wc-pending' || $order->post_status == 'wc-failed' ) ) {
456
+			$virtual_order = true;
457
+
458
+			if ( count( $order->get_items() ) > 0 ) {
459
+				foreach( $order->get_items() as $item ) {
460
+					if ( $item['product_id'] > 0 ) {
461
+						$_product = $order->get_product_from_item( $item );
462
+						if ( ! $_product->is_virtual() ) {
463
+							$virtual_order = false;
464
+							break;
465
+						} // End If Statement
466
+					} // End If Statement
467
+				} // End For Loop
468
+			} // End If Statement
469
+
470
+			// virtual order, mark as completed
471
+			if ( $virtual_order ) {
472
+				return 'completed';
473
+			} // End If Statement
474
+		} // End If Statement
475
+		return $order_status;
476
+	}
477
+
478
+	/**
479
+	 * Register the widgets.
480
+	 * @access public
481
+	 * @since  1.0.0
482
+	 * @return void
483
+	 */
484
+	public function register_widgets () {
485
+		// Widget List (key => value is filename => widget class).
486
+		$widget_list = apply_filters( 'sensei_registered_widgets_list', array( 	'course-component' 	=> 'Course_Component',
487
+				'lesson-component' 	=> 'Lesson_Component',
488
+				'course-categories' => 'Course_Categories',
489
+				'category-courses' 	=> 'Category_Courses' )
490
+		);
491
+		foreach ( $widget_list as $key => $value ) {
492
+			if ( file_exists( $this->plugin_path . 'widgets/widget-woothemes-sensei-' . $key  . '.php' ) ) {
493
+				require_once( $this->plugin_path . 'widgets/widget-woothemes-sensei-' . $key  . '.php' );
494
+				register_widget( 'WooThemes_Sensei_' . $value . '_Widget' );
495
+			}
496
+		} // End For Loop
497
+
498
+		do_action( 'sensei_register_widgets' );
499
+
500
+	} // End register_widgets()
501
+
502
+	/**
503
+	 * Load the plugin's localisation file.
504
+	 * @access public
505
+	 * @since  1.0.0
506
+	 * @return void
507
+	 */
508
+	public function load_localisation () {
509
+		load_plugin_textdomain( 'woothemes-sensei', false, dirname( plugin_basename( $this->file ) ) . '/lang/' );
510
+	} // End load_localisation()
511
+
512
+	/**
513
+	 * Load the plugin textdomain from the main WordPress "languages" folder.
514
+	 * @access  public
515
+	 * @since   1.0.0
516
+	 * @return  void
517
+	 */
518
+	public function load_plugin_textdomain () {
519
+		$domain = 'woothemes-sensei';
520
+		// The "plugin_locale" filter is also used in load_plugin_textdomain()
521
+		$locale = apply_filters( 'plugin_locale', get_locale(), $domain );
522
+		load_textdomain( $domain, WP_LANG_DIR . '/' . $domain . '/' . $domain . '-' . $locale . '.mo' );
523
+		load_plugin_textdomain( $domain, FALSE, dirname( plugin_basename( $this->file ) ) . '/lang/' );
524
+	} // End load_plugin_textdomain()
525
+
526
+	/**
527
+	 * Run on activation.
528
+	 * @access public
529
+	 * @since  1.0.0
530
+	 * @return void
531
+	 */
532
+	public function activation () {
533
+		$this->register_plugin_version();
534
+	} // End activation()
535
+
536
+
537
+	/**
538
+	 * Register activation hooks.
539
+	 * @access public
540
+	 * @since  1.0.0
541
+	 * @return void
542
+	 */
543
+	public function install () {
544
+		register_activation_hook( $this->file, array( $this, 'activate_sensei' ) );
545
+		register_activation_hook( $this->file, 'flush_rewrite_rules' );
546
+	} // End install()
547
+
548
+
549
+	/**
550
+	 * Run on activation of the plugin.
551
+	 * @access public
552
+	 * @since  1.0.0
553
+	 * @return void
554
+	 */
555
+	public function activate_sensei () {
556
+		update_option( 'skip_install_sensei_pages', 0 );
557
+		update_option( 'sensei_installed', 1 );
558
+	} // End activate_sensei()
559
+
560
+	/**
561
+	 * Register the plugin's version.
562
+	 * @access public
563
+	 * @since  1.0.0
564
+	 * @return void
565
+	 */
566
+	private function register_plugin_version () {
567
+		if ( $this->version != '' ) {
568
+
569
+			// Check previous version to see if forced updates must run
570
+			// $old_version = get_option( 'woothemes-sensei-version', false );
571
+			// if( $old_version && version_compare( $old_version, '1.7.0', '<' )  ) {
572
+			// 	update_option( 'woothemes-sensei-force-updates', $this->version );
573
+			// } else {
574
+			// 	delete_option( 'woothemes-sensei-force-updates' );
575
+			// }
576
+
577
+			update_option( 'woothemes-sensei-version', $this->version );
578
+		}
579
+	} // End register_plugin_version()
580
+
581
+	/**
582
+	 * Ensure that "post-thumbnails" support is available for those themes that don't register it.
583
+	 * @access  public
584
+	 * @since   1.0.1
585
+	 * @return  void
586
+	 */
587
+	public function ensure_post_thumbnails_support () {
588
+		if ( ! current_theme_supports( 'post-thumbnails' ) ) { add_theme_support( 'post-thumbnails' ); }
589
+	} // End ensure_post_thumbnails_support()
590
+
591
+
592
+	/**
593
+	 * template_loader function.
594
+	 *
595
+	 * @access public
596
+	 * @param mixed $template
597
+	 * @return void
598
+	 * @deprecated
599
+	 */
600
+	public function template_loader ( $template = '' ) {
601
+
602
+		_deprecated_function( 'Sensei()->template_loader', '1.9.0', 'Use Sensei_Templates::template_loader( $template ) instead' );
603
+		Sensei_Templates::template_loader( $template );
604
+
605
+	} // End template_loader()
606
+
607
+	/**
608
+	 * Determine the relative path to the plugin's directory.
609
+	 * @access public
610
+	 * @since  1.0.0
611
+	 * @return string $sensei_plugin_path
612
+	 */
613
+	public function plugin_path () {
614
+
615
+		if ( $this->plugin_path ) {
616
+
617
+			$sensei_plugin_path =  $this->plugin_path;
618
+
619
+		}else{
620
+
621
+			$sensei_plugin_path = plugin_dir_path( __FILE__ );
622
+
623
+		}
624
+
625
+		return $sensei_plugin_path;
626
+
627
+	} // End plugin_path()
628
+
629
+
630
+	/**
631
+	 * Retrieve the ID of a specified page setting.
632
+	 * @access public
633
+	 * @since  1.0.0
634
+	 * @param  string $page
635
+	 * @return int
636
+	 */
637
+	public function get_page_id ( $page ) {
638
+		$page = apply_filters( 'sensei_get_' . esc_attr( $page ) . '_page_id', get_option( 'sensei_' . esc_attr( $page ) . '_page_id' ) );
639
+		return ( $page ) ? $page : -1;
640
+	} // End get_page_id()
641
+
642
+
643
+	/**
644
+	 * If WooCommerce is activated and the customer has purchased the course, update Sensei to indicate that they are taking the course.
645
+	 * @access public
646
+	 * @since  1.0.0
647
+	 * @param  int 			$course_id  (default: 0)
648
+	 * @param  array/Object $order_user (default: array()) Specific user's data.
649
+	 * @return bool|int
650
+	 */
651
+	public function woocommerce_course_update ( $course_id = 0, $order_user = array()  ) {
652
+		global $current_user;
653
+
654
+		if ( ! isset( $current_user ) || !$current_user->ID > 0 ) return false;
655
+
656
+		$data_update = false;
657
+
658
+		// Get the product ID
659
+		$wc_post_id = get_post_meta( intval( $course_id ), '_course_woocommerce_product', true );
660
+
661
+		// Check if in the admin
662
+		if ( is_admin() ) {
663
+			$user_login = $order_user['user_login'];
664
+			$user_email = $order_user['user_email'];
665
+			$user_url = $order_user['user_url'];
666
+			$user_id = $order_user['ID'];
667
+		} else {
668
+			$user_login = $current_user->user_login;
669
+			$user_email = $current_user->user_email;
670
+			$user_url = $current_user->user_url;
671
+			$user_id = $current_user->ID;
672
+		} // End If Statement
673
+
674
+		// This doesn't appear to be purely WooCommerce related. Should it be in a separate function?
675
+		$course_prerequisite_id = (int) get_post_meta( $course_id, '_course_prerequisite', true );
676
+		if( 0 < absint( $course_prerequisite_id ) ) {
677
+			$prereq_course_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, intval( $user_id ) );
678
+			if ( ! $prereq_course_complete ) {
679
+				// Remove all course user meta
680
+				return Sensei_Utils::sensei_remove_user_from_course( $course_id, $user_id );
681
+			}
682
+		}
683
+
684
+		$is_user_taking_course = Sensei_Utils::user_started_course( intval( $course_id ), intval( $user_id ) );
685
+
686
+		if( ! $is_user_taking_course ) {
687
+
688
+			if ( Sensei_WC::is_woocommerce_active() && Sensei_Utils::sensei_customer_bought_product( $user_email, $user_id, $wc_post_id ) && ( 0 < $wc_post_id ) ) {
689
+
690
+				$activity_logged = Sensei_Utils::user_start_course( intval( $user_id), intval( $course_id ) );
691
+
692
+				$is_user_taking_course = false;
693
+				if ( true == $activity_logged ) {
694
+					$is_user_taking_course = true;
695
+				} // End If Statement
696
+			} // End If Statement
697
+		}
698
+
699
+		return $is_user_taking_course;
700
+	} // End woocommerce_course_update()
701
+
702
+
703
+	/**
704
+	 * check_user_permissions function.
705
+	 *
706
+	 * @access public
707
+	 * @param string $page (default: '')
708
+	 *
709
+	 * @return bool
710
+	 */
711
+	public function check_user_permissions ( $page = '' ) {
712
+		// REFACTOR
713
+		global $current_user, $post;
714
+
715
+		// if use is not logged in
716
+		// skipped for single lesson
717
+		if ( empty( $current_user->caps ) && Sensei()->settings->get('access_permission')
718
+			&& 'lesson-single' !=  $page ){
719
+			$this->permissions_message['title'] = __('Restricted Access', 'woothemes-sensei' );
720
+			$this->permissions_message['message'] = sprintf( __('You must be logged in to view this %s'), get_post_type() );
721
+			return false;
722
+		}
723
+
724
+
725
+		// Get User Meta
726
+		get_currentuserinfo();
727
+
728
+		$user_allowed = false;
729
+
730
+		switch ( $page ) {
731
+			case 'course-single':
732
+				// check for prerequisite course or lesson,
733
+				$course_prerequisite_id = (int) get_post_meta( $post->ID, '_course_prerequisite', true);
734
+				$update_course = $this->woocommerce_course_update( $post->ID );
735
+				// Count completed lessons
736
+				if ( 0 < absint( $course_prerequisite_id ) ) {
737
+
738
+					$prerequisite_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, $current_user->ID );
739
+
740
+				}
741
+				else {
742
+					$prerequisite_complete = true;
743
+				} // End If Statement
744
+				// Handles restrictions
745
+				if ( !$prerequisite_complete && 0 < absint( $course_prerequisite_id ) ) {
746
+					$this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' );
747
+					$course_link = '<a href="' . esc_url( get_permalink( $course_prerequisite_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>';
748
+					$this->permissions_message['message'] = sprintf( __('Please complete the previous %1$s before taking this course.', 'woothemes-sensei' ), $course_link );
749
+				} else {
750
+					$user_allowed = true;
751
+				} // End If Statement
752
+				break;
753
+			case 'lesson-single':
754
+				// Check for WC purchase
755
+				$lesson_course_id = get_post_meta( $post->ID, '_lesson_course',true );
756
+
757
+				$update_course = $this->woocommerce_course_update( $lesson_course_id );
758
+				$is_preview = Sensei_Utils::is_preview_lesson( $post->ID );
759
+
760
+				if ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) {
761
+					$user_allowed = true;
762
+				} elseif( $this->access_settings() && false == $is_preview ) {
763
+
764
+					$user_allowed = true;
765
+
766
+				} else {
767
+					$this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' );
768
+					$course_link = '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>';
769
+					$wc_post_id = get_post_meta( $lesson_course_id, '_course_woocommerce_product',true );
770
+					if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) {
771
+						if ( $is_preview ) {
772
+							$this->permissions_message['message'] = sprintf( __('This is a preview lesson. Please purchase the %1$s to access all lessons.', 'woothemes-sensei' ), $course_link );
773
+						} else {
774
+							$this->permissions_message['message'] =  sprintf( __('Please purchase the %1$s before starting this Lesson.', 'woothemes-sensei' ), $course_link );
775
+						}
776
+					} else {
777
+						if ( $is_preview ) {
778
+							$this->permissions_message['message'] = sprintf( __('This is a preview lesson. Please sign up for the %1$s to access all lessons.', 'woothemes-sensei' ), $course_link );
779
+						} else {
780
+							/** This filter is documented in class-woothemes-sensei-frontend.php */
781
+							$this->permissions_message['message'] =  sprintf( __( 'Please sign up for the %1$s before starting the lesson.', 'woothemes-sensei' ), $course_link );
782
+						}
783
+					} // End If Statement
784
+				} // End If Statement
785
+				break;
786
+			case 'quiz-single':
787
+				$lesson_id = get_post_meta( $post->ID, '_quiz_lesson',true );
788
+				$lesson_course_id = get_post_meta( $lesson_id, '_lesson_course',true );
789
+
790
+				$update_course = $this->woocommerce_course_update( $lesson_course_id );
791
+				if ( ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) || sensei_all_access() ) {
792
+
793
+					// Check for prerequisite lesson for this quiz
794
+					$lesson_prerequisite_id = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true);
795
+					$user_lesson_prerequisite_complete = Sensei_Utils::user_completed_lesson( $lesson_prerequisite_id, $current_user->ID);
796
+
797
+					// Handle restrictions
798
+					if( sensei_all_access() ) {
799
+						$user_allowed = true;
800
+					} else {
801
+						if ( 0 < absint( $lesson_prerequisite_id ) && ( !$user_lesson_prerequisite_complete ) ) {
802
+							$this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' );
803
+							$lesson_link = '<a href="' . esc_url( get_permalink( $lesson_prerequisite_id ) ) . '">' . __( 'lesson', 'woothemes-sensei' ) . '</a>';
804
+							$this->permissions_message['message'] = sprintf( __('Please complete the previous %1$s before taking this Quiz.', 'woothemes-sensei' ), $lesson_link );
805
+						} else {
806
+							$user_allowed = true;
807
+						} // End If Statement
808
+					} // End If Statement
809
+				} elseif( $this->access_settings() ) {
810
+					// Check if the user has started the course
811
+
812
+					if ( is_user_logged_in() && ! Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) && ( isset( $this->settings->settings['access_permission'] ) && ( true == $this->settings->settings['access_permission'] ) ) ) {
813
+
814
+						$user_allowed = false;
815
+						$this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' );
816
+						$course_link = '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>';
817
+						$wc_post_id = get_post_meta( $lesson_course_id, '_course_woocommerce_product',true );
818
+						if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) {
819
+							$this->permissions_message['message'] = sprintf( __('Please purchase the %1$s before starting this Quiz.', 'woothemes-sensei' ), $course_link );
820
+						} else {
821
+							$this->permissions_message['message'] = sprintf( __('Please sign up for the %1$s before starting this Quiz.', 'woothemes-sensei' ), $course_link );
822
+						} // End If Statement
823
+					} else {
824
+						$user_allowed = true;
825
+					} // End If Statement
826
+				} else {
827
+					$this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' );
828
+					$course_link = '<a href="' . esc_url( get_permalink( get_post_meta( get_post_meta( $post->ID, '_quiz_lesson', true ), '_lesson_course', true ) ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>';
829
+					$this->permissions_message['message'] = sprintf( __('Please sign up for the %1$s before taking this Quiz.', 'woothemes-sensei' ), $course_link );
830
+				} // End If Statement
831
+				break;
832
+			default:
833
+				$user_allowed = true;
834
+				break;
835
+
836
+		} // End Switch Statement
837
+
838
+		/**
839
+		 * filter the permissions message shown on sensei post types.
840
+		 *
841
+		 * @since 1.8.7
842
+		 *
843
+		 * @param array $permissions_message{
844
+		 *
845
+		 *   @type string $title
846
+		 *   @type string $message
847
+		 *
848
+		 * }
849
+		 * @param string $post_id
850
+		 */
851
+		$this->permissions_message = apply_filters( 'sensei_permissions_message', $this->permissions_message, $post->ID );
852
+
853
+
854
+		if( sensei_all_access() || Sensei_Utils::is_preview_lesson( $post->ID ) ) {
855
+			$user_allowed = true;
856
+		}
857
+
858
+		return apply_filters( 'sensei_access_permissions', $user_allowed );
859
+	} // End get_placeholder_image()
860
+
861
+
862
+	/**
863
+	 * Check if visitors have access permission. If the "access_permission" setting is active, do a log in check.
864
+	 * @since  1.0.0
865
+	 * @access public
866
+	 * @return bool
867
+	 */
868
+	public function access_settings () {
869
+
870
+		if( sensei_all_access() ) return true;
871
+
872
+		if ( isset( $this->settings->settings['access_permission'] ) && ( true == $this->settings->settings['access_permission'] ) ) {
873
+			if ( is_user_logged_in() ) {
874
+				return true;
875
+			} else {
876
+				return false;
877
+			} // End If Statement
878
+		} else {
879
+			return true;
880
+		} // End If Statement
881
+	} // End access_settings()
882
+
883
+	/**
884
+	 * sensei_woocommerce_complete_order description
885
+	 * @since   1.0.3
886
+	 * @access  public
887
+	 * @param   int $order_id WC order ID
888
+	 * @return  void
889
+	 */
890
+	public function sensei_woocommerce_complete_order ( $order_id = 0 ) {
891
+		$order_user = array();
892
+		// Check for WooCommerce
893
+		if ( Sensei_WC::is_woocommerce_active() && ( 0 < $order_id ) ) {
894
+			// Get order object
895
+			$order = new WC_Order( $order_id );
896
+			$user = get_user_by( 'id', $order->get_user_id() );
897
+			$order_user['ID'] = $user->ID;
898
+			$order_user['user_login'] = $user->user_login;
899
+			$order_user['user_email'] = $user->user_email;
900
+			$order_user['user_url'] = $user->user_url;
901
+			// Run through each product ordered
902
+			if ( 0 < sizeof( $order->get_items() ) ) {
903
+				foreach( $order->get_items() as $item ) {
904
+					$product_type = '';
905
+					if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
906
+						$item_id = $item['variation_id'];
907
+						$product_type = 'variation';
908
+					} else {
909
+						$item_id = $item['product_id'];
910
+					} // End If Statement
911
+					$_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type );
912
+					// Get courses that use the WC product
913
+					$courses = $this->post_types->course->get_product_courses( $_product->id );
914
+					// Loop and update those courses
915
+					foreach ( $courses as $course_item ) {
916
+						$update_course = $this->woocommerce_course_update( $course_item->ID, $order_user );
917
+					} // End For Loop
918
+				} // End For Loop
919
+			} // End If Statement
920
+			// Add meta to indicate that payment has been completed successfully
921
+			update_post_meta( $order_id, 'sensei_payment_complete', '1' );
922
+		} // End If Statement
923
+	} // End sensei_woocommerce_complete_order()
924
+
925
+	/**
926
+	 * Runs when an order is cancelled.
927
+	 * @since   1.2.0
928
+	 * @access  public
929
+	 * @param   integer $order_id order ID
930
+	 * @return  void
931
+	 */
932
+	public function sensei_woocommerce_cancel_order ( $order_id ) {
933
+
934
+		// Get order object
935
+		$order = new WC_Order( $order_id );
936
+
937
+		// Run through each product ordered
938
+		if ( 0 < sizeof( $order->get_items() ) ) {
939
+
940
+			// Get order user
941
+			$user_id = $order->__get( 'user_id' );
942
+
943
+			foreach( $order->get_items() as $item ) {
944
+
945
+				$product_type = '';
946
+				if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
947
+					$item_id = $item['variation_id'];
948
+					$product_type = 'variation';
949
+				} else {
950
+					$item_id = $item['product_id'];
951
+				} // End If Statement
952
+				$_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type );
953
+
954
+				// Get courses that use the WC product
955
+				$courses = array();
956
+				$courses = $this->post_types->course->get_product_courses( $item_id );
957
+
958
+				// Loop and update those courses
959
+				foreach ($courses as $course_item){
960
+					// Check and Remove course from courses user meta
961
+					$dataset_changes = Sensei_Utils::sensei_remove_user_from_course( $course_item->ID, $user_id );
962
+				} // End For Loop
963
+			} // End For Loop
964
+		} // End If Statement
965
+	} // End sensei_woocommerce_cancel_order()
966
+
967
+	/**
968
+	 * Runs when an subscription is cancelled or expires.
969
+	 * @since   1.3.3
970
+	 * @access  public
971
+	 * @param   integer $user_id User ID
972
+	 * @param   integer $subscription_key Subscription Unique Key
973
+	 * @return  void
974
+	 */
975
+	public function sensei_woocommerce_subscription_ended( $user_id, $subscription_key ) {
976
+		$subscription = WC_Subscriptions_Manager::get_users_subscription( $user_id, $subscription_key );
977
+		self::sensei_woocommerce_cancel_order( $subscription['order_id'] );
978
+	}
979
+
980
+	/**
981
+	 * Runs when an subscription is re-activated after suspension.
982
+	 * @since   1.3.3
983
+	 * @access  public
984
+	 * @param   integer $user_id User ID
985
+	 * @param   integer $subscription_key Subscription Unique Key
986
+	 * @return  void
987
+	 */
988
+	public function sensei_woocommerce_reactivate_subscription( $user_id, $subscription_key ) {
989
+		$subscription = WC_Subscriptions_Manager::get_users_subscription( $user_id, $subscription_key );
990
+		$order = new WC_Order( $subscription['order_id'] );
991
+		$user = get_user_by( 'id', $order->get_user_id() );
992
+		$order_user = array();
993
+		$order_user['ID'] = $user->ID;
994
+		$order_user['user_login'] = $user->user_login;
995
+		$order_user['user_email'] = $user->user_email;
996
+		$order_user['user_url'] = $user->user_url;
997
+		$courses = $this->post_types->course->get_product_courses( $subscription['product_id'] );
998
+		foreach ( $courses as $course_item ){
999
+			$update_course = $this->woocommerce_course_update( $course_item->ID, $order_user );
1000
+		} // End For Loop
1001
+	} // End sensei_woocommerce_reactivate_subscription
1002
+
1003
+	/**
1004
+	 * Returns the WooCommerce Product Object
1005
+	 *
1006
+	 * The code caters for pre and post WooCommerce 2.2 installations.
1007
+	 *
1008
+	 * @since   1.1.1
1009
+	 * @access  public
1010
+	 * @param   integer $wc_product_id Product ID or Variation ID
1011
+	 * @param   string  $product_type  '' or 'variation'
1012
+	 * @return   WC_Product $wc_product_object
1013
+	 */
1014
+	public function sensei_get_woocommerce_product_object ( $wc_product_id = 0, $product_type = '' ) {
1015
+
1016
+		$wc_product_object = false;
1017
+		if ( 0 < intval( $wc_product_id ) ) {
1018
+
1019
+			// Get the product
1020
+			if ( function_exists( 'wc_get_product' ) ) {
1021
+
1022
+				$wc_product_object = wc_get_product( $wc_product_id ); // Post WC 2.3
1023
+
1024
+			} elseif ( function_exists( 'get_product' ) ) {
1025
+
1026
+				$wc_product_object = get_product( $wc_product_id ); // Post WC 2.0
1027
+
1028
+			} else {
1029
+
1030
+				// Pre WC 2.0
1031
+				if ( 'variation' == $product_type || 'subscription_variation' == $product_type ) {
1032
+
1033
+					$wc_product_object = new WC_Product_Variation( $wc_product_id );
1034
+
1035
+				} else {
1036
+
1037
+					$wc_product_object = new WC_Product( $wc_product_id );
1038
+
1039
+				} // End If Statement
1040
+
1041
+			} // End If Statement
1042
+
1043
+		} // End If Statement
1044
+
1045
+		return $wc_product_object;
1046
+
1047
+	} // End sensei_get_woocommerce_product_object()
1048
+
1049
+	/**
1050
+	 * load_class loads in class files
1051
+	 * @since   1.2.0
1052
+	 * @access  public
1053
+	 * @return  void
1054
+	 */
1055
+	public function load_class ( $class_name = '' ) {
1056
+		if ( '' != $class_name && '' != $this->token ) {
1057
+			require_once( 'class-' . esc_attr( $this->token ) . '-' . esc_attr( $class_name ) . '.php' );
1058
+		} // End If Statement
1059
+	} // End load_class()
1060
+
1061
+	/**
1062
+	 * sensei_activate_subscription runs when a subscription product is purchased
1063
+	 * @since   1.2.0
1064
+	 * @access  public
1065
+	 * @param   integer $order_id order ID
1066
+	 * @return  void
1067
+	 */
1068
+	public function sensei_activate_subscription(  $order_id = 0 ) {
1069
+		if ( 0 < intval( $order_id ) ) {
1070
+			$order = new WC_Order( $order_id );
1071
+			$user = get_user_by('id', $order->user_id);
1072
+			$order_user['ID'] = $user->ID;
1073
+			$order_user['user_login'] = $user->user_login;
1074
+			$order_user['user_email'] = $user->user_email;
1075
+			$order_user['user_url'] = $user->user_url;
1076
+			// Run through each product ordered
1077
+			if (sizeof($order->get_items())>0) {
1078
+				foreach($order->get_items() as $item) {
1079
+					$product_type = '';
1080
+					if (isset($item['variation_id']) && $item['variation_id'] > 0) {
1081
+						$item_id = $item['variation_id'];
1082
+						$product_type = 'subscription_variation';
1083
+					} else {
1084
+						$item_id = $item['product_id'];
1085
+					} // End If Statement
1086
+					$_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type );
1087
+					// Get courses that use the WC product
1088
+					$courses = array();
1089
+					if ( $product_type == 'subscription_variation' ) {
1090
+						$courses = $this->post_types->course->get_product_courses( $item_id );
1091
+					} // End If Statement
1092
+					// Loop and update those courses
1093
+					foreach ($courses as $course_item){
1094
+						$update_course = $this->woocommerce_course_update( $course_item->ID, $order_user );
1095
+					} // End For Loop
1096
+				} // End For Loop
1097
+			} // End If Statement
1098
+		} // End If Statement
1099
+	} // End sensei_activate_subscription()
1100
+
1101
+	/**
1102
+	 * sensei_woocommerce_email_course_details adds detail to email
1103
+	 * @since   1.4.5
1104
+	 * @access  public
1105
+	 * @param   WC_Order $order
1106
+	 * @return  void
1107
+	 */
1108
+	public function sensei_woocommerce_email_course_details( $order ) {
1109
+		global $woocommerce;
1110
+
1111
+		// exit early if not wc-completed or wc-processing
1112
+		if( 'wc-completed' != $order->post_status
1113
+			&& 'wc-processing' != $order->post_status  ) {
1114
+			return;
1115
+		}
1116
+
1117
+		$order_items = $order->get_items();
1118
+		$order_id = $order->id;
1119
+
1120
+		//If object have items go through them all to find course
1121
+		if ( 0 < sizeof( $order_items ) ) {
1122
+
1123
+			$course_details_html =  '<h2>' . __( 'Course details', 'woothemes-sensei' ) . '</h2>';
1124
+			$order_contains_courses = false;
1125
+
1126
+
1127
+			foreach ( $order_items as $item ) {
1128
+
1129
+				$product_type = '';
1130
+				if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
1131
+					// If item has variation_id then its from variation
1132
+					$item_id = $item['variation_id'];
1133
+					$product_type = 'variation';
1134
+				} else {
1135
+					// If not its real product set its id to item_id
1136
+					$item_id = $item['product_id'];
1137
+				} // End If Statement
1138
+
1139
+				$user_id = get_post_meta( $order_id, '_customer_user', true );
1140
+
1141
+				if( $user_id ) {
1142
+
1143
+					// Get all courses for product
1144
+					$args = array(
1145
+						'posts_per_page' => -1,
1146
+						'post_type' => 'course',
1147
+						'meta_query' => array(
1148
+							array(
1149
+								'key' => '_course_woocommerce_product',
1150
+								'value' => $item_id
1151
+							)
1152
+						),
1153
+						'orderby' => 'menu_order date',
1154
+						'order' => 'ASC',
1155
+					);
1156
+					$courses = get_posts( $args );
1157
+
1158
+					if( $courses && count( $courses ) > 0 ) {
1159
+
1160
+						foreach( $courses as $course ) {
1161
+
1162
+							$title = $course->post_title;
1163
+							$permalink = get_permalink( $course->ID );
1164
+							$order_contains_courses = true;
1165
+							$course_details_html .=  '<p><strong>' . sprintf( __( 'View course: %1$s', 'woothemes-sensei' ), '</strong><a href="' . esc_url( $permalink ) . '">' . $title . '</a>' ) . '</p>';
1166
+						}
1167
+
1168
+
1169
+					} // end if has courses
1170
+
1171
+				} // end if $userPid
1172
+
1173
+			} // end for each order item
1174
+
1175
+			// Output Course details
1176
+			if( $order_contains_courses ){
1177
+
1178
+				echo $course_details_html;
1179
+
1180
+			}
1181
+
1182
+
1183
+		} // end if  order items not empty
1184
+
1185
+	} // end func email course details
1186
+
1187
+	/**
1188
+	 * Filtering wp_count_comments to ensure that Sensei comments are ignored
1189
+	 * @since   1.4.0
1190
+	 * @access  public
1191
+	 * @param  array   $comments
1192
+	 * @param  integer $post_id
1193
+	 * @return array
1194
+	 */
1195
+	public function sensei_count_comments( $comments, $post_id ) {
1196
+		global $wpdb;
1197
+
1198
+		$post_id = (int) $post_id;
1199
+
1200
+		$count = wp_cache_get("comments-{$post_id}", 'counts');
1201
+
1202
+		if ( false !== $count ) {
1203
+			return $count;
1204
+		}
1205
+
1206
+		$statuses = array( '' ); // Default to the WP normal comments
1207
+		$stati = $wpdb->get_results( "SELECT comment_type FROM {$wpdb->comments} GROUP BY comment_type", ARRAY_A );
1208
+		foreach ( (array) $stati AS $status ) {
1209
+			if ( 'sensei_' != substr($status['comment_type'], 0, 7 ) ) {
1210
+				$statuses[] = $status['comment_type'];
1211
+			}
1212
+		}
1213
+		$where = "WHERE comment_type IN ('" . join("', '", array_unique( $statuses ) ) . "')";
1214
+
1215
+		if ( $post_id > 0 )
1216
+			$where .= $wpdb->prepare( " AND comment_post_ID = %d", $post_id );
1217
+
1218
+		$count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A );
1219
+
1220
+		$total = 0;
1221
+		$approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash', 'post-trashed' => 'post-trashed');
1222
+		foreach ( (array) $count as $row ) {
1223
+			// Don't count post-trashed toward totals
1224
+			if ( 'post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'] )
1225
+				$total += $row['num_comments'];
1226
+			if ( isset( $approved[$row['comment_approved']] ) )
1227
+				$stats[$approved[$row['comment_approved']]] = $row['num_comments'];
1228
+		}
1229
+
1230
+		$stats['total_comments'] = $total;
1231
+		foreach ( $approved as $key ) {
1232
+			if ( empty($stats[$key]) )
1233
+				$stats[$key] = 0;
1234
+		}
1235
+
1236
+		$stats = (object) $stats;
1237
+		wp_cache_set("comments-{$post_id}", $stats, 'counts');
1238
+
1239
+		return $stats;
1240
+	}
1241
+
1242
+	/**
1243
+	 * Init images.
1244
+	 *
1245
+	 * @since 1.4.5
1246
+	 * @access public
1247
+	 * @return void
1248
+	 */
1249
+	public function init_image_sizes() {
1250
+		$course_archive_thumbnail 	= $this->get_image_size( 'course_archive_image' );
1251
+		$course_single_thumbnail	= $this->get_image_size( 'course_single_image' );
1252
+		$lesson_archive_thumbnail 	= $this->get_image_size( 'lesson_archive_image' );
1253
+		$lesson_single_thumbnail	= $this->get_image_size( 'lesson_single_image' );
1254
+
1255
+		add_image_size( 'course_archive_thumbnail', $course_archive_thumbnail['width'], $course_archive_thumbnail['height'], $course_archive_thumbnail['crop'] );
1256
+		add_image_size( 'course_single_thumbnail', $course_single_thumbnail['width'], $course_single_thumbnail['height'], $course_single_thumbnail['crop'] );
1257
+		add_image_size( 'lesson_archive_thumbnail', $lesson_archive_thumbnail['width'], $lesson_archive_thumbnail['height'], $lesson_archive_thumbnail['crop'] );
1258
+		add_image_size( 'lesson_single_thumbnail', $lesson_single_thumbnail['width'], $lesson_single_thumbnail['height'], $lesson_single_thumbnail['crop'] );
1259
+	}
1260
+
1261
+	/**
1262
+	 * Get an image size.
1263
+	 *
1264
+	 * Variable is filtered by sensei_get_image_size_{image_size}
1265
+	 *
1266
+	 * @since 1.4.5
1267
+	 * @access public
1268
+	 * @param mixed $image_size
1269
+	 * @return string
1270
+	 */
1271
+	public function get_image_size( $image_size ) {
1272
+
1273
+		// Only return sizes we define in settings
1274
+		if ( ! in_array( $image_size, array( 'course_archive_image', 'course_single_image', 'lesson_archive_image', 'lesson_single_image' ) ) )
1275
+			return apply_filters( 'sensei_get_image_size_' . $image_size, '' );
1276
+
1277
+		if( ! isset( $this->settings->settings[ $image_size . '_width' ] ) ) {
1278
+			$this->settings->settings[ $image_size . '_width' ] = false;
1279
+		}
1280
+		if( ! isset( $this->settings->settings[ $image_size . '_height' ] ) ) {
1281
+			$this->settings->settings[ $image_size . '_height' ] = false;
1282
+		}
1283
+		if( ! isset( $this->settings->settings[ $image_size . '_hard_crop' ] ) ) {
1284
+			$this->settings->settings[ $image_size . '_hard_crop' ] = false;
1285
+		}
1286
+
1287
+		$size = array_filter( array(
1288
+			'width' => $this->settings->settings[ $image_size . '_width' ],
1289
+			'height' => $this->settings->settings[ $image_size . '_height' ],
1290
+			'crop' => $this->settings->settings[ $image_size . '_hard_crop' ]
1291
+		) );
1292
+
1293
+		$size['width'] 	= isset( $size['width'] ) ? $size['width'] : '100';
1294
+		$size['height'] = isset( $size['height'] ) ? $size['height'] : '100';
1295
+		$size['crop'] 	= isset( $size['crop'] ) ? $size['crop'] : 0;
1296
+
1297
+		return apply_filters( 'sensei_get_image_size_' . $image_size, $size );
1298
+	}
1299
+
1300
+	public function body_class( $classes ) {
1301
+		if( is_sensei() ) {
1302
+			$classes[] = 'sensei';
1303
+		}
1304
+		return $classes;
1305
+	}
1306
+
1307
+	/**
1308
+	 * Checks that the Jetpack Beautiful Maths module has been activated to support LaTeX within question titles and answers
1309
+	 *
1310
+	 * @return null
1311
+	 * @since 1.7.0
1312
+	 */
1313
+	public function jetpack_latex_support() {
1314
+		if ( function_exists( 'latex_markup') ) {
1315
+			add_filter( 'sensei_question_title', 'latex_markup' );
1316
+			add_filter( 'sensei_answer_text', 'latex_markup' );
1317
+		}
1318
+	}
1319
+
1320
+	/**
1321
+	 * Load the module functionality.
1322
+	 *
1323
+	 * This function is hooked into plugins_loaded to avoid conflicts with
1324
+	 * the retired modules extension.
1325
+	 *
1326
+	 * @since 1.8.0
1327
+	 */
1328
+	public function load_modules_class(){
1329
+		global $sensei_modules;
1330
+
1331
+		if( !class_exists( 'Sensei_Modules' )
1332
+			&&  'Sensei_Modules' != get_class( $sensei_modules ) ) {
1333
+
1334
+			//Load the modules class
1335
+			require_once( 'class-sensei-modules.php');
1336
+			Sensei()->modules = new Sensei_Core_Modules( $this->file );
1337
+
1338
+		}else{
1339
+			// fallback for people still using the modules extension.
1340
+			global $sensei_modules;
1341
+			Sensei()->modules = $sensei_modules;
1342
+			add_action( 'admin_notices', array( $this, 'disable_sensei_modules_extension'), 30 );
1343
+		}
1344
+	}
1345
+
1346
+	/**
1347
+	 * Tell the user to that the modules extension is no longer needed.
1348
+	 *
1349
+	 * @since 1.8.0
1350
+	 */
1351
+	public function disable_sensei_modules_extension(){ ?>
1352 1352
         <div class="notice updated fade">
1353 1353
             <p>
1354 1354
                 <?php
1355
-                $plugin_manage_url = admin_url().'plugins.php#sensei-modules';
1356
-                $plugin_link_element = '<a href="' . $plugin_manage_url . '" >plugins page</a> ';
1357
-                ?>
1355
+				$plugin_manage_url = admin_url().'plugins.php#sensei-modules';
1356
+				$plugin_link_element = '<a href="' . $plugin_manage_url . '" >plugins page</a> ';
1357
+				?>
1358 1358
                 <strong> Modules are now included in Sensei,</strong> so you no longer need the Sensei Modules extension.
1359 1359
                 Please deactivate and delete it from your <?php echo $plugin_link_element; ?>. (This will not affect your existing modules).
1360 1360
             </p>
@@ -1362,46 +1362,46 @@  discard block
 block discarded – undo
1362 1362
 
1363 1363
     <?php }// end function
1364 1364
 
1365
-    /**
1366
-     * Sensei wide rewrite flush call.
1367
-     *
1368
-     * To use this simply update the option 'sensei_flush_rewrite_rules' to 1
1369
-     *
1370
-     * After the option is one the Rules will be flushed.
1371
-     *
1372
-     * @since 1.9.0
1373
-     */
1374
-    public function flush_rewrite_rules(){
1365
+	/**
1366
+	 * Sensei wide rewrite flush call.
1367
+	 *
1368
+	 * To use this simply update the option 'sensei_flush_rewrite_rules' to 1
1369
+	 *
1370
+	 * After the option is one the Rules will be flushed.
1371
+	 *
1372
+	 * @since 1.9.0
1373
+	 */
1374
+	public function flush_rewrite_rules(){
1375 1375
 
1376
-        // ensures that the rewrite rules are flushed on the second
1377
-        // attempt. This ensure that the settings for any other process
1378
-        // have been completed and saved to the database before we refresh the
1379
-        // rewrite rules.
1380
-        $option =  get_option('sensei_flush_rewrite_rules');
1381
-        if( '1' == $option ) {
1376
+		// ensures that the rewrite rules are flushed on the second
1377
+		// attempt. This ensure that the settings for any other process
1378
+		// have been completed and saved to the database before we refresh the
1379
+		// rewrite rules.
1380
+		$option =  get_option('sensei_flush_rewrite_rules');
1381
+		if( '1' == $option ) {
1382 1382
 
1383
-            update_option('sensei_flush_rewrite_rules', '2');
1383
+			update_option('sensei_flush_rewrite_rules', '2');
1384 1384
 
1385
-        }elseif( '2' == $option ) {
1385
+		}elseif( '2' == $option ) {
1386 1386
 
1387
-            flush_rewrite_rules();
1388
-            update_option('sensei_flush_rewrite_rules', '0');
1387
+			flush_rewrite_rules();
1388
+			update_option('sensei_flush_rewrite_rules', '0');
1389 1389
 
1390
-        }
1390
+		}
1391 1391
 
1392
-    } // end flush_rewrite_rules
1392
+	} // end flush_rewrite_rules
1393 1393
 
1394
-    /**
1395
-     * Calling this function will tell Sensei to flush rewrite
1396
-     * rules on the next load.
1397
-     *
1398
-     * @since 1.9.0
1399
-     */
1400
-    public function initiate_rewrite_rules_flush(){
1394
+	/**
1395
+	 * Calling this function will tell Sensei to flush rewrite
1396
+	 * rules on the next load.
1397
+	 *
1398
+	 * @since 1.9.0
1399
+	 */
1400
+	public function initiate_rewrite_rules_flush(){
1401 1401
 
1402
-        update_option('sensei_flush_rewrite_rules', '1');
1402
+		update_option('sensei_flush_rewrite_rules', '1');
1403 1403
 
1404
-    }
1404
+	}
1405 1405
 
1406 1406
 } // End Class
1407 1407
 
Please login to merge, or discard this patch.
Spacing   +307 added lines, -307 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_Main
@@ -146,23 +146,23 @@  discard block
 block discarded – undo
146 146
      * @param  string $file The base file of the plugin.
147 147
      * @since  1.0.0
148 148
      */
149
-    public function __construct ( $file ) {
149
+    public function __construct($file) {
150 150
 
151 151
         // Setup object data
152 152
         $this->file = $file;
153
-        $this->plugin_url = trailingslashit( plugins_url( '', $plugin = $file ) );
154
-        $this->plugin_path = trailingslashit( dirname( $file ) );
155
-        $this->template_url	= apply_filters( 'sensei_template_url', 'sensei/' );
156
-        $this->permissions_message = array( 'title' => __( 'Permission Denied', 'woothemes-sensei' ), 'message' => __( 'Unfortunately you do not have permissions to access this page.', 'woothemes-sensei' ) );
153
+        $this->plugin_url = trailingslashit(plugins_url('', $plugin = $file));
154
+        $this->plugin_path = trailingslashit(dirname($file));
155
+        $this->template_url = apply_filters('sensei_template_url', 'sensei/');
156
+        $this->permissions_message = array('title' => __('Permission Denied', 'woothemes-sensei'), 'message' => __('Unfortunately you do not have permissions to access this page.', 'woothemes-sensei'));
157 157
 
158 158
         // Initialize the core Sensei functionality
159 159
         $this->init();
160 160
 
161 161
         // Installation
162
-        if ( is_admin() && ! defined( 'DOING_AJAX' ) ) $this->install();
162
+        if (is_admin() && ! defined('DOING_AJAX')) $this->install();
163 163
 
164 164
         // Run this on activation.
165
-        register_activation_hook( $this->file, array( $this, 'activation' ) );
165
+        register_activation_hook($this->file, array($this, 'activation'));
166 166
 
167 167
         // Image Sizes
168 168
         $this->init_image_sizes();
@@ -179,11 +179,11 @@  discard block
 block discarded – undo
179 179
      * Load the foundations of Sensei.
180 180
      * @since 1.9.0
181 181
      */
182
-    protected function init(){
182
+    protected function init() {
183 183
 
184 184
         // Localisation
185 185
         $this->load_plugin_textdomain();
186
-        add_action( 'init', array( $this, 'load_localisation' ), 0 );
186
+        add_action('init', array($this, 'load_localisation'), 0);
187 187
 
188 188
         // load the shortcode loader into memory, so as to listen to all for
189 189
         // all shortcodes on the front end
@@ -203,12 +203,12 @@  discard block
 block discarded – undo
203 203
      */
204 204
     public static function instance() {
205 205
 
206
-        if ( is_null( self::$_instance ) ) {
206
+        if (is_null(self::$_instance)) {
207 207
 
208 208
             //Sensei requires a reference to the main Sensei plugin file
209
-            $sensei_main_plugin_file = dirname ( dirname( __FILE__ ) ) . '/woothemes-sensei.php';
209
+            $sensei_main_plugin_file = dirname(dirname(__FILE__)).'/woothemes-sensei.php';
210 210
 
211
-            self::$_instance = new self( $sensei_main_plugin_file  );
211
+            self::$_instance = new self($sensei_main_plugin_file);
212 212
 
213 213
             // load the global class objects needed throughout Sensei
214 214
             self::$_instance->initialize_global_objects();
@@ -227,9 +227,9 @@  discard block
 block discarded – undo
227 227
      *
228 228
      * @param $plugin
229 229
      */
230
-    public static function activation_flush_rules( $plugin ){
230
+    public static function activation_flush_rules($plugin) {
231 231
 
232
-        if( strpos( $plugin, '/woothemes-sensei.php' ) > 0  ){
232
+        if (strpos($plugin, '/woothemes-sensei.php') > 0) {
233 233
 
234 234
             flush_rewrite_rules(true);
235 235
 
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
      * @since 1.8.0
243 243
      */
244 244
     public function __clone() {
245
-        _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'woothemes-sensei' ), '1.8' );
245
+        _doing_it_wrong(__FUNCTION__, __('Cheatin&#8217; huh?', 'woothemes-sensei'), '1.8');
246 246
     }
247 247
 
248 248
     /**
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
      * @since 1.8.0
251 251
      */
252 252
     public function __wakeup() {
253
-        _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'woothemes-sensei' ), '1.8' );
253
+        _doing_it_wrong(__FUNCTION__, __('Cheatin&#8217; huh?', 'woothemes-sensei'), '1.8');
254 254
     }
255 255
 
256 256
     /**
@@ -258,13 +258,13 @@  discard block
 block discarded – undo
258 258
      *
259 259
      * @since 1.9.0
260 260
      */
261
-    public function initialize_global_objects(){
261
+    public function initialize_global_objects() {
262 262
 
263 263
         // Setup post types.
264 264
         $this->post_types = new Sensei_PostTypes();
265 265
 
266 266
         // Lad the updates class
267
-        $this->updates = new Sensei_Updates( $this );
267
+        $this->updates = new Sensei_Updates($this);
268 268
 
269 269
         // Setup settings
270 270
         $this->settings = new Sensei_Settings();
@@ -288,22 +288,22 @@  discard block
 block discarded – undo
288 288
         $this->quiz = $this->post_types->quiz;
289 289
 
290 290
         // load the modules class after all plugsin are loaded
291
-        add_action( 'plugins_loaded', array( $this, 'load_modules_class' ) );
291
+        add_action('plugins_loaded', array($this, 'load_modules_class'));
292 292
 
293 293
         // Load Learner Management Functionality
294
-        $this->learners = new Sensei_Learner_Management( $this->file );
294
+        $this->learners = new Sensei_Learner_Management($this->file);
295 295
 
296 296
         // Differentiate between administration and frontend logic.
297
-        if ( is_admin() ) {
297
+        if (is_admin()) {
298 298
 
299 299
             // Load Admin Welcome class
300 300
             new Sensei_Welcome();
301 301
 
302 302
             // Load Admin Class
303
-            $this->admin = new Sensei_Admin( $this->file );
303
+            $this->admin = new Sensei_Admin($this->file);
304 304
 
305 305
             // Load Analysis Reports
306
-            $this->analysis = new Sensei_Analysis( $this->file );
306
+            $this->analysis = new Sensei_Analysis($this->file);
307 307
 
308 308
         } else {
309 309
 
@@ -320,10 +320,10 @@  discard block
 block discarded – undo
320 320
         }
321 321
 
322 322
         // Load Grading Functionality
323
-        $this->grading = new Sensei_Grading( $this->file );
323
+        $this->grading = new Sensei_Grading($this->file);
324 324
 
325 325
         // Load Email Class
326
-        $this->emails = new Sensei_Emails( $this->file );
326
+        $this->emails = new Sensei_Emails($this->file);
327 327
 
328 328
         // Load Learner Profiles Class
329 329
         $this->learner_profiles = new Sensei_Learner_Profiles();
@@ -335,40 +335,40 @@  discard block
 block discarded – undo
335 335
      *
336 336
      * @since 1.9.0
337 337
      */
338
-    public function load_hooks(){
338
+    public function load_hooks() {
339 339
 
340
-        add_action( 'widgets_init', array( $this, 'register_widgets' ) );
341
-        add_action( 'after_setup_theme', array( $this, 'ensure_post_thumbnails_support' ) );
340
+        add_action('widgets_init', array($this, 'register_widgets'));
341
+        add_action('after_setup_theme', array($this, 'ensure_post_thumbnails_support'));
342 342
 
343 343
         // WooCommerce Payment Actions
344
-        add_action( 'woocommerce_payment_complete' , array( $this, 'sensei_woocommerce_complete_order' ) );
345
-        add_action( 'woocommerce_thankyou' , array( $this, 'sensei_woocommerce_complete_order' ) );
346
-        add_action( 'woocommerce_order_status_completed' , array( $this, 'sensei_woocommerce_complete_order' ) );
347
-        add_action( 'woocommerce_order_status_processing' , array( $this, 'sensei_woocommerce_complete_order' ) );
348
-        add_action( 'woocommerce_order_status_cancelled' , array( $this, 'sensei_woocommerce_cancel_order' ) );
349
-        add_action( 'woocommerce_order_status_refunded' , array( $this, 'sensei_woocommerce_cancel_order' ) );
350
-        add_action( 'subscriptions_activated_for_order', array( $this, 'sensei_activate_subscription' ) );
344
+        add_action('woocommerce_payment_complete', array($this, 'sensei_woocommerce_complete_order'));
345
+        add_action('woocommerce_thankyou', array($this, 'sensei_woocommerce_complete_order'));
346
+        add_action('woocommerce_order_status_completed', array($this, 'sensei_woocommerce_complete_order'));
347
+        add_action('woocommerce_order_status_processing', array($this, 'sensei_woocommerce_complete_order'));
348
+        add_action('woocommerce_order_status_cancelled', array($this, 'sensei_woocommerce_cancel_order'));
349
+        add_action('woocommerce_order_status_refunded', array($this, 'sensei_woocommerce_cancel_order'));
350
+        add_action('subscriptions_activated_for_order', array($this, 'sensei_activate_subscription'));
351 351
 
352 352
         // WooCommerce Subscriptions Actions
353
-        add_action( 'reactivated_subscription', array( $this, 'sensei_woocommerce_reactivate_subscription' ), 10, 2 );
354
-        add_action( 'subscription_expired' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 );
355
-        add_action( 'subscription_end_of_prepaid_term' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 );
356
-        add_action( 'cancelled_subscription' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 );
357
-        add_action( 'subscription_put_on-hold' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 );
353
+        add_action('reactivated_subscription', array($this, 'sensei_woocommerce_reactivate_subscription'), 10, 2);
354
+        add_action('subscription_expired', array($this, 'sensei_woocommerce_subscription_ended'), 10, 2);
355
+        add_action('subscription_end_of_prepaid_term', array($this, 'sensei_woocommerce_subscription_ended'), 10, 2);
356
+        add_action('cancelled_subscription', array($this, 'sensei_woocommerce_subscription_ended'), 10, 2);
357
+        add_action('subscription_put_on-hold', array($this, 'sensei_woocommerce_subscription_ended'), 10, 2);
358 358
 
359 359
         // Add Email link to course orders
360
-        add_action( 'woocommerce_email_after_order_table', array( $this, 'sensei_woocommerce_email_course_details' ), 10, 1 );
360
+        add_action('woocommerce_email_after_order_table', array($this, 'sensei_woocommerce_email_course_details'), 10, 1);
361 361
 
362 362
         // Filter comment counts
363
-        add_filter( 'wp_count_comments', array( $this, 'sensei_count_comments' ), 10, 2 );
363
+        add_filter('wp_count_comments', array($this, 'sensei_count_comments'), 10, 2);
364 364
 
365
-        add_action( 'body_class', array( $this, 'body_class' ) );
365
+        add_action('body_class', array($this, 'body_class'));
366 366
 
367 367
         // Check for and activate JetPack LaTeX support
368
-        add_action( 'plugins_loaded', array( $this, 'jetpack_latex_support'), 200 ); // Runs after Jetpack has loaded it's modules
368
+        add_action('plugins_loaded', array($this, 'jetpack_latex_support'), 200); // Runs after Jetpack has loaded it's modules
369 369
 
370 370
         // check flush the rewrite rules if the option sensei_flush_rewrite_rules option is 1
371
-        add_action( 'init', array( $this, 'flush_rewrite_rules'), 101 );
371
+        add_action('init', array($this, 'flush_rewrite_rules'), 101);
372 372
 
373 373
     }
374 374
 
@@ -380,7 +380,7 @@  discard block
 block discarded – undo
380 380
      */
381 381
     public function run_updates() {
382 382
         // Run updates if administrator
383
-        if ( current_user_can( 'manage_options' ) || current_user_can( 'manage_sensei' ) ) {
383
+        if (current_user_can('manage_options') || current_user_can('manage_sensei')) {
384 384
 
385 385
             $this->updates->update();
386 386
 
@@ -397,10 +397,10 @@  discard block
 block discarded – undo
397 397
      */
398 398
     public function set_woocommerce_functionality() {
399 399
         // Disable guest checkout if a course is in the cart as we need a valid user to store data for
400
-        add_filter( 'pre_option_woocommerce_enable_guest_checkout', array( $this, 'disable_guest_checkout' ) );
400
+        add_filter('pre_option_woocommerce_enable_guest_checkout', array($this, 'disable_guest_checkout'));
401 401
 
402 402
         // Mark orders with virtual products as complete rather then stay processing
403
-        add_filter( 'woocommerce_payment_complete_order_status', array( $this, 'virtual_order_payment_complete' ), 10, 2 );
403
+        add_filter('woocommerce_payment_complete_order_status', array($this, 'virtual_order_payment_complete'), 10, 2);
404 404
 
405 405
     } // End set_woocommerce_functionality()
406 406
 
@@ -409,14 +409,14 @@  discard block
 block discarded – undo
409 409
      * @param  boolean $guest_checkout Current guest checkout setting
410 410
      * @return boolean                 Modified guest checkout setting
411 411
      */
412
-    public function disable_guest_checkout( $guest_checkout ) {
412
+    public function disable_guest_checkout($guest_checkout) {
413 413
         global $woocommerce;
414 414
 
415
-        if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
415
+        if ( ! is_admin() || (defined('DOING_AJAX') && DOING_AJAX)) {
416 416
 
417
-            if( isset( $woocommerce->cart->cart_contents ) && count( $woocommerce->cart->cart_contents ) > 0 ) {
418
-                foreach( $woocommerce->cart->cart_contents as $cart_key => $product ) {
419
-                    if( isset( $product['product_id'] ) ) {
417
+            if (isset($woocommerce->cart->cart_contents) && count($woocommerce->cart->cart_contents) > 0) {
418
+                foreach ($woocommerce->cart->cart_contents as $cart_key => $product) {
419
+                    if (isset($product['product_id'])) {
420 420
                         $args = array(
421 421
                             'posts_per_page' => -1,
422 422
                             'post_type' => 'course',
@@ -427,9 +427,9 @@  discard block
 block discarded – undo
427 427
                                 )
428 428
                             )
429 429
                         );
430
-                        $posts = get_posts( $args );
431
-                        if( $posts && count( $posts ) > 0 ) {
432
-                            foreach( $posts as $course ) {
430
+                        $posts = get_posts($args);
431
+                        if ($posts && count($posts) > 0) {
432
+                            foreach ($posts as $course) {
433 433
                                 $guest_checkout = '';
434 434
                                 break;
435 435
                             }
@@ -449,17 +449,17 @@  discard block
 block discarded – undo
449 449
      * @param int $order_id
450 450
      * @return string
451 451
      **/
452
-    public function virtual_order_payment_complete( $order_status, $order_id ) {
453
-        $order = new WC_Order( $order_id );
454
-        if ( ! isset ( $order ) ) return '';
455
-        if ( $order_status == 'wc-processing' && ( $order->post_status == 'wc-on-hold' || $order->post_status == 'wc-pending' || $order->post_status == 'wc-failed' ) ) {
452
+    public function virtual_order_payment_complete($order_status, $order_id) {
453
+        $order = new WC_Order($order_id);
454
+        if ( ! isset ($order)) return '';
455
+        if ($order_status == 'wc-processing' && ($order->post_status == 'wc-on-hold' || $order->post_status == 'wc-pending' || $order->post_status == 'wc-failed')) {
456 456
             $virtual_order = true;
457 457
 
458
-            if ( count( $order->get_items() ) > 0 ) {
459
-                foreach( $order->get_items() as $item ) {
460
-                    if ( $item['product_id'] > 0 ) {
461
-                        $_product = $order->get_product_from_item( $item );
462
-                        if ( ! $_product->is_virtual() ) {
458
+            if (count($order->get_items()) > 0) {
459
+                foreach ($order->get_items() as $item) {
460
+                    if ($item['product_id'] > 0) {
461
+                        $_product = $order->get_product_from_item($item);
462
+                        if ( ! $_product->is_virtual()) {
463 463
                             $virtual_order = false;
464 464
                             break;
465 465
                         } // End If Statement
@@ -468,7 +468,7 @@  discard block
 block discarded – undo
468 468
             } // End If Statement
469 469
 
470 470
             // virtual order, mark as completed
471
-            if ( $virtual_order ) {
471
+            if ($virtual_order) {
472 472
                 return 'completed';
473 473
             } // End If Statement
474 474
         } // End If Statement
@@ -481,21 +481,21 @@  discard block
 block discarded – undo
481 481
      * @since  1.0.0
482 482
      * @return void
483 483
      */
484
-    public function register_widgets () {
484
+    public function register_widgets() {
485 485
         // Widget List (key => value is filename => widget class).
486
-        $widget_list = apply_filters( 'sensei_registered_widgets_list', array( 	'course-component' 	=> 'Course_Component',
486
+        $widget_list = apply_filters('sensei_registered_widgets_list', array('course-component' 	=> 'Course_Component',
487 487
                 'lesson-component' 	=> 'Lesson_Component',
488 488
                 'course-categories' => 'Course_Categories',
489
-                'category-courses' 	=> 'Category_Courses' )
489
+                'category-courses' 	=> 'Category_Courses')
490 490
         );
491
-        foreach ( $widget_list as $key => $value ) {
492
-            if ( file_exists( $this->plugin_path . 'widgets/widget-woothemes-sensei-' . $key  . '.php' ) ) {
493
-                require_once( $this->plugin_path . 'widgets/widget-woothemes-sensei-' . $key  . '.php' );
494
-                register_widget( 'WooThemes_Sensei_' . $value . '_Widget' );
491
+        foreach ($widget_list as $key => $value) {
492
+            if (file_exists($this->plugin_path.'widgets/widget-woothemes-sensei-'.$key.'.php')) {
493
+                require_once($this->plugin_path.'widgets/widget-woothemes-sensei-'.$key.'.php');
494
+                register_widget('WooThemes_Sensei_'.$value.'_Widget');
495 495
             }
496 496
         } // End For Loop
497 497
 
498
-        do_action( 'sensei_register_widgets' );
498
+        do_action('sensei_register_widgets');
499 499
 
500 500
     } // End register_widgets()
501 501
 
@@ -505,8 +505,8 @@  discard block
 block discarded – undo
505 505
      * @since  1.0.0
506 506
      * @return void
507 507
      */
508
-    public function load_localisation () {
509
-        load_plugin_textdomain( 'woothemes-sensei', false, dirname( plugin_basename( $this->file ) ) . '/lang/' );
508
+    public function load_localisation() {
509
+        load_plugin_textdomain('woothemes-sensei', false, dirname(plugin_basename($this->file)).'/lang/');
510 510
     } // End load_localisation()
511 511
 
512 512
     /**
@@ -515,12 +515,12 @@  discard block
 block discarded – undo
515 515
      * @since   1.0.0
516 516
      * @return  void
517 517
      */
518
-    public function load_plugin_textdomain () {
518
+    public function load_plugin_textdomain() {
519 519
         $domain = 'woothemes-sensei';
520 520
         // The "plugin_locale" filter is also used in load_plugin_textdomain()
521
-        $locale = apply_filters( 'plugin_locale', get_locale(), $domain );
522
-        load_textdomain( $domain, WP_LANG_DIR . '/' . $domain . '/' . $domain . '-' . $locale . '.mo' );
523
-        load_plugin_textdomain( $domain, FALSE, dirname( plugin_basename( $this->file ) ) . '/lang/' );
521
+        $locale = apply_filters('plugin_locale', get_locale(), $domain);
522
+        load_textdomain($domain, WP_LANG_DIR.'/'.$domain.'/'.$domain.'-'.$locale.'.mo');
523
+        load_plugin_textdomain($domain, FALSE, dirname(plugin_basename($this->file)).'/lang/');
524 524
     } // End load_plugin_textdomain()
525 525
 
526 526
     /**
@@ -529,7 +529,7 @@  discard block
 block discarded – undo
529 529
      * @since  1.0.0
530 530
      * @return void
531 531
      */
532
-    public function activation () {
532
+    public function activation() {
533 533
         $this->register_plugin_version();
534 534
     } // End activation()
535 535
 
@@ -540,9 +540,9 @@  discard block
 block discarded – undo
540 540
      * @since  1.0.0
541 541
      * @return void
542 542
      */
543
-    public function install () {
544
-        register_activation_hook( $this->file, array( $this, 'activate_sensei' ) );
545
-        register_activation_hook( $this->file, 'flush_rewrite_rules' );
543
+    public function install() {
544
+        register_activation_hook($this->file, array($this, 'activate_sensei'));
545
+        register_activation_hook($this->file, 'flush_rewrite_rules');
546 546
     } // End install()
547 547
 
548 548
 
@@ -552,9 +552,9 @@  discard block
 block discarded – undo
552 552
      * @since  1.0.0
553 553
      * @return void
554 554
      */
555
-    public function activate_sensei () {
556
-        update_option( 'skip_install_sensei_pages', 0 );
557
-        update_option( 'sensei_installed', 1 );
555
+    public function activate_sensei() {
556
+        update_option('skip_install_sensei_pages', 0);
557
+        update_option('sensei_installed', 1);
558 558
     } // End activate_sensei()
559 559
 
560 560
     /**
@@ -563,8 +563,8 @@  discard block
 block discarded – undo
563 563
      * @since  1.0.0
564 564
      * @return void
565 565
      */
566
-    private function register_plugin_version () {
567
-        if ( $this->version != '' ) {
566
+    private function register_plugin_version() {
567
+        if ($this->version != '') {
568 568
 
569 569
             // Check previous version to see if forced updates must run
570 570
             // $old_version = get_option( 'woothemes-sensei-version', false );
@@ -574,7 +574,7 @@  discard block
 block discarded – undo
574 574
             // 	delete_option( 'woothemes-sensei-force-updates' );
575 575
             // }
576 576
 
577
-            update_option( 'woothemes-sensei-version', $this->version );
577
+            update_option('woothemes-sensei-version', $this->version);
578 578
         }
579 579
     } // End register_plugin_version()
580 580
 
@@ -584,8 +584,8 @@  discard block
 block discarded – undo
584 584
      * @since   1.0.1
585 585
      * @return  void
586 586
      */
587
-    public function ensure_post_thumbnails_support () {
588
-        if ( ! current_theme_supports( 'post-thumbnails' ) ) { add_theme_support( 'post-thumbnails' ); }
587
+    public function ensure_post_thumbnails_support() {
588
+        if ( ! current_theme_supports('post-thumbnails')) { add_theme_support('post-thumbnails'); }
589 589
     } // End ensure_post_thumbnails_support()
590 590
 
591 591
 
@@ -597,10 +597,10 @@  discard block
 block discarded – undo
597 597
      * @return void
598 598
      * @deprecated
599 599
      */
600
-    public function template_loader ( $template = '' ) {
600
+    public function template_loader($template = '') {
601 601
 
602
-        _deprecated_function( 'Sensei()->template_loader', '1.9.0', 'Use Sensei_Templates::template_loader( $template ) instead' );
603
-        Sensei_Templates::template_loader( $template );
602
+        _deprecated_function('Sensei()->template_loader', '1.9.0', 'Use Sensei_Templates::template_loader( $template ) instead');
603
+        Sensei_Templates::template_loader($template);
604 604
 
605 605
     } // End template_loader()
606 606
 
@@ -610,15 +610,15 @@  discard block
 block discarded – undo
610 610
      * @since  1.0.0
611 611
      * @return string $sensei_plugin_path
612 612
      */
613
-    public function plugin_path () {
613
+    public function plugin_path() {
614 614
 
615
-        if ( $this->plugin_path ) {
615
+        if ($this->plugin_path) {
616 616
 
617
-            $sensei_plugin_path =  $this->plugin_path;
617
+            $sensei_plugin_path = $this->plugin_path;
618 618
 
619
-        }else{
619
+        } else {
620 620
 
621
-            $sensei_plugin_path = plugin_dir_path( __FILE__ );
621
+            $sensei_plugin_path = plugin_dir_path(__FILE__);
622 622
 
623 623
         }
624 624
 
@@ -634,9 +634,9 @@  discard block
 block discarded – undo
634 634
      * @param  string $page
635 635
      * @return int
636 636
      */
637
-    public function get_page_id ( $page ) {
638
-        $page = apply_filters( 'sensei_get_' . esc_attr( $page ) . '_page_id', get_option( 'sensei_' . esc_attr( $page ) . '_page_id' ) );
639
-        return ( $page ) ? $page : -1;
637
+    public function get_page_id($page) {
638
+        $page = apply_filters('sensei_get_'.esc_attr($page).'_page_id', get_option('sensei_'.esc_attr($page).'_page_id'));
639
+        return ($page) ? $page : -1;
640 640
     } // End get_page_id()
641 641
 
642 642
 
@@ -648,18 +648,18 @@  discard block
 block discarded – undo
648 648
      * @param  array/Object $order_user (default: array()) Specific user's data.
649 649
      * @return bool|int
650 650
      */
651
-    public function woocommerce_course_update ( $course_id = 0, $order_user = array()  ) {
651
+    public function woocommerce_course_update($course_id = 0, $order_user = array()) {
652 652
         global $current_user;
653 653
 
654
-        if ( ! isset( $current_user ) || !$current_user->ID > 0 ) return false;
654
+        if ( ! isset($current_user) || ! $current_user->ID > 0) return false;
655 655
 
656 656
         $data_update = false;
657 657
 
658 658
         // Get the product ID
659
-        $wc_post_id = get_post_meta( intval( $course_id ), '_course_woocommerce_product', true );
659
+        $wc_post_id = get_post_meta(intval($course_id), '_course_woocommerce_product', true);
660 660
 
661 661
         // Check if in the admin
662
-        if ( is_admin() ) {
662
+        if (is_admin()) {
663 663
             $user_login = $order_user['user_login'];
664 664
             $user_email = $order_user['user_email'];
665 665
             $user_url = $order_user['user_url'];
@@ -672,25 +672,25 @@  discard block
 block discarded – undo
672 672
         } // End If Statement
673 673
 
674 674
         // This doesn't appear to be purely WooCommerce related. Should it be in a separate function?
675
-        $course_prerequisite_id = (int) get_post_meta( $course_id, '_course_prerequisite', true );
676
-        if( 0 < absint( $course_prerequisite_id ) ) {
677
-            $prereq_course_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, intval( $user_id ) );
678
-            if ( ! $prereq_course_complete ) {
675
+        $course_prerequisite_id = (int) get_post_meta($course_id, '_course_prerequisite', true);
676
+        if (0 < absint($course_prerequisite_id)) {
677
+            $prereq_course_complete = Sensei_Utils::user_completed_course($course_prerequisite_id, intval($user_id));
678
+            if ( ! $prereq_course_complete) {
679 679
                 // Remove all course user meta
680
-                return Sensei_Utils::sensei_remove_user_from_course( $course_id, $user_id );
680
+                return Sensei_Utils::sensei_remove_user_from_course($course_id, $user_id);
681 681
             }
682 682
         }
683 683
 
684
-        $is_user_taking_course = Sensei_Utils::user_started_course( intval( $course_id ), intval( $user_id ) );
684
+        $is_user_taking_course = Sensei_Utils::user_started_course(intval($course_id), intval($user_id));
685 685
 
686
-        if( ! $is_user_taking_course ) {
686
+        if ( ! $is_user_taking_course) {
687 687
 
688
-            if ( Sensei_WC::is_woocommerce_active() && Sensei_Utils::sensei_customer_bought_product( $user_email, $user_id, $wc_post_id ) && ( 0 < $wc_post_id ) ) {
688
+            if (Sensei_WC::is_woocommerce_active() && Sensei_Utils::sensei_customer_bought_product($user_email, $user_id, $wc_post_id) && (0 < $wc_post_id)) {
689 689
 
690
-                $activity_logged = Sensei_Utils::user_start_course( intval( $user_id), intval( $course_id ) );
690
+                $activity_logged = Sensei_Utils::user_start_course(intval($user_id), intval($course_id));
691 691
 
692 692
                 $is_user_taking_course = false;
693
-                if ( true == $activity_logged ) {
693
+                if (true == $activity_logged) {
694 694
                     $is_user_taking_course = true;
695 695
                 } // End If Statement
696 696
             } // End If Statement
@@ -708,16 +708,16 @@  discard block
 block discarded – undo
708 708
      *
709 709
      * @return bool
710 710
      */
711
-    public function check_user_permissions ( $page = '' ) {
711
+    public function check_user_permissions($page = '') {
712 712
         // REFACTOR
713 713
         global $current_user, $post;
714 714
 
715 715
         // if use is not logged in
716 716
         // skipped for single lesson
717
-        if ( empty( $current_user->caps ) && Sensei()->settings->get('access_permission')
718
-            && 'lesson-single' !=  $page ){
719
-            $this->permissions_message['title'] = __('Restricted Access', 'woothemes-sensei' );
720
-            $this->permissions_message['message'] = sprintf( __('You must be logged in to view this %s'), get_post_type() );
717
+        if (empty($current_user->caps) && Sensei()->settings->get('access_permission')
718
+            && 'lesson-single' != $page) {
719
+            $this->permissions_message['title'] = __('Restricted Access', 'woothemes-sensei');
720
+            $this->permissions_message['message'] = sprintf(__('You must be logged in to view this %s'), get_post_type());
721 721
             return false;
722 722
         }
723 723
 
@@ -727,106 +727,106 @@  discard block
 block discarded – undo
727 727
 
728 728
         $user_allowed = false;
729 729
 
730
-        switch ( $page ) {
730
+        switch ($page) {
731 731
             case 'course-single':
732 732
                 // check for prerequisite course or lesson,
733
-                $course_prerequisite_id = (int) get_post_meta( $post->ID, '_course_prerequisite', true);
734
-                $update_course = $this->woocommerce_course_update( $post->ID );
733
+                $course_prerequisite_id = (int) get_post_meta($post->ID, '_course_prerequisite', true);
734
+                $update_course = $this->woocommerce_course_update($post->ID);
735 735
                 // Count completed lessons
736
-                if ( 0 < absint( $course_prerequisite_id ) ) {
736
+                if (0 < absint($course_prerequisite_id)) {
737 737
 
738
-                    $prerequisite_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, $current_user->ID );
738
+                    $prerequisite_complete = Sensei_Utils::user_completed_course($course_prerequisite_id, $current_user->ID);
739 739
 
740 740
                 }
741 741
                 else {
742 742
                     $prerequisite_complete = true;
743 743
                 } // End If Statement
744 744
                 // Handles restrictions
745
-                if ( !$prerequisite_complete && 0 < absint( $course_prerequisite_id ) ) {
746
-                    $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' );
747
-                    $course_link = '<a href="' . esc_url( get_permalink( $course_prerequisite_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>';
748
-                    $this->permissions_message['message'] = sprintf( __('Please complete the previous %1$s before taking this course.', 'woothemes-sensei' ), $course_link );
745
+                if ( ! $prerequisite_complete && 0 < absint($course_prerequisite_id)) {
746
+                    $this->permissions_message['title'] = get_the_title($post->ID).': '.__('Restricted Access', 'woothemes-sensei');
747
+                    $course_link = '<a href="'.esc_url(get_permalink($course_prerequisite_id)).'">'.__('course', 'woothemes-sensei').'</a>';
748
+                    $this->permissions_message['message'] = sprintf(__('Please complete the previous %1$s before taking this course.', 'woothemes-sensei'), $course_link);
749 749
                 } else {
750 750
                     $user_allowed = true;
751 751
                 } // End If Statement
752 752
                 break;
753 753
             case 'lesson-single':
754 754
                 // Check for WC purchase
755
-                $lesson_course_id = get_post_meta( $post->ID, '_lesson_course',true );
755
+                $lesson_course_id = get_post_meta($post->ID, '_lesson_course', true);
756 756
 
757
-                $update_course = $this->woocommerce_course_update( $lesson_course_id );
758
-                $is_preview = Sensei_Utils::is_preview_lesson( $post->ID );
757
+                $update_course = $this->woocommerce_course_update($lesson_course_id);
758
+                $is_preview = Sensei_Utils::is_preview_lesson($post->ID);
759 759
 
760
-                if ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) {
760
+                if ($this->access_settings() && Sensei_Utils::user_started_course($lesson_course_id, $current_user->ID)) {
761 761
                     $user_allowed = true;
762
-                } elseif( $this->access_settings() && false == $is_preview ) {
762
+                } elseif ($this->access_settings() && false == $is_preview) {
763 763
 
764 764
                     $user_allowed = true;
765 765
 
766 766
                 } else {
767
-                    $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' );
768
-                    $course_link = '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>';
769
-                    $wc_post_id = get_post_meta( $lesson_course_id, '_course_woocommerce_product',true );
770
-                    if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) {
771
-                        if ( $is_preview ) {
772
-                            $this->permissions_message['message'] = sprintf( __('This is a preview lesson. Please purchase the %1$s to access all lessons.', 'woothemes-sensei' ), $course_link );
767
+                    $this->permissions_message['title'] = get_the_title($post->ID).': '.__('Restricted Access', 'woothemes-sensei');
768
+                    $course_link = '<a href="'.esc_url(get_permalink($lesson_course_id)).'">'.__('course', 'woothemes-sensei').'</a>';
769
+                    $wc_post_id = get_post_meta($lesson_course_id, '_course_woocommerce_product', true);
770
+                    if (Sensei_WC::is_woocommerce_active() && (0 < $wc_post_id)) {
771
+                        if ($is_preview) {
772
+                            $this->permissions_message['message'] = sprintf(__('This is a preview lesson. Please purchase the %1$s to access all lessons.', 'woothemes-sensei'), $course_link);
773 773
                         } else {
774
-                            $this->permissions_message['message'] =  sprintf( __('Please purchase the %1$s before starting this Lesson.', 'woothemes-sensei' ), $course_link );
774
+                            $this->permissions_message['message'] = sprintf(__('Please purchase the %1$s before starting this Lesson.', 'woothemes-sensei'), $course_link);
775 775
                         }
776 776
                     } else {
777
-                        if ( $is_preview ) {
778
-                            $this->permissions_message['message'] = sprintf( __('This is a preview lesson. Please sign up for the %1$s to access all lessons.', 'woothemes-sensei' ), $course_link );
777
+                        if ($is_preview) {
778
+                            $this->permissions_message['message'] = sprintf(__('This is a preview lesson. Please sign up for the %1$s to access all lessons.', 'woothemes-sensei'), $course_link);
779 779
                         } else {
780 780
                             /** This filter is documented in class-woothemes-sensei-frontend.php */
781
-                            $this->permissions_message['message'] =  sprintf( __( 'Please sign up for the %1$s before starting the lesson.', 'woothemes-sensei' ), $course_link );
781
+                            $this->permissions_message['message'] = sprintf(__('Please sign up for the %1$s before starting the lesson.', 'woothemes-sensei'), $course_link);
782 782
                         }
783 783
                     } // End If Statement
784 784
                 } // End If Statement
785 785
                 break;
786 786
             case 'quiz-single':
787
-                $lesson_id = get_post_meta( $post->ID, '_quiz_lesson',true );
788
-                $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course',true );
787
+                $lesson_id = get_post_meta($post->ID, '_quiz_lesson', true);
788
+                $lesson_course_id = get_post_meta($lesson_id, '_lesson_course', true);
789 789
 
790
-                $update_course = $this->woocommerce_course_update( $lesson_course_id );
791
-                if ( ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) || sensei_all_access() ) {
790
+                $update_course = $this->woocommerce_course_update($lesson_course_id);
791
+                if (($this->access_settings() && Sensei_Utils::user_started_course($lesson_course_id, $current_user->ID)) || sensei_all_access()) {
792 792
 
793 793
                     // Check for prerequisite lesson for this quiz
794
-                    $lesson_prerequisite_id = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true);
795
-                    $user_lesson_prerequisite_complete = Sensei_Utils::user_completed_lesson( $lesson_prerequisite_id, $current_user->ID);
794
+                    $lesson_prerequisite_id = (int) get_post_meta($lesson_id, '_lesson_prerequisite', true);
795
+                    $user_lesson_prerequisite_complete = Sensei_Utils::user_completed_lesson($lesson_prerequisite_id, $current_user->ID);
796 796
 
797 797
                     // Handle restrictions
798
-                    if( sensei_all_access() ) {
798
+                    if (sensei_all_access()) {
799 799
                         $user_allowed = true;
800 800
                     } else {
801
-                        if ( 0 < absint( $lesson_prerequisite_id ) && ( !$user_lesson_prerequisite_complete ) ) {
802
-                            $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' );
803
-                            $lesson_link = '<a href="' . esc_url( get_permalink( $lesson_prerequisite_id ) ) . '">' . __( 'lesson', 'woothemes-sensei' ) . '</a>';
804
-                            $this->permissions_message['message'] = sprintf( __('Please complete the previous %1$s before taking this Quiz.', 'woothemes-sensei' ), $lesson_link );
801
+                        if (0 < absint($lesson_prerequisite_id) && ( ! $user_lesson_prerequisite_complete)) {
802
+                            $this->permissions_message['title'] = get_the_title($post->ID).': '.__('Restricted Access', 'woothemes-sensei');
803
+                            $lesson_link = '<a href="'.esc_url(get_permalink($lesson_prerequisite_id)).'">'.__('lesson', 'woothemes-sensei').'</a>';
804
+                            $this->permissions_message['message'] = sprintf(__('Please complete the previous %1$s before taking this Quiz.', 'woothemes-sensei'), $lesson_link);
805 805
                         } else {
806 806
                             $user_allowed = true;
807 807
                         } // End If Statement
808 808
                     } // End If Statement
809
-                } elseif( $this->access_settings() ) {
809
+                } elseif ($this->access_settings()) {
810 810
                     // Check if the user has started the course
811 811
 
812
-                    if ( is_user_logged_in() && ! Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) && ( isset( $this->settings->settings['access_permission'] ) && ( true == $this->settings->settings['access_permission'] ) ) ) {
812
+                    if (is_user_logged_in() && ! Sensei_Utils::user_started_course($lesson_course_id, $current_user->ID) && (isset($this->settings->settings['access_permission']) && (true == $this->settings->settings['access_permission']))) {
813 813
 
814 814
                         $user_allowed = false;
815
-                        $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' );
816
-                        $course_link = '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>';
817
-                        $wc_post_id = get_post_meta( $lesson_course_id, '_course_woocommerce_product',true );
818
-                        if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) {
819
-                            $this->permissions_message['message'] = sprintf( __('Please purchase the %1$s before starting this Quiz.', 'woothemes-sensei' ), $course_link );
815
+                        $this->permissions_message['title'] = get_the_title($post->ID).': '.__('Restricted Access', 'woothemes-sensei');
816
+                        $course_link = '<a href="'.esc_url(get_permalink($lesson_course_id)).'">'.__('course', 'woothemes-sensei').'</a>';
817
+                        $wc_post_id = get_post_meta($lesson_course_id, '_course_woocommerce_product', true);
818
+                        if (Sensei_WC::is_woocommerce_active() && (0 < $wc_post_id)) {
819
+                            $this->permissions_message['message'] = sprintf(__('Please purchase the %1$s before starting this Quiz.', 'woothemes-sensei'), $course_link);
820 820
                         } else {
821
-                            $this->permissions_message['message'] = sprintf( __('Please sign up for the %1$s before starting this Quiz.', 'woothemes-sensei' ), $course_link );
821
+                            $this->permissions_message['message'] = sprintf(__('Please sign up for the %1$s before starting this Quiz.', 'woothemes-sensei'), $course_link);
822 822
                         } // End If Statement
823 823
                     } else {
824 824
                         $user_allowed = true;
825 825
                     } // End If Statement
826 826
                 } else {
827
-                    $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' );
828
-                    $course_link = '<a href="' . esc_url( get_permalink( get_post_meta( get_post_meta( $post->ID, '_quiz_lesson', true ), '_lesson_course', true ) ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>';
829
-                    $this->permissions_message['message'] = sprintf( __('Please sign up for the %1$s before taking this Quiz.', 'woothemes-sensei' ), $course_link );
827
+                    $this->permissions_message['title'] = get_the_title($post->ID).': '.__('Restricted Access', 'woothemes-sensei');
828
+                    $course_link = '<a href="'.esc_url(get_permalink(get_post_meta(get_post_meta($post->ID, '_quiz_lesson', true), '_lesson_course', true))).'">'.__('course', 'woothemes-sensei').'</a>';
829
+                    $this->permissions_message['message'] = sprintf(__('Please sign up for the %1$s before taking this Quiz.', 'woothemes-sensei'), $course_link);
830 830
                 } // End If Statement
831 831
                 break;
832 832
             default:
@@ -848,14 +848,14 @@  discard block
 block discarded – undo
848 848
          * }
849 849
          * @param string $post_id
850 850
          */
851
-        $this->permissions_message = apply_filters( 'sensei_permissions_message', $this->permissions_message, $post->ID );
851
+        $this->permissions_message = apply_filters('sensei_permissions_message', $this->permissions_message, $post->ID);
852 852
 
853 853
 
854
-        if( sensei_all_access() || Sensei_Utils::is_preview_lesson( $post->ID ) ) {
854
+        if (sensei_all_access() || Sensei_Utils::is_preview_lesson($post->ID)) {
855 855
             $user_allowed = true;
856 856
         }
857 857
 
858
-        return apply_filters( 'sensei_access_permissions', $user_allowed );
858
+        return apply_filters('sensei_access_permissions', $user_allowed);
859 859
     } // End get_placeholder_image()
860 860
 
861 861
 
@@ -865,12 +865,12 @@  discard block
 block discarded – undo
865 865
      * @access public
866 866
      * @return bool
867 867
      */
868
-    public function access_settings () {
868
+    public function access_settings() {
869 869
 
870
-        if( sensei_all_access() ) return true;
870
+        if (sensei_all_access()) return true;
871 871
 
872
-        if ( isset( $this->settings->settings['access_permission'] ) && ( true == $this->settings->settings['access_permission'] ) ) {
873
-            if ( is_user_logged_in() ) {
872
+        if (isset($this->settings->settings['access_permission']) && (true == $this->settings->settings['access_permission'])) {
873
+            if (is_user_logged_in()) {
874 874
                 return true;
875 875
             } else {
876 876
                 return false;
@@ -887,38 +887,38 @@  discard block
 block discarded – undo
887 887
      * @param   int $order_id WC order ID
888 888
      * @return  void
889 889
      */
890
-    public function sensei_woocommerce_complete_order ( $order_id = 0 ) {
890
+    public function sensei_woocommerce_complete_order($order_id = 0) {
891 891
         $order_user = array();
892 892
         // Check for WooCommerce
893
-        if ( Sensei_WC::is_woocommerce_active() && ( 0 < $order_id ) ) {
893
+        if (Sensei_WC::is_woocommerce_active() && (0 < $order_id)) {
894 894
             // Get order object
895
-            $order = new WC_Order( $order_id );
896
-            $user = get_user_by( 'id', $order->get_user_id() );
895
+            $order = new WC_Order($order_id);
896
+            $user = get_user_by('id', $order->get_user_id());
897 897
             $order_user['ID'] = $user->ID;
898 898
             $order_user['user_login'] = $user->user_login;
899 899
             $order_user['user_email'] = $user->user_email;
900 900
             $order_user['user_url'] = $user->user_url;
901 901
             // Run through each product ordered
902
-            if ( 0 < sizeof( $order->get_items() ) ) {
903
-                foreach( $order->get_items() as $item ) {
902
+            if (0 < sizeof($order->get_items())) {
903
+                foreach ($order->get_items() as $item) {
904 904
                     $product_type = '';
905
-                    if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
905
+                    if (isset($item['variation_id']) && (0 < $item['variation_id'])) {
906 906
                         $item_id = $item['variation_id'];
907 907
                         $product_type = 'variation';
908 908
                     } else {
909 909
                         $item_id = $item['product_id'];
910 910
                     } // End If Statement
911
-                    $_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type );
911
+                    $_product = $this->sensei_get_woocommerce_product_object($item_id, $product_type);
912 912
                     // Get courses that use the WC product
913
-                    $courses = $this->post_types->course->get_product_courses( $_product->id );
913
+                    $courses = $this->post_types->course->get_product_courses($_product->id);
914 914
                     // Loop and update those courses
915
-                    foreach ( $courses as $course_item ) {
916
-                        $update_course = $this->woocommerce_course_update( $course_item->ID, $order_user );
915
+                    foreach ($courses as $course_item) {
916
+                        $update_course = $this->woocommerce_course_update($course_item->ID, $order_user);
917 917
                     } // End For Loop
918 918
                 } // End For Loop
919 919
             } // End If Statement
920 920
             // Add meta to indicate that payment has been completed successfully
921
-            update_post_meta( $order_id, 'sensei_payment_complete', '1' );
921
+            update_post_meta($order_id, 'sensei_payment_complete', '1');
922 922
         } // End If Statement
923 923
     } // End sensei_woocommerce_complete_order()
924 924
 
@@ -929,36 +929,36 @@  discard block
 block discarded – undo
929 929
      * @param   integer $order_id order ID
930 930
      * @return  void
931 931
      */
932
-    public function sensei_woocommerce_cancel_order ( $order_id ) {
932
+    public function sensei_woocommerce_cancel_order($order_id) {
933 933
 
934 934
         // Get order object
935
-        $order = new WC_Order( $order_id );
935
+        $order = new WC_Order($order_id);
936 936
 
937 937
         // Run through each product ordered
938
-        if ( 0 < sizeof( $order->get_items() ) ) {
938
+        if (0 < sizeof($order->get_items())) {
939 939
 
940 940
             // Get order user
941
-            $user_id = $order->__get( 'user_id' );
941
+            $user_id = $order->__get('user_id');
942 942
 
943
-            foreach( $order->get_items() as $item ) {
943
+            foreach ($order->get_items() as $item) {
944 944
 
945 945
                 $product_type = '';
946
-                if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
946
+                if (isset($item['variation_id']) && (0 < $item['variation_id'])) {
947 947
                     $item_id = $item['variation_id'];
948 948
                     $product_type = 'variation';
949 949
                 } else {
950 950
                     $item_id = $item['product_id'];
951 951
                 } // End If Statement
952
-                $_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type );
952
+                $_product = $this->sensei_get_woocommerce_product_object($item_id, $product_type);
953 953
 
954 954
                 // Get courses that use the WC product
955 955
                 $courses = array();
956
-                $courses = $this->post_types->course->get_product_courses( $item_id );
956
+                $courses = $this->post_types->course->get_product_courses($item_id);
957 957
 
958 958
                 // Loop and update those courses
959
-                foreach ($courses as $course_item){
959
+                foreach ($courses as $course_item) {
960 960
                     // Check and Remove course from courses user meta
961
-                    $dataset_changes = Sensei_Utils::sensei_remove_user_from_course( $course_item->ID, $user_id );
961
+                    $dataset_changes = Sensei_Utils::sensei_remove_user_from_course($course_item->ID, $user_id);
962 962
                 } // End For Loop
963 963
             } // End For Loop
964 964
         } // End If Statement
@@ -972,9 +972,9 @@  discard block
 block discarded – undo
972 972
      * @param   integer $subscription_key Subscription Unique Key
973 973
      * @return  void
974 974
      */
975
-    public function sensei_woocommerce_subscription_ended( $user_id, $subscription_key ) {
976
-        $subscription = WC_Subscriptions_Manager::get_users_subscription( $user_id, $subscription_key );
977
-        self::sensei_woocommerce_cancel_order( $subscription['order_id'] );
975
+    public function sensei_woocommerce_subscription_ended($user_id, $subscription_key) {
976
+        $subscription = WC_Subscriptions_Manager::get_users_subscription($user_id, $subscription_key);
977
+        self::sensei_woocommerce_cancel_order($subscription['order_id']);
978 978
     }
979 979
 
980 980
     /**
@@ -985,18 +985,18 @@  discard block
 block discarded – undo
985 985
      * @param   integer $subscription_key Subscription Unique Key
986 986
      * @return  void
987 987
      */
988
-    public function sensei_woocommerce_reactivate_subscription( $user_id, $subscription_key ) {
989
-        $subscription = WC_Subscriptions_Manager::get_users_subscription( $user_id, $subscription_key );
990
-        $order = new WC_Order( $subscription['order_id'] );
991
-        $user = get_user_by( 'id', $order->get_user_id() );
988
+    public function sensei_woocommerce_reactivate_subscription($user_id, $subscription_key) {
989
+        $subscription = WC_Subscriptions_Manager::get_users_subscription($user_id, $subscription_key);
990
+        $order = new WC_Order($subscription['order_id']);
991
+        $user = get_user_by('id', $order->get_user_id());
992 992
         $order_user = array();
993 993
         $order_user['ID'] = $user->ID;
994 994
         $order_user['user_login'] = $user->user_login;
995 995
         $order_user['user_email'] = $user->user_email;
996 996
         $order_user['user_url'] = $user->user_url;
997
-        $courses = $this->post_types->course->get_product_courses( $subscription['product_id'] );
998
-        foreach ( $courses as $course_item ){
999
-            $update_course = $this->woocommerce_course_update( $course_item->ID, $order_user );
997
+        $courses = $this->post_types->course->get_product_courses($subscription['product_id']);
998
+        foreach ($courses as $course_item) {
999
+            $update_course = $this->woocommerce_course_update($course_item->ID, $order_user);
1000 1000
         } // End For Loop
1001 1001
     } // End sensei_woocommerce_reactivate_subscription
1002 1002
 
@@ -1011,30 +1011,30 @@  discard block
 block discarded – undo
1011 1011
      * @param   string  $product_type  '' or 'variation'
1012 1012
      * @return   WC_Product $wc_product_object
1013 1013
      */
1014
-    public function sensei_get_woocommerce_product_object ( $wc_product_id = 0, $product_type = '' ) {
1014
+    public function sensei_get_woocommerce_product_object($wc_product_id = 0, $product_type = '') {
1015 1015
 
1016 1016
         $wc_product_object = false;
1017
-        if ( 0 < intval( $wc_product_id ) ) {
1017
+        if (0 < intval($wc_product_id)) {
1018 1018
 
1019 1019
             // Get the product
1020
-            if ( function_exists( 'wc_get_product' ) ) {
1020
+            if (function_exists('wc_get_product')) {
1021 1021
 
1022
-                $wc_product_object = wc_get_product( $wc_product_id ); // Post WC 2.3
1022
+                $wc_product_object = wc_get_product($wc_product_id); // Post WC 2.3
1023 1023
 
1024
-            } elseif ( function_exists( 'get_product' ) ) {
1024
+            } elseif (function_exists('get_product')) {
1025 1025
 
1026
-                $wc_product_object = get_product( $wc_product_id ); // Post WC 2.0
1026
+                $wc_product_object = get_product($wc_product_id); // Post WC 2.0
1027 1027
 
1028 1028
             } else {
1029 1029
 
1030 1030
                 // Pre WC 2.0
1031
-                if ( 'variation' == $product_type || 'subscription_variation' == $product_type ) {
1031
+                if ('variation' == $product_type || 'subscription_variation' == $product_type) {
1032 1032
 
1033
-                    $wc_product_object = new WC_Product_Variation( $wc_product_id );
1033
+                    $wc_product_object = new WC_Product_Variation($wc_product_id);
1034 1034
 
1035 1035
                 } else {
1036 1036
 
1037
-                    $wc_product_object = new WC_Product( $wc_product_id );
1037
+                    $wc_product_object = new WC_Product($wc_product_id);
1038 1038
 
1039 1039
                 } // End If Statement
1040 1040
 
@@ -1052,9 +1052,9 @@  discard block
 block discarded – undo
1052 1052
      * @access  public
1053 1053
      * @return  void
1054 1054
      */
1055
-    public function load_class ( $class_name = '' ) {
1056
-        if ( '' != $class_name && '' != $this->token ) {
1057
-            require_once( 'class-' . esc_attr( $this->token ) . '-' . esc_attr( $class_name ) . '.php' );
1055
+    public function load_class($class_name = '') {
1056
+        if ('' != $class_name && '' != $this->token) {
1057
+            require_once('class-'.esc_attr($this->token).'-'.esc_attr($class_name).'.php');
1058 1058
         } // End If Statement
1059 1059
     } // End load_class()
1060 1060
 
@@ -1065,17 +1065,17 @@  discard block
 block discarded – undo
1065 1065
      * @param   integer $order_id order ID
1066 1066
      * @return  void
1067 1067
      */
1068
-    public function sensei_activate_subscription(  $order_id = 0 ) {
1069
-        if ( 0 < intval( $order_id ) ) {
1070
-            $order = new WC_Order( $order_id );
1068
+    public function sensei_activate_subscription($order_id = 0) {
1069
+        if (0 < intval($order_id)) {
1070
+            $order = new WC_Order($order_id);
1071 1071
             $user = get_user_by('id', $order->user_id);
1072 1072
             $order_user['ID'] = $user->ID;
1073 1073
             $order_user['user_login'] = $user->user_login;
1074 1074
             $order_user['user_email'] = $user->user_email;
1075 1075
             $order_user['user_url'] = $user->user_url;
1076 1076
             // Run through each product ordered
1077
-            if (sizeof($order->get_items())>0) {
1078
-                foreach($order->get_items() as $item) {
1077
+            if (sizeof($order->get_items()) > 0) {
1078
+                foreach ($order->get_items() as $item) {
1079 1079
                     $product_type = '';
1080 1080
                     if (isset($item['variation_id']) && $item['variation_id'] > 0) {
1081 1081
                         $item_id = $item['variation_id'];
@@ -1083,15 +1083,15 @@  discard block
 block discarded – undo
1083 1083
                     } else {
1084 1084
                         $item_id = $item['product_id'];
1085 1085
                     } // End If Statement
1086
-                    $_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type );
1086
+                    $_product = $this->sensei_get_woocommerce_product_object($item_id, $product_type);
1087 1087
                     // Get courses that use the WC product
1088 1088
                     $courses = array();
1089
-                    if ( $product_type == 'subscription_variation' ) {
1090
-                        $courses = $this->post_types->course->get_product_courses( $item_id );
1089
+                    if ($product_type == 'subscription_variation') {
1090
+                        $courses = $this->post_types->course->get_product_courses($item_id);
1091 1091
                     } // End If Statement
1092 1092
                     // Loop and update those courses
1093
-                    foreach ($courses as $course_item){
1094
-                        $update_course = $this->woocommerce_course_update( $course_item->ID, $order_user );
1093
+                    foreach ($courses as $course_item) {
1094
+                        $update_course = $this->woocommerce_course_update($course_item->ID, $order_user);
1095 1095
                     } // End For Loop
1096 1096
                 } // End For Loop
1097 1097
             } // End If Statement
@@ -1105,12 +1105,12 @@  discard block
 block discarded – undo
1105 1105
      * @param   WC_Order $order
1106 1106
      * @return  void
1107 1107
      */
1108
-    public function sensei_woocommerce_email_course_details( $order ) {
1108
+    public function sensei_woocommerce_email_course_details($order) {
1109 1109
         global $woocommerce;
1110 1110
 
1111 1111
         // exit early if not wc-completed or wc-processing
1112
-        if( 'wc-completed' != $order->post_status
1113
-            && 'wc-processing' != $order->post_status  ) {
1112
+        if ('wc-completed' != $order->post_status
1113
+            && 'wc-processing' != $order->post_status) {
1114 1114
             return;
1115 1115
         }
1116 1116
 
@@ -1118,16 +1118,16 @@  discard block
 block discarded – undo
1118 1118
         $order_id = $order->id;
1119 1119
 
1120 1120
         //If object have items go through them all to find course
1121
-        if ( 0 < sizeof( $order_items ) ) {
1121
+        if (0 < sizeof($order_items)) {
1122 1122
 
1123
-            $course_details_html =  '<h2>' . __( 'Course details', 'woothemes-sensei' ) . '</h2>';
1123
+            $course_details_html = '<h2>'.__('Course details', 'woothemes-sensei').'</h2>';
1124 1124
             $order_contains_courses = false;
1125 1125
 
1126 1126
 
1127
-            foreach ( $order_items as $item ) {
1127
+            foreach ($order_items as $item) {
1128 1128
 
1129 1129
                 $product_type = '';
1130
-                if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
1130
+                if (isset($item['variation_id']) && (0 < $item['variation_id'])) {
1131 1131
                     // If item has variation_id then its from variation
1132 1132
                     $item_id = $item['variation_id'];
1133 1133
                     $product_type = 'variation';
@@ -1136,9 +1136,9 @@  discard block
 block discarded – undo
1136 1136
                     $item_id = $item['product_id'];
1137 1137
                 } // End If Statement
1138 1138
 
1139
-                $user_id = get_post_meta( $order_id, '_customer_user', true );
1139
+                $user_id = get_post_meta($order_id, '_customer_user', true);
1140 1140
 
1141
-                if( $user_id ) {
1141
+                if ($user_id) {
1142 1142
 
1143 1143
                     // Get all courses for product
1144 1144
                     $args = array(
@@ -1153,16 +1153,16 @@  discard block
 block discarded – undo
1153 1153
                         'orderby' => 'menu_order date',
1154 1154
                         'order' => 'ASC',
1155 1155
                     );
1156
-                    $courses = get_posts( $args );
1156
+                    $courses = get_posts($args);
1157 1157
 
1158
-                    if( $courses && count( $courses ) > 0 ) {
1158
+                    if ($courses && count($courses) > 0) {
1159 1159
 
1160
-                        foreach( $courses as $course ) {
1160
+                        foreach ($courses as $course) {
1161 1161
 
1162 1162
                             $title = $course->post_title;
1163
-                            $permalink = get_permalink( $course->ID );
1163
+                            $permalink = get_permalink($course->ID);
1164 1164
                             $order_contains_courses = true;
1165
-                            $course_details_html .=  '<p><strong>' . sprintf( __( 'View course: %1$s', 'woothemes-sensei' ), '</strong><a href="' . esc_url( $permalink ) . '">' . $title . '</a>' ) . '</p>';
1165
+                            $course_details_html .= '<p><strong>'.sprintf(__('View course: %1$s', 'woothemes-sensei'), '</strong><a href="'.esc_url($permalink).'">'.$title.'</a>').'</p>';
1166 1166
                         }
1167 1167
 
1168 1168
 
@@ -1173,7 +1173,7 @@  discard block
 block discarded – undo
1173 1173
             } // end for each order item
1174 1174
 
1175 1175
             // Output Course details
1176
-            if( $order_contains_courses ){
1176
+            if ($order_contains_courses) {
1177 1177
 
1178 1178
                 echo $course_details_html;
1179 1179
 
@@ -1192,44 +1192,44 @@  discard block
 block discarded – undo
1192 1192
      * @param  integer $post_id
1193 1193
      * @return array
1194 1194
      */
1195
-    public function sensei_count_comments( $comments, $post_id ) {
1195
+    public function sensei_count_comments($comments, $post_id) {
1196 1196
         global $wpdb;
1197 1197
 
1198 1198
         $post_id = (int) $post_id;
1199 1199
 
1200 1200
         $count = wp_cache_get("comments-{$post_id}", 'counts');
1201 1201
 
1202
-        if ( false !== $count ) {
1202
+        if (false !== $count) {
1203 1203
             return $count;
1204 1204
         }
1205 1205
 
1206
-        $statuses = array( '' ); // Default to the WP normal comments
1207
-        $stati = $wpdb->get_results( "SELECT comment_type FROM {$wpdb->comments} GROUP BY comment_type", ARRAY_A );
1208
-        foreach ( (array) $stati AS $status ) {
1209
-            if ( 'sensei_' != substr($status['comment_type'], 0, 7 ) ) {
1206
+        $statuses = array(''); // Default to the WP normal comments
1207
+        $stati = $wpdb->get_results("SELECT comment_type FROM {$wpdb->comments} GROUP BY comment_type", ARRAY_A);
1208
+        foreach ((array) $stati AS $status) {
1209
+            if ('sensei_' != substr($status['comment_type'], 0, 7)) {
1210 1210
                 $statuses[] = $status['comment_type'];
1211 1211
             }
1212 1212
         }
1213
-        $where = "WHERE comment_type IN ('" . join("', '", array_unique( $statuses ) ) . "')";
1213
+        $where = "WHERE comment_type IN ('".join("', '", array_unique($statuses))."')";
1214 1214
 
1215
-        if ( $post_id > 0 )
1216
-            $where .= $wpdb->prepare( " AND comment_post_ID = %d", $post_id );
1215
+        if ($post_id > 0)
1216
+            $where .= $wpdb->prepare(" AND comment_post_ID = %d", $post_id);
1217 1217
 
1218
-        $count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A );
1218
+        $count = $wpdb->get_results("SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A);
1219 1219
 
1220 1220
         $total = 0;
1221 1221
         $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash', 'post-trashed' => 'post-trashed');
1222
-        foreach ( (array) $count as $row ) {
1222
+        foreach ((array) $count as $row) {
1223 1223
             // Don't count post-trashed toward totals
1224
-            if ( 'post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'] )
1224
+            if ('post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'])
1225 1225
                 $total += $row['num_comments'];
1226
-            if ( isset( $approved[$row['comment_approved']] ) )
1226
+            if (isset($approved[$row['comment_approved']]))
1227 1227
                 $stats[$approved[$row['comment_approved']]] = $row['num_comments'];
1228 1228
         }
1229 1229
 
1230 1230
         $stats['total_comments'] = $total;
1231
-        foreach ( $approved as $key ) {
1232
-            if ( empty($stats[$key]) )
1231
+        foreach ($approved as $key) {
1232
+            if (empty($stats[$key]))
1233 1233
                 $stats[$key] = 0;
1234 1234
         }
1235 1235
 
@@ -1247,15 +1247,15 @@  discard block
 block discarded – undo
1247 1247
      * @return void
1248 1248
      */
1249 1249
     public function init_image_sizes() {
1250
-        $course_archive_thumbnail 	= $this->get_image_size( 'course_archive_image' );
1251
-        $course_single_thumbnail	= $this->get_image_size( 'course_single_image' );
1252
-        $lesson_archive_thumbnail 	= $this->get_image_size( 'lesson_archive_image' );
1253
-        $lesson_single_thumbnail	= $this->get_image_size( 'lesson_single_image' );
1254
-
1255
-        add_image_size( 'course_archive_thumbnail', $course_archive_thumbnail['width'], $course_archive_thumbnail['height'], $course_archive_thumbnail['crop'] );
1256
-        add_image_size( 'course_single_thumbnail', $course_single_thumbnail['width'], $course_single_thumbnail['height'], $course_single_thumbnail['crop'] );
1257
-        add_image_size( 'lesson_archive_thumbnail', $lesson_archive_thumbnail['width'], $lesson_archive_thumbnail['height'], $lesson_archive_thumbnail['crop'] );
1258
-        add_image_size( 'lesson_single_thumbnail', $lesson_single_thumbnail['width'], $lesson_single_thumbnail['height'], $lesson_single_thumbnail['crop'] );
1250
+        $course_archive_thumbnail 	= $this->get_image_size('course_archive_image');
1251
+        $course_single_thumbnail	= $this->get_image_size('course_single_image');
1252
+        $lesson_archive_thumbnail 	= $this->get_image_size('lesson_archive_image');
1253
+        $lesson_single_thumbnail	= $this->get_image_size('lesson_single_image');
1254
+
1255
+        add_image_size('course_archive_thumbnail', $course_archive_thumbnail['width'], $course_archive_thumbnail['height'], $course_archive_thumbnail['crop']);
1256
+        add_image_size('course_single_thumbnail', $course_single_thumbnail['width'], $course_single_thumbnail['height'], $course_single_thumbnail['crop']);
1257
+        add_image_size('lesson_archive_thumbnail', $lesson_archive_thumbnail['width'], $lesson_archive_thumbnail['height'], $lesson_archive_thumbnail['crop']);
1258
+        add_image_size('lesson_single_thumbnail', $lesson_single_thumbnail['width'], $lesson_single_thumbnail['height'], $lesson_single_thumbnail['crop']);
1259 1259
     }
1260 1260
 
1261 1261
     /**
@@ -1268,37 +1268,37 @@  discard block
 block discarded – undo
1268 1268
      * @param mixed $image_size
1269 1269
      * @return string
1270 1270
      */
1271
-    public function get_image_size( $image_size ) {
1271
+    public function get_image_size($image_size) {
1272 1272
 
1273 1273
         // Only return sizes we define in settings
1274
-        if ( ! in_array( $image_size, array( 'course_archive_image', 'course_single_image', 'lesson_archive_image', 'lesson_single_image' ) ) )
1275
-            return apply_filters( 'sensei_get_image_size_' . $image_size, '' );
1274
+        if ( ! in_array($image_size, array('course_archive_image', 'course_single_image', 'lesson_archive_image', 'lesson_single_image')))
1275
+            return apply_filters('sensei_get_image_size_'.$image_size, '');
1276 1276
 
1277
-        if( ! isset( $this->settings->settings[ $image_size . '_width' ] ) ) {
1278
-            $this->settings->settings[ $image_size . '_width' ] = false;
1277
+        if ( ! isset($this->settings->settings[$image_size.'_width'])) {
1278
+            $this->settings->settings[$image_size.'_width'] = false;
1279 1279
         }
1280
-        if( ! isset( $this->settings->settings[ $image_size . '_height' ] ) ) {
1281
-            $this->settings->settings[ $image_size . '_height' ] = false;
1280
+        if ( ! isset($this->settings->settings[$image_size.'_height'])) {
1281
+            $this->settings->settings[$image_size.'_height'] = false;
1282 1282
         }
1283
-        if( ! isset( $this->settings->settings[ $image_size . '_hard_crop' ] ) ) {
1284
-            $this->settings->settings[ $image_size . '_hard_crop' ] = false;
1283
+        if ( ! isset($this->settings->settings[$image_size.'_hard_crop'])) {
1284
+            $this->settings->settings[$image_size.'_hard_crop'] = false;
1285 1285
         }
1286 1286
 
1287
-        $size = array_filter( array(
1288
-            'width' => $this->settings->settings[ $image_size . '_width' ],
1289
-            'height' => $this->settings->settings[ $image_size . '_height' ],
1290
-            'crop' => $this->settings->settings[ $image_size . '_hard_crop' ]
1291
-        ) );
1287
+        $size = array_filter(array(
1288
+            'width' => $this->settings->settings[$image_size.'_width'],
1289
+            'height' => $this->settings->settings[$image_size.'_height'],
1290
+            'crop' => $this->settings->settings[$image_size.'_hard_crop']
1291
+        ));
1292 1292
 
1293
-        $size['width'] 	= isset( $size['width'] ) ? $size['width'] : '100';
1294
-        $size['height'] = isset( $size['height'] ) ? $size['height'] : '100';
1295
-        $size['crop'] 	= isset( $size['crop'] ) ? $size['crop'] : 0;
1293
+        $size['width'] 	= isset($size['width']) ? $size['width'] : '100';
1294
+        $size['height'] = isset($size['height']) ? $size['height'] : '100';
1295
+        $size['crop'] = isset($size['crop']) ? $size['crop'] : 0;
1296 1296
 
1297
-        return apply_filters( 'sensei_get_image_size_' . $image_size, $size );
1297
+        return apply_filters('sensei_get_image_size_'.$image_size, $size);
1298 1298
     }
1299 1299
 
1300
-    public function body_class( $classes ) {
1301
-        if( is_sensei() ) {
1300
+    public function body_class($classes) {
1301
+        if (is_sensei()) {
1302 1302
             $classes[] = 'sensei';
1303 1303
         }
1304 1304
         return $classes;
@@ -1311,9 +1311,9 @@  discard block
 block discarded – undo
1311 1311
      * @since 1.7.0
1312 1312
      */
1313 1313
     public function jetpack_latex_support() {
1314
-        if ( function_exists( 'latex_markup') ) {
1315
-            add_filter( 'sensei_question_title', 'latex_markup' );
1316
-            add_filter( 'sensei_answer_text', 'latex_markup' );
1314
+        if (function_exists('latex_markup')) {
1315
+            add_filter('sensei_question_title', 'latex_markup');
1316
+            add_filter('sensei_answer_text', 'latex_markup');
1317 1317
         }
1318 1318
     }
1319 1319
 
@@ -1325,21 +1325,21 @@  discard block
 block discarded – undo
1325 1325
      *
1326 1326
      * @since 1.8.0
1327 1327
      */
1328
-    public function load_modules_class(){
1328
+    public function load_modules_class() {
1329 1329
         global $sensei_modules;
1330 1330
 
1331
-        if( !class_exists( 'Sensei_Modules' )
1332
-            &&  'Sensei_Modules' != get_class( $sensei_modules ) ) {
1331
+        if ( ! class_exists('Sensei_Modules')
1332
+            &&  'Sensei_Modules' != get_class($sensei_modules)) {
1333 1333
 
1334 1334
             //Load the modules class
1335
-            require_once( 'class-sensei-modules.php');
1336
-            Sensei()->modules = new Sensei_Core_Modules( $this->file );
1335
+            require_once('class-sensei-modules.php');
1336
+            Sensei()->modules = new Sensei_Core_Modules($this->file);
1337 1337
 
1338
-        }else{
1338
+        } else {
1339 1339
             // fallback for people still using the modules extension.
1340 1340
             global $sensei_modules;
1341 1341
             Sensei()->modules = $sensei_modules;
1342
-            add_action( 'admin_notices', array( $this, 'disable_sensei_modules_extension'), 30 );
1342
+            add_action('admin_notices', array($this, 'disable_sensei_modules_extension'), 30);
1343 1343
         }
1344 1344
     }
1345 1345
 
@@ -1348,12 +1348,12 @@  discard block
 block discarded – undo
1348 1348
      *
1349 1349
      * @since 1.8.0
1350 1350
      */
1351
-    public function disable_sensei_modules_extension(){ ?>
1351
+    public function disable_sensei_modules_extension() { ?>
1352 1352
         <div class="notice updated fade">
1353 1353
             <p>
1354 1354
                 <?php
1355 1355
                 $plugin_manage_url = admin_url().'plugins.php#sensei-modules';
1356
-                $plugin_link_element = '<a href="' . $plugin_manage_url . '" >plugins page</a> ';
1356
+                $plugin_link_element = '<a href="'.$plugin_manage_url.'" >plugins page</a> ';
1357 1357
                 ?>
1358 1358
                 <strong> Modules are now included in Sensei,</strong> so you no longer need the Sensei Modules extension.
1359 1359
                 Please deactivate and delete it from your <?php echo $plugin_link_element; ?>. (This will not affect your existing modules).
@@ -1371,18 +1371,18 @@  discard block
 block discarded – undo
1371 1371
      *
1372 1372
      * @since 1.9.0
1373 1373
      */
1374
-    public function flush_rewrite_rules(){
1374
+    public function flush_rewrite_rules() {
1375 1375
 
1376 1376
         // ensures that the rewrite rules are flushed on the second
1377 1377
         // attempt. This ensure that the settings for any other process
1378 1378
         // have been completed and saved to the database before we refresh the
1379 1379
         // rewrite rules.
1380
-        $option =  get_option('sensei_flush_rewrite_rules');
1381
-        if( '1' == $option ) {
1380
+        $option = get_option('sensei_flush_rewrite_rules');
1381
+        if ('1' == $option) {
1382 1382
 
1383 1383
             update_option('sensei_flush_rewrite_rules', '2');
1384 1384
 
1385
-        }elseif( '2' == $option ) {
1385
+        }elseif ('2' == $option) {
1386 1386
 
1387 1387
             flush_rewrite_rules();
1388 1388
             update_option('sensei_flush_rewrite_rules', '0');
@@ -1397,7 +1397,7 @@  discard block
 block discarded – undo
1397 1397
      *
1398 1398
      * @since 1.9.0
1399 1399
      */
1400
-    public function initiate_rewrite_rules_flush(){
1400
+    public function initiate_rewrite_rules_flush() {
1401 1401
 
1402 1402
         update_option('sensei_flush_rewrite_rules', '1');
1403 1403
 
@@ -1410,4 +1410,4 @@  discard block
 block discarded – undo
1410 1410
  * for backward compatibility
1411 1411
  * @since 1.9.0
1412 1412
  */
1413
-class Woothemes_Sensei extends Sensei_Main{ }
1413
+class Woothemes_Sensei extends Sensei_Main { }
Please login to merge, or discard this patch.
includes/class-sensei-wc.php 2 patches
Indentation   +748 added lines, -748 removed lines patch added patch discarded remove patch
@@ -12,735 +12,735 @@  discard block
 block discarded – undo
12 12
  */
13 13
 
14 14
 Class Sensei_WC{
15
-    /**
16
-     * Load the files needed for the woocommerce integration.
17
-     *
18
-     * @since 1.9.0
19
-     */
20
-    public static function load_woocommerce_integration_hooks(){
15
+	/**
16
+	 * Load the files needed for the woocommerce integration.
17
+	 *
18
+	 * @since 1.9.0
19
+	 */
20
+	public static function load_woocommerce_integration_hooks(){
21 21
 
22
-        require_once( __DIR__ . '/hooks/woocommerce.php' );
22
+		require_once( __DIR__ . '/hooks/woocommerce.php' );
23 23
 
24
-    }
25
-    /**
26
-     * check if WooCommerce plugin is loaded and allowed by Sensei
27
-     *
28
-     * @since 1.9.0
29
-     * @return bool
30
-     */
31
-    public static function is_woocommerce_active(){
24
+	}
25
+	/**
26
+	 * check if WooCommerce plugin is loaded and allowed by Sensei
27
+	 *
28
+	 * @since 1.9.0
29
+	 * @return bool
30
+	 */
31
+	public static function is_woocommerce_active(){
32 32
 
33
-        $is_woocommerce_enabled_in_settings = isset( Sensei()->settings->settings['woocommerce_enabled'] ) && Sensei()->settings->settings['woocommerce_enabled'];
34
-        return self::is_woocommerce_present() && $is_woocommerce_enabled_in_settings;
33
+		$is_woocommerce_enabled_in_settings = isset( Sensei()->settings->settings['woocommerce_enabled'] ) && Sensei()->settings->settings['woocommerce_enabled'];
34
+		return self::is_woocommerce_present() && $is_woocommerce_enabled_in_settings;
35 35
 
36
-    } // end is_woocommerce_active
36
+	} // end is_woocommerce_active
37 37
 
38
-    /**
39
-     * Checks if the WooCommerce plugin is installed and activation.
40
-     *
41
-     * If you need to check if WooCommerce is activated use Sensei_Utils::is_woocommerce_active().
42
-     * This function does nott check to see if the Sensei setting for WooCommerce is enabled.
43
-     *
44
-     * @since 1.9.0
45
-     *
46
-     * @return bool
47
-     */
48
-    public static function is_woocommerce_present(){
38
+	/**
39
+	 * Checks if the WooCommerce plugin is installed and activation.
40
+	 *
41
+	 * If you need to check if WooCommerce is activated use Sensei_Utils::is_woocommerce_active().
42
+	 * This function does nott check to see if the Sensei setting for WooCommerce is enabled.
43
+	 *
44
+	 * @since 1.9.0
45
+	 *
46
+	 * @return bool
47
+	 */
48
+	public static function is_woocommerce_present(){
49 49
 
50
-        $active_plugins = (array) get_option( 'active_plugins', array() );
50
+		$active_plugins = (array) get_option( 'active_plugins', array() );
51 51
 
52
-        if ( is_multisite() ){
52
+		if ( is_multisite() ){
53 53
 
54
-            $active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) );
54
+			$active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) );
55 55
 
56
-        }
56
+		}
57 57
 
58
-        $is_woocommerce_plugin_present_and_activated = in_array( 'woocommerce/woocommerce.php', $active_plugins ) || array_key_exists( 'woocommerce/woocommerce.php', $active_plugins );
58
+		$is_woocommerce_plugin_present_and_activated = in_array( 'woocommerce/woocommerce.php', $active_plugins ) || array_key_exists( 'woocommerce/woocommerce.php', $active_plugins );
59 59
 
60
-        return class_exists( 'Woocommerce' ) || $is_woocommerce_plugin_present_and_activated;
60
+		return class_exists( 'Woocommerce' ) || $is_woocommerce_plugin_present_and_activated;
61 61
 
62
-    }// end is_woocommerce_present
62
+	}// end is_woocommerce_present
63 63
 
64
-    /**
65
-     * Find the order active number (completed or processing ) for a given user on a course. It will return the latest order.
66
-     *
67
-     * If multiple exist we will return the latest order.
68
-     *
69
-     * @param $user_id
70
-     * @param $course_id
71
-     * @return array $user_course_orders
72
-     */
73
-    public static function get_learner_course_active_order_id( $user_id, $course_id ){
64
+	/**
65
+	 * Find the order active number (completed or processing ) for a given user on a course. It will return the latest order.
66
+	 *
67
+	 * If multiple exist we will return the latest order.
68
+	 *
69
+	 * @param $user_id
70
+	 * @param $course_id
71
+	 * @return array $user_course_orders
72
+	 */
73
+	public static function get_learner_course_active_order_id( $user_id, $course_id ){
74 74
 
75
-        $course_product_id = get_post_meta( $course_id, '_course_woocommerce_product', true );
75
+		$course_product_id = get_post_meta( $course_id, '_course_woocommerce_product', true );
76 76
 
77
-        $orders_query = new WP_Query( array(
78
-            'post_type'   => 'shop_order',
79
-            'posts_per_page' => -1,
80
-            'post_status' => array( 'wc-processing', 'wc-completed' ),
81
-            'meta_key'=> '_customer_user',
82
-            'meta_value'=> $user_id,
83
-        ) );
77
+		$orders_query = new WP_Query( array(
78
+			'post_type'   => 'shop_order',
79
+			'posts_per_page' => -1,
80
+			'post_status' => array( 'wc-processing', 'wc-completed' ),
81
+			'meta_key'=> '_customer_user',
82
+			'meta_value'=> $user_id,
83
+		) );
84 84
 
85
-        if( $orders_query->post_count == 0 ){
85
+		if( $orders_query->post_count == 0 ){
86 86
 
87
-            return false;
87
+			return false;
88 88
 
89
-        }
89
+		}
90 90
 
91
-        foreach( $orders_query->get_posts() as $order ){
91
+		foreach( $orders_query->get_posts() as $order ){
92 92
 
93
-            $order = new WC_Order( $order->ID );
94
-            $items = $order->get_items();
93
+			$order = new WC_Order( $order->ID );
94
+			$items = $order->get_items();
95 95
 
96
-            $user_orders =  array();
96
+			$user_orders =  array();
97 97
 
98
-            foreach( $items as $item ){
98
+			foreach( $items as $item ){
99 99
 
100
-                // if the product id on the order and the one given to this function
101
-                // this order has been placed by the given user on the given course.
102
-                $product = wc_get_product( $item['product_id'] );
100
+				// if the product id on the order and the one given to this function
101
+				// this order has been placed by the given user on the given course.
102
+				$product = wc_get_product( $item['product_id'] );
103 103
 
104
-                if ( $product->is_type( 'variable' )) {
104
+				if ( $product->is_type( 'variable' )) {
105 105
 
106
-                    $item_product_id = $item['variation_id'];
106
+					$item_product_id = $item['variation_id'];
107 107
 
108
-                } else {
108
+				} else {
109 109
 
110
-                    $item_product_id =  $item['product_id'];
110
+					$item_product_id =  $item['product_id'];
111 111
 
112
-                }
112
+				}
113 113
 
114
-                if( $course_product_id == $item_product_id ){
114
+				if( $course_product_id == $item_product_id ){
115 115
 
116
-                    return $order->id;
116
+					return $order->id;
117 117
 
118
-                }
118
+				}
119 119
 
120 120
 
121
-            }//end for each order item
121
+			}//end for each order item
122 122
 
123
-        } // end for each order
123
+		} // end for each order
124 124
 
125
-        // if we reach this place we found no order
126
-        return false;
125
+		// if we reach this place we found no order
126
+		return false;
127 127
 
128
-    } // end get_learner_course_active_order_ids
128
+	} // end get_learner_course_active_order_ids
129 129
 
130
-    /**
131
-     * Output WooCommerce specific course filters
132
-     * Removing the paged argument
133
-     *
134
-     * @since 1.9.0
135
-     * @param $filter_links
136
-     * @return mixed
137
-     */
138
-    public static function add_course_archive_wc_filter_links( $filter_links ){
130
+	/**
131
+	 * Output WooCommerce specific course filters
132
+	 * Removing the paged argument
133
+	 *
134
+	 * @since 1.9.0
135
+	 * @param $filter_links
136
+	 * @return mixed
137
+	 */
138
+	public static function add_course_archive_wc_filter_links( $filter_links ){
139 139
 
140
-        $free_courses = self::get_free_courses();
141
-        $paid_courses = self::get_paid_courses();
140
+		$free_courses = self::get_free_courses();
141
+		$paid_courses = self::get_paid_courses();
142 142
 
143
-        if ( empty( $free_courses ) || empty( $paid_courses )  ){
144
-            // do not show any WooCommerce filters if all courses are
145
-            // free or if all courses are paid
146
-            return $filter_links;
143
+		if ( empty( $free_courses ) || empty( $paid_courses )  ){
144
+			// do not show any WooCommerce filters if all courses are
145
+			// free or if all courses are paid
146
+			return $filter_links;
147 147
 
148
-        }
148
+		}
149 149
 
150
-        $filter_links[] = array(
151
-            'id'=>'paid' ,
152
-            'url'=> add_query_arg( array( 'course_filter'=>'paid'), Sensei_Course::get_courses_page_url() ),
153
-            'title'=>__( 'Paid', 'woothemes-sensei' )
154
-        );
150
+		$filter_links[] = array(
151
+			'id'=>'paid' ,
152
+			'url'=> add_query_arg( array( 'course_filter'=>'paid'), Sensei_Course::get_courses_page_url() ),
153
+			'title'=>__( 'Paid', 'woothemes-sensei' )
154
+		);
155 155
 
156
-        $filter_links[] = array(
157
-            'id'=>'free',
158
-            'url'=> add_query_arg( array( 'course_filter'=>'free'), Sensei_Course::get_courses_page_url() ),
159
-            'title'=>__( 'Free', 'woothemes-sensei' )
160
-        );
156
+		$filter_links[] = array(
157
+			'id'=>'free',
158
+			'url'=> add_query_arg( array( 'course_filter'=>'free'), Sensei_Course::get_courses_page_url() ),
159
+			'title'=>__( 'Free', 'woothemes-sensei' )
160
+		);
161 161
 
162
-        return $filter_links;
162
+		return $filter_links;
163 163
 
164
-    }// end add_course_archive_wc_filter_links
164
+	}// end add_course_archive_wc_filter_links
165 165
 
166
-    /**
167
-     * Apply the free filter the the course query
168
-     * getting all course with no products or products with zero price
169
-     *
170
-     * hooked into pre_get_posts
171
-     *
172
-     * @since 1.9.0
173
-     * @param WP_Query $query
174
-     * @return WP_Query $query
175
-     */
176
-    public static function course_archive_wc_filter_free( $query ){
166
+	/**
167
+	 * Apply the free filter the the course query
168
+	 * getting all course with no products or products with zero price
169
+	 *
170
+	 * hooked into pre_get_posts
171
+	 *
172
+	 * @since 1.9.0
173
+	 * @param WP_Query $query
174
+	 * @return WP_Query $query
175
+	 */
176
+	public static function course_archive_wc_filter_free( $query ){
177 177
 
178
-        if( isset( $_GET['course_filter'] ) && 'free' == $_GET['course_filter']
179
-            && 'course' == $query->get( 'post_type') && $query->is_main_query()  ){
178
+		if( isset( $_GET['course_filter'] ) && 'free' == $_GET['course_filter']
179
+			&& 'course' == $query->get( 'post_type') && $query->is_main_query()  ){
180 180
 
181
-            // setup the course meta query
182
-            $meta_query = self::get_free_courses_meta_query_args();
181
+			// setup the course meta query
182
+			$meta_query = self::get_free_courses_meta_query_args();
183 183
 
184
-            // manipulate the query to return free courses
185
-            $query->set('meta_query', $meta_query );
184
+			// manipulate the query to return free courses
185
+			$query->set('meta_query', $meta_query );
186 186
 
187
-            // don't show any paid courses
188
-            $courses = self::get_paid_courses();
189
-            $ids = array();
190
-            foreach( $courses as $course ){
191
-                $ids[] = $course->ID;
192
-            }
193
-            $query->set( 'post__not_in', $ids );
187
+			// don't show any paid courses
188
+			$courses = self::get_paid_courses();
189
+			$ids = array();
190
+			foreach( $courses as $course ){
191
+				$ids[] = $course->ID;
192
+			}
193
+			$query->set( 'post__not_in', $ids );
194 194
 
195
-        }// end if course_filter
195
+		}// end if course_filter
196 196
 
197
-        return $query;
197
+		return $query;
198 198
 
199
-    }// course_archive_wc_filter_free
199
+	}// course_archive_wc_filter_free
200 200
 
201
-    /**
202
-     * Apply the paid filter to the course query on the courses page
203
-     * will include all course with a product attached with a price
204
-     * more than 0
205
-     *
206
-     * hooked into pre_get_posts
207
-     *
208
-     * @since 1.9.0
209
-     * @param WP_Query $query
210
-     * @return WP_Query $query
211
-     */
212
-    public static function course_archive_wc_filter_paid( $query ){
201
+	/**
202
+	 * Apply the paid filter to the course query on the courses page
203
+	 * will include all course with a product attached with a price
204
+	 * more than 0
205
+	 *
206
+	 * hooked into pre_get_posts
207
+	 *
208
+	 * @since 1.9.0
209
+	 * @param WP_Query $query
210
+	 * @return WP_Query $query
211
+	 */
212
+	public static function course_archive_wc_filter_paid( $query ){
213 213
 
214
-        if( isset( $_GET['course_filter'] ) && 'paid' == $_GET['course_filter']
215
-            && 'course' == $query->get( 'post_type') && $query->is_main_query() ){
216
-
217
-            // setup the course meta query
218
-            $meta_query = self::get_paid_courses_meta_query_args();
219
-
220
-            // manipulate the query to return free courses
221
-            $query->set('meta_query', $meta_query );
222
-
223
-        }
224
-
225
-        return $query;
226
-
227
-    }
228
-
229
-    /**
230
-     * Load the WooCommerce single product actions above
231
-     * single courses if woocommerce is active allowing purchase
232
-     * information and actions to be hooked from WooCommerce.
233
-     */
234
-    public static function do_single_course_wc_single_product_action(){
235
-
236
-        /**
237
-         * this hooks is documented within the WooCommerce plugin.
238
-         */
239
-        if ( Sensei_WC::is_woocommerce_active() ) {
240
-
241
-            do_action( 'woocommerce_before_single_product' );
242
-
243
-        } // End If Statement
244
-
245
-    }// end do_single_course_wc_single_product_action
246
-
247
-    /**
248
-     * Hooking into the single lesson page to alter the
249
-     * user access permissions based on if they have purchased the
250
-     * course the lesson belongs to.
251
-     *
252
-     * This function will only return false or the passed in user_access value.
253
-     * It doesn't return true in order to avoid altering other options.
254
-     *
255
-     * @since 1.9.0
256
-     *
257
-     * @param $can_user_view_lesson
258
-     * @param $lesson_id
259
-     * @param $user_id
260
-     * @return bool
261
-     */
262
-    public static function alter_can_user_view_lesson ( $can_user_view_lesson, $lesson_id, $user_id  ){
263
-
264
-        // check if the course has a valid product attached to it
265
-        // which the user should have purchased if they want to access
266
-        // the current lesson
267
-        $course_id = get_post_meta( $lesson_id , '_lesson_course', true);
268
-        $wc_post_id = get_post_meta( $course_id, '_course_woocommerce_product', true );
269
-        $product = Sensei()->sensei_get_woocommerce_product_object($wc_post_id);
270
-        if( isset ($product) && is_object($product) ){
271
-
272
-            // valid product found
273
-            $order_id = self::get_learner_course_active_order_id( $user_id, $course_id );
274
-
275
-            // product has a successful order so this user may access the content
276
-            // this function may only return false or the default
277
-            // returning true may override other negatives which we don't want
278
-            if( ! $order_id ){
279
-
280
-                return false;
281
-
282
-            }
283
-
284
-        }
285
-
286
-        // return the passed in value
287
-        return $can_user_view_lesson;
288
-
289
-    }
290
-
291
-    /**
292
-     * Add course link to order thank you and details pages.
293
-     *
294
-     * @since  1.4.5
295
-     * @access public
296
-     *
297
-     * @return void
298
-     */
299
-    public static function course_link_from_order( ) {
300
-
301
-        if( ! is_order_received_page() ){
302
-            return;
303
-        }
304
-
305
-        $order_id = get_query_var( 'order-received' );
214
+		if( isset( $_GET['course_filter'] ) && 'paid' == $_GET['course_filter']
215
+			&& 'course' == $query->get( 'post_type') && $query->is_main_query() ){
216
+
217
+			// setup the course meta query
218
+			$meta_query = self::get_paid_courses_meta_query_args();
219
+
220
+			// manipulate the query to return free courses
221
+			$query->set('meta_query', $meta_query );
222
+
223
+		}
224
+
225
+		return $query;
226
+
227
+	}
228
+
229
+	/**
230
+	 * Load the WooCommerce single product actions above
231
+	 * single courses if woocommerce is active allowing purchase
232
+	 * information and actions to be hooked from WooCommerce.
233
+	 */
234
+	public static function do_single_course_wc_single_product_action(){
235
+
236
+		/**
237
+		 * this hooks is documented within the WooCommerce plugin.
238
+		 */
239
+		if ( Sensei_WC::is_woocommerce_active() ) {
240
+
241
+			do_action( 'woocommerce_before_single_product' );
242
+
243
+		} // End If Statement
244
+
245
+	}// end do_single_course_wc_single_product_action
246
+
247
+	/**
248
+	 * Hooking into the single lesson page to alter the
249
+	 * user access permissions based on if they have purchased the
250
+	 * course the lesson belongs to.
251
+	 *
252
+	 * This function will only return false or the passed in user_access value.
253
+	 * It doesn't return true in order to avoid altering other options.
254
+	 *
255
+	 * @since 1.9.0
256
+	 *
257
+	 * @param $can_user_view_lesson
258
+	 * @param $lesson_id
259
+	 * @param $user_id
260
+	 * @return bool
261
+	 */
262
+	public static function alter_can_user_view_lesson ( $can_user_view_lesson, $lesson_id, $user_id  ){
263
+
264
+		// check if the course has a valid product attached to it
265
+		// which the user should have purchased if they want to access
266
+		// the current lesson
267
+		$course_id = get_post_meta( $lesson_id , '_lesson_course', true);
268
+		$wc_post_id = get_post_meta( $course_id, '_course_woocommerce_product', true );
269
+		$product = Sensei()->sensei_get_woocommerce_product_object($wc_post_id);
270
+		if( isset ($product) && is_object($product) ){
271
+
272
+			// valid product found
273
+			$order_id = self::get_learner_course_active_order_id( $user_id, $course_id );
274
+
275
+			// product has a successful order so this user may access the content
276
+			// this function may only return false or the default
277
+			// returning true may override other negatives which we don't want
278
+			if( ! $order_id ){
279
+
280
+				return false;
281
+
282
+			}
283
+
284
+		}
285
+
286
+		// return the passed in value
287
+		return $can_user_view_lesson;
288
+
289
+	}
290
+
291
+	/**
292
+	 * Add course link to order thank you and details pages.
293
+	 *
294
+	 * @since  1.4.5
295
+	 * @access public
296
+	 *
297
+	 * @return void
298
+	 */
299
+	public static function course_link_from_order( ) {
300
+
301
+		if( ! is_order_received_page() ){
302
+			return;
303
+		}
304
+
305
+		$order_id = get_query_var( 'order-received' );
306 306
 		$order = new WC_Order( $order_id );
307 307
 
308 308
 		// exit early if not wc-completed or wc-processing
309 309
 		if( 'wc-completed' != $order->post_status
310
-            && 'wc-processing' != $order->post_status  ) {
311
-            return;
312
-        }
310
+			&& 'wc-processing' != $order->post_status  ) {
311
+			return;
312
+		}
313 313
 
314
-        $course_links = array(); // store the for links for courses purchased
314
+		$course_links = array(); // store the for links for courses purchased
315 315
 		foreach ( $order->get_items() as $item ) {
316 316
 
317
-            if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
317
+			if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
318 318
 
319
-                // If item has variation_id then its a variation of the product
320
-                $item_id = $item['variation_id'];
319
+				// If item has variation_id then its a variation of the product
320
+				$item_id = $item['variation_id'];
321 321
 
322
-            } else {
322
+			} else {
323 323
 
324
-                //If not its real product set its id to item_id
325
-                $item_id = $item['product_id'];
324
+				//If not its real product set its id to item_id
325
+				$item_id = $item['product_id'];
326 326
 
327
-            } // End If Statement
327
+			} // End If Statement
328 328
 
329
-            $user_id = get_post_meta( $order->id, '_customer_user', true );
329
+			$user_id = get_post_meta( $order->id, '_customer_user', true );
330 330
 
331
-            if( $user_id ) {
331
+			if( $user_id ) {
332 332
 
333
-                // Get all courses for product
334
-                $args = Sensei_Course::get_default_query_args();
335
-                $args['meta_query'] = array( array(
336
-                            'key' => '_course_woocommerce_product',
337
-                            'value' => $item_id
338
-                        ) );
339
-                $args['orderby'] = 'menu_order date';
340
-                $args['order'] = 'ASC';
333
+				// Get all courses for product
334
+				$args = Sensei_Course::get_default_query_args();
335
+				$args['meta_query'] = array( array(
336
+							'key' => '_course_woocommerce_product',
337
+							'value' => $item_id
338
+						) );
339
+				$args['orderby'] = 'menu_order date';
340
+				$args['order'] = 'ASC';
341 341
 
342
-                // loop through courses
343
-                $courses = get_posts( $args );
344
-                if( $courses && count( $courses ) > 0 ) {
342
+				// loop through courses
343
+				$courses = get_posts( $args );
344
+				if( $courses && count( $courses ) > 0 ) {
345 345
 
346
-                    foreach( $courses as $course ) {
346
+					foreach( $courses as $course ) {
347 347
 
348
-                        $title = $course->post_title;
349
-                        $permalink = get_permalink( $course->ID );
350
-                        $course_links[] .= '<a href="' . esc_url( $permalink ) . '" >' . $title . '</a> ';
348
+						$title = $course->post_title;
349
+						$permalink = get_permalink( $course->ID );
350
+						$course_links[] .= '<a href="' . esc_url( $permalink ) . '" >' . $title . '</a> ';
351 351
 
352
-                    } // end for each
352
+					} // end for each
353 353
 
354
-                    // close the message div
354
+					// close the message div
355 355
 
356
-                }// end if $courses check
357
-            }
358
-        }// end loop through orders
356
+				}// end if $courses check
357
+			}
358
+		}// end loop through orders
359 359
 
360
-        // add the courses to the WooCommerce notice
361
-        if( ! empty( $course_links) ){
360
+		// add the courses to the WooCommerce notice
361
+		if( ! empty( $course_links) ){
362 362
 
363
-            $courses_html = _nx(
364
-                'You have purchased the following course:',
365
-                'You have purchased the following courses:',
366
-                count( $course_links ),
367
-                'Purchase thank you note on Checkout page. The course link(s) will be show', 'woothemes-sensei'
368
-            );
363
+			$courses_html = _nx(
364
+				'You have purchased the following course:',
365
+				'You have purchased the following courses:',
366
+				count( $course_links ),
367
+				'Purchase thank you note on Checkout page. The course link(s) will be show', 'woothemes-sensei'
368
+			);
369 369
 
370
-            foreach( $course_links as $link ){
370
+			foreach( $course_links as $link ){
371 371
 
372
-                $courses_html .= '<li>' . $link . '</li>';
372
+				$courses_html .= '<li>' . $link . '</li>';
373 373
 
374
-            }
374
+			}
375 375
 
376
-            $courses_html .= ' </ul>';
376
+			$courses_html .= ' </ul>';
377 377
 
378
-            wc_add_notice( $courses_html, 'success' );
379
-        }
378
+			wc_add_notice( $courses_html, 'success' );
379
+		}
380 380
 
381 381
 	} // end course_link_order_form
382 382
 
383
-    /**
384
-     * Show the message that a user should complete
385
-     * their purchase if the course is in the cart
386
-     *
387
-     * This should be used within the course loop or single course page
388
-     *
389
-     * @since 1.9.0
390
-     */
391
-    public static function course_in_cart_message(){
383
+	/**
384
+	 * Show the message that a user should complete
385
+	 * their purchase if the course is in the cart
386
+	 *
387
+	 * This should be used within the course loop or single course page
388
+	 *
389
+	 * @since 1.9.0
390
+	 */
391
+	public static function course_in_cart_message(){
392 392
 
393
-        global $post;
393
+		global $post;
394 394
 
395
-        if( self::is_course_in_cart( $post->ID ) ){ ?>
395
+		if( self::is_course_in_cart( $post->ID ) ){ ?>
396 396
 
397 397
             <div class="sensei-message info">
398 398
                 <?php
399 399
 
400
-                $cart_link =  '<a class="cart-complete" href="' . WC()->cart->get_checkout_url()
401
-                              . '" title="' . __('complete purchase', 'woothemes-sensei') . '">'
402
-                              . __('complete the purchase', 'woothemes-sensei') . '</a>';
400
+				$cart_link =  '<a class="cart-complete" href="' . WC()->cart->get_checkout_url()
401
+							  . '" title="' . __('complete purchase', 'woothemes-sensei') . '">'
402
+							  . __('complete the purchase', 'woothemes-sensei') . '</a>';
403 403
 
404
-                echo sprintf(  __('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei'), $cart_link );
404
+				echo sprintf(  __('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei'), $cart_link );
405 405
 
406
-                ?>
406
+				?>
407 407
             </div>
408 408
         <?php }
409 409
 
410
-    } // End sensei_woocommerce_in_cart_message()
410
+	} // End sensei_woocommerce_in_cart_message()
411 411
 
412
-    /**
413
-     * Checks the cart to see if a course is in the cart.
414
-     *
415
-     * @param $course_id
416
-     * @return bool
417
-     */
418
-    public static function is_course_in_cart( $course_id ){
419
-
420
-        $wc_post_id = absint( get_post_meta( $course_id, '_course_woocommerce_product', true ) );
421
-        $user_course_status_id = Sensei_Utils::user_started_course( $course_id , get_current_user_id() );
422
-
423
-        if ( 0 < intval( $wc_post_id ) && ! $user_course_status_id ) {
424
-
425
-            if ( self::is_product_in_cart( $wc_post_id ) ) {
426
-
427
-                return true;
428
-
429
-            }
430
-
431
-        }
432
-
433
-        return false;
434
-
435
-    }// is_course_in_cart
436
-
437
-    /**
438
-     * Check the cart to see if the product is in the cart
439
-     *
440
-     * @param $product_id
441
-     * @return bool
442
-     */
443
-    public static function is_product_in_cart( $product_id ){
444
-
445
-        if ( 0 < $product_id ) {
446
-
447
-            $product = wc_get_product( $product_id );
448
-
449
-            $parent_id = '';
450
-            if( isset( $product->variation_id ) && 0 < intval( $product->variation_id ) ) {
451
-                $wc_product_id = $product->parent->id;
452
-            }
453
-            foreach( WC()->cart->get_cart() as $cart_item_key => $values ) {
454
-
455
-                $cart_product = $values['data'];
456
-                if( $product_id == $cart_product->id ) {
457
-
458
-                    return true;
459
-
460
-                }
461
-
462
-            }
463
-        } // End If Statement
464
-
465
-        return false;
466
-
467
-    } // end is_product_in_car
468
-
469
-    /**
470
-     * Get all free WooCommerce products
471
-     *
472
-     * @since 1.9.0
473
-     *
474
-     * @return array $free_products{
475
-     *  @type int $wp_post_id
476
-     * }
477
-     */
478
-    public static function get_free_product_ids(){
479
-
480
-        return  get_posts( array(
481
-            'post_type' => 'product',
482
-            'posts_per_page' => '1000',
483
-            'fields' => 'ids',
484
-            'meta_query'=> array(
485
-                'relation' => 'OR',
486
-                array(
487
-                    'key'=> '_regular_price',
488
-                    'value' => 0,
489
-                ),
490
-                array(
491
-                    'key'=> '_sale_price',
492
-                    'value' => 0,
493
-                ),
494
-            ),
495
-        ));
496
-
497
-    }// end get free product query
498
-
499
-    /**
500
-     * The metat query for courses that are free
501
-     *
502
-     * @since 1.9.0
503
-     * @return array $wp_meta_query_param
504
-     */
505
-    public static function get_free_courses_meta_query_args(){
506
-
507
-        return array(
508
-            'relation' => 'OR',
509
-            array(
510
-                'key'     => '_course_woocommerce_product',
511
-                'value' => '-',
512
-                'compare' => '=',
513
-            ),
514
-            array(
515
-                'key'     => '_course_woocommerce_product',
516
-                'value' => self::get_free_product_ids(),
517
-                'compare' => 'IN',
518
-            ),
519
-        );
520
-
521
-    }// get_free_courses_meta_query
522
-
523
-    /**
524
-     * The metat query for courses that are free
525
-     *
526
-     * @since 1.9.0
527
-     * @return array $wp_query_meta_query_args_param
528
-     */
529
-    public static function get_paid_courses_meta_query_args(){
530
-
531
-        $paid_product_ids = self::get_paid_product_ids();
532
-
533
-        return array(
534
-            array(
535
-                'key'     => '_course_woocommerce_product',
536
-                // when empty we give a false post_id to ensure the caller doesn't get any courses for their
537
-                // query
538
-                'value' => empty( $paid_product_ids  )? '-1000' : $paid_product_ids,
539
-                'compare' => 'IN',
540
-            ),
541
-        );
542
-
543
-    }// get_free_courses_meta_query
544
-
545
-    /**
546
-     * The WordPress Query args
547
-     * for paid products on sale
548
-     *
549
-     * @since 1.9.0
550
-     * @return array $product_query_args
551
-     */
552
-    public static function get_paid_products_on_sale_query_args(){
553
-
554
-        $args = array(
555
-                   'post_type' 		=> 'product',
556
-                   'posts_per_page' 		=> 1000,
557
-                   'orderby'         	=> 'date',
558
-                   'order'           	=> 'DESC',
559
-                   'suppress_filters' 	=> 0
560
-        );
561
-
562
-        $args[ 'fields' ]     = 'ids';
563
-
564
-        $args[ 'meta_query' ] = array(
565
-            'relation' => 'AND',
566
-            array(
567
-                'key'=> '_regular_price',
568
-                'compare' => '>',
569
-                'value' => 0,
570
-            ),
571
-            array(
572
-                'key'=> '_sale_price',
573
-                'compare' => '>',
574
-                'value' => 0,
575
-            ),
576
-        );
577
-
578
-        return $args;
579
-
580
-    } // get_paid_products_on_sale_query_args
581
-
582
-
583
-    /**
584
-     * Return the WordPress query args for
585
-     * products not on sale but that is not a free
586
-     *
587
-     * @since 1.9.0
588
-     *
589
-     * @return array
590
-     */
591
-    public static function get_paid_products_not_on_sale_query_args(){
592
-
593
-        $args = array(
594
-            'post_type' 		=> 'product',
595
-            'posts_per_page' 		=> 1000,
596
-            'orderby'         	=> 'date',
597
-            'order'           	=> 'DESC',
598
-            'suppress_filters' 	=> 0
599
-        );
600
-
601
-        $args[ 'fields' ]     = 'ids';
602
-        $args[ 'meta_query' ] = array(
603
-            'relation' => 'AND',
604
-            array(
605
-                'key'=> '_regular_price',
606
-                'compare' => '>',
607
-                'value' => 0,
608
-            ),
609
-            array(
610
-                'key'=> '_sale_price',
611
-                'compare' => '=',
612
-                'value' => '',
613
-            ),
614
-        );
615
-
616
-        return $args;
617
-
618
-
619
-    } // get_paid_courses_meta_query
620
-
621
-    /**
622
-     * Get all WooCommerce non-free product id's
623
-     *
624
-     * @since 1.9.0
625
-     *
626
-     * @return array $woocommerce_paid_product_ids
627
-     */
628
-    public static function get_paid_product_ids(){
629
-
630
-        // get all the paid WooCommerce products that has regular
631
-        // and sale price greater than 0
632
-        // will be used later to check for course with the id as meta
633
-        $paid_product_ids_with_sale =  get_posts( self::get_paid_products_on_sale_query_args() );
634
-
635
-        // get all the paid WooCommerce products that has regular price
636
-        // greater than 0 without a sale price
637
-        // will be used later to check for course with the id as meta
638
-        $paid_product_ids_without_sale = get_posts( self::get_paid_products_not_on_sale_query_args() );
639
-
640
-        // combine products ID's with regular and sale price grater than zero and those without
641
-        // sale but regular price greater than zero
642
-        $woocommerce_paid_product_ids = array_merge( $paid_product_ids_with_sale, $paid_product_ids_without_sale );
643
-
644
-        // if
645
-        if( empty($woocommerce_paid_product_ids) ){
646
-            return array( );
647
-        }
648
-        return $woocommerce_paid_product_ids;
649
-
650
-    }
651
-
652
-    /**
653
-     * Get all free courses.
654
-     *
655
-     * This course that have a WC product attached
656
-     * that has a price or sale price of zero and
657
-     * other courses with no WooCommerce products
658
-     * attached.
659
-     *
660
-     * @since 1.9.0
661
-     *
662
-     * @return array
663
-     */
664
-    public static function get_free_courses(){
665
-
666
-        $free_course_query_args = Sensei_Course::get_default_query_args();
667
-        $free_course_query_args[ 'meta_query' ] = self::get_free_courses_meta_query_args();
668
-
669
-        // don't show any paid courses
670
-        $courses = self::get_paid_courses();
671
-        $ids = array();
672
-        foreach( $courses as $course ){
673
-            $ids[] = $course->ID;
674
-        }
675
-        $free_course_query_args[ 'post__not_in' ] =  $ids;
676
-
677
-        return get_posts( $free_course_query_args );
678
-
679
-    }
680
-
681
-    /**
682
-     * Return all products that are not free
683
-     *
684
-     * @since 1.9.0
685
-     * @return array
686
-     */
687
-    public static function get_paid_courses(){
688
-
689
-        $paid_course_query_args = Sensei_Course::get_default_query_args();
690
-
691
-        $paid_course_query_args[ 'meta_query' ] = self::get_paid_courses_meta_query_args();
692
-
693
-        return get_posts(  $paid_course_query_args );
694
-    }
695
-
696
-    /**
697
-     * Show the WooCommerce add to cart button for the  current course
698
-     *
699
-     * The function will only show the button if
700
-     * 1- the user can buy the course
701
-     * 2- if they have completed their pre-requisite
702
-     * 3- if the course has a valid product attached
703
-     *
704
-     * @since 1.9.0
705
-     * @param int $course_id
706
-     * @return string $html markup for the button or nothing if user not allowed to buy
707
-     */
708
-    public static function the_add_to_cart_button_html( $course_id ){
709
-
710
-        if ( ! Sensei_Course::is_prerequisite_complete( $course_id )) {
711
-            return '';
712
-        }
713
-
714
-        $wc_post_id = self::get_course_product_id( $course_id );
715
-
716
-        // Check if customer purchased the product
717
-        if ( self::has_customer_bought_product(  get_current_user_id(), $wc_post_id )
718
-            || empty( $wc_post_id ) ) {
719
-
720
-            return '';
721
-
722
-        }
723
-
724
-        // based on simple.php in WC templates/single-product/add-to-cart/
725
-        // Get the product
726
-        $product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id );
727
-
728
-        // do not show the button for invalid products, non purchasable products, out
729
-        // of stock product or if course is already in cart
730
-        if ( ! isset ( $product )
731
-            || ! is_object( $product )
732
-            || ! $product->is_purchasable()
733
-            || ! $product->is_in_stock()
734
-            || self::is_course_in_cart( $wc_post_id ) ) {
735
-
736
-            return '';
737
-
738
-        }
739
-
740
-        //
741
-        // button  output:
742
-        //
743
-        ?>
412
+	/**
413
+	 * Checks the cart to see if a course is in the cart.
414
+	 *
415
+	 * @param $course_id
416
+	 * @return bool
417
+	 */
418
+	public static function is_course_in_cart( $course_id ){
419
+
420
+		$wc_post_id = absint( get_post_meta( $course_id, '_course_woocommerce_product', true ) );
421
+		$user_course_status_id = Sensei_Utils::user_started_course( $course_id , get_current_user_id() );
422
+
423
+		if ( 0 < intval( $wc_post_id ) && ! $user_course_status_id ) {
424
+
425
+			if ( self::is_product_in_cart( $wc_post_id ) ) {
426
+
427
+				return true;
428
+
429
+			}
430
+
431
+		}
432
+
433
+		return false;
434
+
435
+	}// is_course_in_cart
436
+
437
+	/**
438
+	 * Check the cart to see if the product is in the cart
439
+	 *
440
+	 * @param $product_id
441
+	 * @return bool
442
+	 */
443
+	public static function is_product_in_cart( $product_id ){
444
+
445
+		if ( 0 < $product_id ) {
446
+
447
+			$product = wc_get_product( $product_id );
448
+
449
+			$parent_id = '';
450
+			if( isset( $product->variation_id ) && 0 < intval( $product->variation_id ) ) {
451
+				$wc_product_id = $product->parent->id;
452
+			}
453
+			foreach( WC()->cart->get_cart() as $cart_item_key => $values ) {
454
+
455
+				$cart_product = $values['data'];
456
+				if( $product_id == $cart_product->id ) {
457
+
458
+					return true;
459
+
460
+				}
461
+
462
+			}
463
+		} // End If Statement
464
+
465
+		return false;
466
+
467
+	} // end is_product_in_car
468
+
469
+	/**
470
+	 * Get all free WooCommerce products
471
+	 *
472
+	 * @since 1.9.0
473
+	 *
474
+	 * @return array $free_products{
475
+	 *  @type int $wp_post_id
476
+	 * }
477
+	 */
478
+	public static function get_free_product_ids(){
479
+
480
+		return  get_posts( array(
481
+			'post_type' => 'product',
482
+			'posts_per_page' => '1000',
483
+			'fields' => 'ids',
484
+			'meta_query'=> array(
485
+				'relation' => 'OR',
486
+				array(
487
+					'key'=> '_regular_price',
488
+					'value' => 0,
489
+				),
490
+				array(
491
+					'key'=> '_sale_price',
492
+					'value' => 0,
493
+				),
494
+			),
495
+		));
496
+
497
+	}// end get free product query
498
+
499
+	/**
500
+	 * The metat query for courses that are free
501
+	 *
502
+	 * @since 1.9.0
503
+	 * @return array $wp_meta_query_param
504
+	 */
505
+	public static function get_free_courses_meta_query_args(){
506
+
507
+		return array(
508
+			'relation' => 'OR',
509
+			array(
510
+				'key'     => '_course_woocommerce_product',
511
+				'value' => '-',
512
+				'compare' => '=',
513
+			),
514
+			array(
515
+				'key'     => '_course_woocommerce_product',
516
+				'value' => self::get_free_product_ids(),
517
+				'compare' => 'IN',
518
+			),
519
+		);
520
+
521
+	}// get_free_courses_meta_query
522
+
523
+	/**
524
+	 * The metat query for courses that are free
525
+	 *
526
+	 * @since 1.9.0
527
+	 * @return array $wp_query_meta_query_args_param
528
+	 */
529
+	public static function get_paid_courses_meta_query_args(){
530
+
531
+		$paid_product_ids = self::get_paid_product_ids();
532
+
533
+		return array(
534
+			array(
535
+				'key'     => '_course_woocommerce_product',
536
+				// when empty we give a false post_id to ensure the caller doesn't get any courses for their
537
+				// query
538
+				'value' => empty( $paid_product_ids  )? '-1000' : $paid_product_ids,
539
+				'compare' => 'IN',
540
+			),
541
+		);
542
+
543
+	}// get_free_courses_meta_query
544
+
545
+	/**
546
+	 * The WordPress Query args
547
+	 * for paid products on sale
548
+	 *
549
+	 * @since 1.9.0
550
+	 * @return array $product_query_args
551
+	 */
552
+	public static function get_paid_products_on_sale_query_args(){
553
+
554
+		$args = array(
555
+				   'post_type' 		=> 'product',
556
+				   'posts_per_page' 		=> 1000,
557
+				   'orderby'         	=> 'date',
558
+				   'order'           	=> 'DESC',
559
+				   'suppress_filters' 	=> 0
560
+		);
561
+
562
+		$args[ 'fields' ]     = 'ids';
563
+
564
+		$args[ 'meta_query' ] = array(
565
+			'relation' => 'AND',
566
+			array(
567
+				'key'=> '_regular_price',
568
+				'compare' => '>',
569
+				'value' => 0,
570
+			),
571
+			array(
572
+				'key'=> '_sale_price',
573
+				'compare' => '>',
574
+				'value' => 0,
575
+			),
576
+		);
577
+
578
+		return $args;
579
+
580
+	} // get_paid_products_on_sale_query_args
581
+
582
+
583
+	/**
584
+	 * Return the WordPress query args for
585
+	 * products not on sale but that is not a free
586
+	 *
587
+	 * @since 1.9.0
588
+	 *
589
+	 * @return array
590
+	 */
591
+	public static function get_paid_products_not_on_sale_query_args(){
592
+
593
+		$args = array(
594
+			'post_type' 		=> 'product',
595
+			'posts_per_page' 		=> 1000,
596
+			'orderby'         	=> 'date',
597
+			'order'           	=> 'DESC',
598
+			'suppress_filters' 	=> 0
599
+		);
600
+
601
+		$args[ 'fields' ]     = 'ids';
602
+		$args[ 'meta_query' ] = array(
603
+			'relation' => 'AND',
604
+			array(
605
+				'key'=> '_regular_price',
606
+				'compare' => '>',
607
+				'value' => 0,
608
+			),
609
+			array(
610
+				'key'=> '_sale_price',
611
+				'compare' => '=',
612
+				'value' => '',
613
+			),
614
+		);
615
+
616
+		return $args;
617
+
618
+
619
+	} // get_paid_courses_meta_query
620
+
621
+	/**
622
+	 * Get all WooCommerce non-free product id's
623
+	 *
624
+	 * @since 1.9.0
625
+	 *
626
+	 * @return array $woocommerce_paid_product_ids
627
+	 */
628
+	public static function get_paid_product_ids(){
629
+
630
+		// get all the paid WooCommerce products that has regular
631
+		// and sale price greater than 0
632
+		// will be used later to check for course with the id as meta
633
+		$paid_product_ids_with_sale =  get_posts( self::get_paid_products_on_sale_query_args() );
634
+
635
+		// get all the paid WooCommerce products that has regular price
636
+		// greater than 0 without a sale price
637
+		// will be used later to check for course with the id as meta
638
+		$paid_product_ids_without_sale = get_posts( self::get_paid_products_not_on_sale_query_args() );
639
+
640
+		// combine products ID's with regular and sale price grater than zero and those without
641
+		// sale but regular price greater than zero
642
+		$woocommerce_paid_product_ids = array_merge( $paid_product_ids_with_sale, $paid_product_ids_without_sale );
643
+
644
+		// if
645
+		if( empty($woocommerce_paid_product_ids) ){
646
+			return array( );
647
+		}
648
+		return $woocommerce_paid_product_ids;
649
+
650
+	}
651
+
652
+	/**
653
+	 * Get all free courses.
654
+	 *
655
+	 * This course that have a WC product attached
656
+	 * that has a price or sale price of zero and
657
+	 * other courses with no WooCommerce products
658
+	 * attached.
659
+	 *
660
+	 * @since 1.9.0
661
+	 *
662
+	 * @return array
663
+	 */
664
+	public static function get_free_courses(){
665
+
666
+		$free_course_query_args = Sensei_Course::get_default_query_args();
667
+		$free_course_query_args[ 'meta_query' ] = self::get_free_courses_meta_query_args();
668
+
669
+		// don't show any paid courses
670
+		$courses = self::get_paid_courses();
671
+		$ids = array();
672
+		foreach( $courses as $course ){
673
+			$ids[] = $course->ID;
674
+		}
675
+		$free_course_query_args[ 'post__not_in' ] =  $ids;
676
+
677
+		return get_posts( $free_course_query_args );
678
+
679
+	}
680
+
681
+	/**
682
+	 * Return all products that are not free
683
+	 *
684
+	 * @since 1.9.0
685
+	 * @return array
686
+	 */
687
+	public static function get_paid_courses(){
688
+
689
+		$paid_course_query_args = Sensei_Course::get_default_query_args();
690
+
691
+		$paid_course_query_args[ 'meta_query' ] = self::get_paid_courses_meta_query_args();
692
+
693
+		return get_posts(  $paid_course_query_args );
694
+	}
695
+
696
+	/**
697
+	 * Show the WooCommerce add to cart button for the  current course
698
+	 *
699
+	 * The function will only show the button if
700
+	 * 1- the user can buy the course
701
+	 * 2- if they have completed their pre-requisite
702
+	 * 3- if the course has a valid product attached
703
+	 *
704
+	 * @since 1.9.0
705
+	 * @param int $course_id
706
+	 * @return string $html markup for the button or nothing if user not allowed to buy
707
+	 */
708
+	public static function the_add_to_cart_button_html( $course_id ){
709
+
710
+		if ( ! Sensei_Course::is_prerequisite_complete( $course_id )) {
711
+			return '';
712
+		}
713
+
714
+		$wc_post_id = self::get_course_product_id( $course_id );
715
+
716
+		// Check if customer purchased the product
717
+		if ( self::has_customer_bought_product(  get_current_user_id(), $wc_post_id )
718
+			|| empty( $wc_post_id ) ) {
719
+
720
+			return '';
721
+
722
+		}
723
+
724
+		// based on simple.php in WC templates/single-product/add-to-cart/
725
+		// Get the product
726
+		$product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id );
727
+
728
+		// do not show the button for invalid products, non purchasable products, out
729
+		// of stock product or if course is already in cart
730
+		if ( ! isset ( $product )
731
+			|| ! is_object( $product )
732
+			|| ! $product->is_purchasable()
733
+			|| ! $product->is_in_stock()
734
+			|| self::is_course_in_cart( $wc_post_id ) ) {
735
+
736
+			return '';
737
+
738
+		}
739
+
740
+		//
741
+		// button  output:
742
+		//
743
+		?>
744 744
 
745 745
         <form action="<?php echo esc_url( $product->add_to_cart_url() ); ?>"
746 746
               class="cart"
@@ -773,54 +773,54 @@  discard block
 block discarded – undo
773 773
         </form>
774 774
 
775 775
         <?php
776
-    } // end the_add_to_cart_button_html
776
+	} // end the_add_to_cart_button_html
777 777
 
778
-    /**
779
-     * Alter the no permissions message on the single course page
780
-     * Changes the message to a WooCommerce specific message.
781
-     *
782
-     * @since 1.9.0
783
-     *
784
-     * @param $message
785
-     * @param $post_id
786
-     *
787
-     * @return string $message
788
-     */
789
-    public static function alter_no_permissions_message( $message, $post_id ){
778
+	/**
779
+	 * Alter the no permissions message on the single course page
780
+	 * Changes the message to a WooCommerce specific message.
781
+	 *
782
+	 * @since 1.9.0
783
+	 *
784
+	 * @param $message
785
+	 * @param $post_id
786
+	 *
787
+	 * @return string $message
788
+	 */
789
+	public static function alter_no_permissions_message( $message, $post_id ){
790 790
 
791
-        if( empty( $post_id ) || 'course'!=get_post_type( $post_id ) ){
792
-            return  $message;
793
-        }
791
+		if( empty( $post_id ) || 'course'!=get_post_type( $post_id ) ){
792
+			return  $message;
793
+		}
794 794
 
795
-        $product_id = self::get_course_product_id( $post_id );
795
+		$product_id = self::get_course_product_id( $post_id );
796 796
 
797
-        if( ! $product_id
798
-            || self::has_customer_bought_product( get_current_user_id(),$product_id ) ){
797
+		if( ! $product_id
798
+			|| self::has_customer_bought_product( get_current_user_id(),$product_id ) ){
799 799
 
800
-            return $message;
800
+			return $message;
801 801
 
802
-        }
802
+		}
803 803
 
804
-        ob_start();
805
-        self::the_course_no_permissions_message( $post_id );
806
-        $woocommerce_course_no_permissions_message = ob_get_clean();
804
+		ob_start();
805
+		self::the_course_no_permissions_message( $post_id );
806
+		$woocommerce_course_no_permissions_message = ob_get_clean();
807 807
 
808
-        return $woocommerce_course_no_permissions_message ;
808
+		return $woocommerce_course_no_permissions_message ;
809 809
 
810
-    }
811
-    /**
812
-     * Show the no permissions message when a user is logged in
813
-     * and have not yet purchased the current course
814
-     *
815
-     * @since 1.9.0
816
-     */
817
-    public static function the_course_no_permissions_message( $course_id ){
810
+	}
811
+	/**
812
+	 * Show the no permissions message when a user is logged in
813
+	 * and have not yet purchased the current course
814
+	 *
815
+	 * @since 1.9.0
816
+	 */
817
+	public static function the_course_no_permissions_message( $course_id ){
818 818
 
819
-        // login link
820
-        $my_courses_page_id = intval( Sensei()->settings->settings[ 'my_course_page' ] );
821
-        $login_link =  '<a href="' . esc_url( get_permalink( $my_courses_page_id ) ) . '">' . __( 'log in', 'woothemes-sensei' ) . '</a>';
819
+		// login link
820
+		$my_courses_page_id = intval( Sensei()->settings->settings[ 'my_course_page' ] );
821
+		$login_link =  '<a href="' . esc_url( get_permalink( $my_courses_page_id ) ) . '">' . __( 'log in', 'woothemes-sensei' ) . '</a>';
822 822
 
823
-        ?>
823
+		?>
824 824
 
825 825
         <span class="add-to-cart-login">
826 826
             <?php echo sprintf( __( 'Or %1$s to access your purchased courses', 'woothemes-sensei' ), $login_link ); ?>
@@ -828,110 +828,110 @@  discard block
 block discarded – undo
828 828
 
829 829
     <?php }
830 830
 
831
-    /**
832
-     * Checks if a user has bought a product item.
833
-     *
834
-     * @since  1.9.0
835
-     *
836
-     * @param  int $user_id
837
-     * @param  int $product_id
838
-     *
839
-     * @return bool
840
-     */
841
-    public static function has_customer_bought_product ( $user_id, $product_id ){
831
+	/**
832
+	 * Checks if a user has bought a product item.
833
+	 *
834
+	 * @since  1.9.0
835
+	 *
836
+	 * @param  int $user_id
837
+	 * @param  int $product_id
838
+	 *
839
+	 * @return bool
840
+	 */
841
+	public static function has_customer_bought_product ( $user_id, $product_id ){
842 842
 
843
-        $orders = get_posts( array(
844
-            'posts_per_page' => -1,
845
-            'meta_key'    => '_customer_user',
846
-            'meta_value'  => intval( $user_id ),
847
-            'post_type'   => 'shop_order',
848
-            'post_status' =>  array( 'wc-processing', 'wc-completed' ),
849
-        ) );
843
+		$orders = get_posts( array(
844
+			'posts_per_page' => -1,
845
+			'meta_key'    => '_customer_user',
846
+			'meta_value'  => intval( $user_id ),
847
+			'post_type'   => 'shop_order',
848
+			'post_status' =>  array( 'wc-processing', 'wc-completed' ),
849
+		) );
850 850
 
851
-        foreach ( $orders as $order_id ) {
851
+		foreach ( $orders as $order_id ) {
852 852
 
853
-            $order = new WC_Order( $order_id->ID );
853
+			$order = new WC_Order( $order_id->ID );
854 854
 
855
-            if ( $order->post_status != 'wc-completed' && $order->post_status != 'wc-processing' ) {
855
+			if ( $order->post_status != 'wc-completed' && $order->post_status != 'wc-processing' ) {
856 856
 
857
-                continue;
858
-            }
857
+				continue;
858
+			}
859 859
 
860
-            if ( ! ( 0 < sizeof( $order->get_items() ) ) ) {
860
+			if ( ! ( 0 < sizeof( $order->get_items() ) ) ) {
861 861
 
862
-                continue;
862
+				continue;
863 863
 
864
-            }
864
+			}
865 865
 
866
-            foreach( $order->get_items() as $item ) {
866
+			foreach( $order->get_items() as $item ) {
867 867
 
868
-                // Check if user has bought product
869
-                if ( $item['product_id'] == $product_id || $item['variation_id'] == $product_id ) {
868
+				// Check if user has bought product
869
+				if ( $item['product_id'] == $product_id || $item['variation_id'] == $product_id ) {
870 870
 
871
-                    // Check if user has an active subscription for product
872
-                    if( class_exists( 'WC_Subscriptions_Manager' ) ) {
873
-                        $sub_key = WC_Subscriptions_Manager::get_subscription_key( $order_id->ID, $product_id );
874
-                        if( $sub_key ) {
875
-                            $sub = WC_Subscriptions_Manager::get_subscription( $sub_key );
876
-                            if( $sub && isset( $sub['status'] ) ) {
877
-                                if( 'active' == $sub['status'] ) {
878
-                                    return true;
879
-                                } else {
880
-                                    return false;
881
-                                }
882
-                            }
883
-                        }
884
-                    }
871
+					// Check if user has an active subscription for product
872
+					if( class_exists( 'WC_Subscriptions_Manager' ) ) {
873
+						$sub_key = WC_Subscriptions_Manager::get_subscription_key( $order_id->ID, $product_id );
874
+						if( $sub_key ) {
875
+							$sub = WC_Subscriptions_Manager::get_subscription( $sub_key );
876
+							if( $sub && isset( $sub['status'] ) ) {
877
+								if( 'active' == $sub['status'] ) {
878
+									return true;
879
+								} else {
880
+									return false;
881
+								}
882
+							}
883
+						}
884
+					}
885 885
 
886
-                    // Customer has bought product
887
-                    return true;
888
-                } // End If Statement
886
+					// Customer has bought product
887
+					return true;
888
+				} // End If Statement
889 889
 
890
-            } // End For each item
890
+			} // End For each item
891 891
 
892
-        } // End For each order
892
+		} // End For each order
893 893
 
894
-    } // end has customer bought product
894
+	} // end has customer bought product
895 895
 
896
-    /**
897
-     * Return the product id for the given course
898
-     *
899
-     * @since 1.9.0
900
-     *
901
-     * @param int $course_id
902
-     *
903
-     * @return string $woocommerce_product_id or false if none exist
904
-     *
905
-     */
906
-    public static function get_course_product_id( $course_id ){
896
+	/**
897
+	 * Return the product id for the given course
898
+	 *
899
+	 * @since 1.9.0
900
+	 *
901
+	 * @param int $course_id
902
+	 *
903
+	 * @return string $woocommerce_product_id or false if none exist
904
+	 *
905
+	 */
906
+	public static function get_course_product_id( $course_id ){
907 907
 
908
-        $product_id =  get_post_meta( $course_id, '_course_woocommerce_product', true );
908
+		$product_id =  get_post_meta( $course_id, '_course_woocommerce_product', true );
909 909
 
910
-        if( empty( $product_id ) || 'product' != get_post_type( $product_id ) ){
911
-            return false;
912
-        }
910
+		if( empty( $product_id ) || 'product' != get_post_type( $product_id ) ){
911
+			return false;
912
+		}
913 913
 
914
-        return $product_id;
914
+		return $product_id;
915 915
 
916
-    }
916
+	}
917 917
 
918
-    /**
919
-     * Alter the body classes adding WooCommerce to the body
920
-     *
921
-     * @param array $classes
922
-     * @return array
923
-     */
924
-    public static function add_woocommerce_body_class( $classes ){
918
+	/**
919
+	 * Alter the body classes adding WooCommerce to the body
920
+	 *
921
+	 * @param array $classes
922
+	 * @return array
923
+	 */
924
+	public static function add_woocommerce_body_class( $classes ){
925 925
 
926
-        if( ! in_array( 'woocommerce', $classes ) ){
926
+		if( ! in_array( 'woocommerce', $classes ) ){
927 927
 
928
-            $classes[] ='woocommerce';
928
+			$classes[] ='woocommerce';
929 929
 
930
-        }
930
+		}
931 931
 
932 932
 
933
-        return $classes;
933
+		return $classes;
934 934
 
935
-    }
935
+	}
936 936
 
937 937
 }// end Sensei_WC
Please login to merge, or discard this patch.
Spacing   +163 added lines, -163 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // security check, don't load file outside WP
2
+if ( ! defined('ABSPATH')) exit; // security check, don't load file outside WP
3 3
 
4 4
 /**
5 5
  * Sensei WooCommerce class
@@ -11,15 +11,15 @@  discard block
 block discarded – undo
11 11
  * @since 1.9.0
12 12
  */
13 13
 
14
-Class Sensei_WC{
14
+Class Sensei_WC {
15 15
     /**
16 16
      * Load the files needed for the woocommerce integration.
17 17
      *
18 18
      * @since 1.9.0
19 19
      */
20
-    public static function load_woocommerce_integration_hooks(){
20
+    public static function load_woocommerce_integration_hooks() {
21 21
 
22
-        require_once( __DIR__ . '/hooks/woocommerce.php' );
22
+        require_once(__DIR__.'/hooks/woocommerce.php');
23 23
 
24 24
     }
25 25
     /**
@@ -28,9 +28,9 @@  discard block
 block discarded – undo
28 28
      * @since 1.9.0
29 29
      * @return bool
30 30
      */
31
-    public static function is_woocommerce_active(){
31
+    public static function is_woocommerce_active() {
32 32
 
33
-        $is_woocommerce_enabled_in_settings = isset( Sensei()->settings->settings['woocommerce_enabled'] ) && Sensei()->settings->settings['woocommerce_enabled'];
33
+        $is_woocommerce_enabled_in_settings = isset(Sensei()->settings->settings['woocommerce_enabled']) && Sensei()->settings->settings['woocommerce_enabled'];
34 34
         return self::is_woocommerce_present() && $is_woocommerce_enabled_in_settings;
35 35
 
36 36
     } // end is_woocommerce_active
@@ -45,19 +45,19 @@  discard block
 block discarded – undo
45 45
      *
46 46
      * @return bool
47 47
      */
48
-    public static function is_woocommerce_present(){
48
+    public static function is_woocommerce_present() {
49 49
 
50
-        $active_plugins = (array) get_option( 'active_plugins', array() );
50
+        $active_plugins = (array) get_option('active_plugins', array());
51 51
 
52
-        if ( is_multisite() ){
52
+        if (is_multisite()) {
53 53
 
54
-            $active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) );
54
+            $active_plugins = array_merge($active_plugins, get_site_option('active_sitewide_plugins', array()));
55 55
 
56 56
         }
57 57
 
58
-        $is_woocommerce_plugin_present_and_activated = in_array( 'woocommerce/woocommerce.php', $active_plugins ) || array_key_exists( 'woocommerce/woocommerce.php', $active_plugins );
58
+        $is_woocommerce_plugin_present_and_activated = in_array('woocommerce/woocommerce.php', $active_plugins) || array_key_exists('woocommerce/woocommerce.php', $active_plugins);
59 59
 
60
-        return class_exists( 'Woocommerce' ) || $is_woocommerce_plugin_present_and_activated;
60
+        return class_exists('Woocommerce') || $is_woocommerce_plugin_present_and_activated;
61 61
 
62 62
     }// end is_woocommerce_present
63 63
 
@@ -70,48 +70,48 @@  discard block
 block discarded – undo
70 70
      * @param $course_id
71 71
      * @return array $user_course_orders
72 72
      */
73
-    public static function get_learner_course_active_order_id( $user_id, $course_id ){
73
+    public static function get_learner_course_active_order_id($user_id, $course_id) {
74 74
 
75
-        $course_product_id = get_post_meta( $course_id, '_course_woocommerce_product', true );
75
+        $course_product_id = get_post_meta($course_id, '_course_woocommerce_product', true);
76 76
 
77
-        $orders_query = new WP_Query( array(
77
+        $orders_query = new WP_Query(array(
78 78
             'post_type'   => 'shop_order',
79 79
             'posts_per_page' => -1,
80
-            'post_status' => array( 'wc-processing', 'wc-completed' ),
80
+            'post_status' => array('wc-processing', 'wc-completed'),
81 81
             'meta_key'=> '_customer_user',
82 82
             'meta_value'=> $user_id,
83
-        ) );
83
+        ));
84 84
 
85
-        if( $orders_query->post_count == 0 ){
85
+        if ($orders_query->post_count == 0) {
86 86
 
87 87
             return false;
88 88
 
89 89
         }
90 90
 
91
-        foreach( $orders_query->get_posts() as $order ){
91
+        foreach ($orders_query->get_posts() as $order) {
92 92
 
93
-            $order = new WC_Order( $order->ID );
93
+            $order = new WC_Order($order->ID);
94 94
             $items = $order->get_items();
95 95
 
96
-            $user_orders =  array();
96
+            $user_orders = array();
97 97
 
98
-            foreach( $items as $item ){
98
+            foreach ($items as $item) {
99 99
 
100 100
                 // if the product id on the order and the one given to this function
101 101
                 // this order has been placed by the given user on the given course.
102
-                $product = wc_get_product( $item['product_id'] );
102
+                $product = wc_get_product($item['product_id']);
103 103
 
104
-                if ( $product->is_type( 'variable' )) {
104
+                if ($product->is_type('variable')) {
105 105
 
106 106
                     $item_product_id = $item['variation_id'];
107 107
 
108 108
                 } else {
109 109
 
110
-                    $item_product_id =  $item['product_id'];
110
+                    $item_product_id = $item['product_id'];
111 111
 
112 112
                 }
113 113
 
114
-                if( $course_product_id == $item_product_id ){
114
+                if ($course_product_id == $item_product_id) {
115 115
 
116 116
                     return $order->id;
117 117
 
@@ -135,12 +135,12 @@  discard block
 block discarded – undo
135 135
      * @param $filter_links
136 136
      * @return mixed
137 137
      */
138
-    public static function add_course_archive_wc_filter_links( $filter_links ){
138
+    public static function add_course_archive_wc_filter_links($filter_links) {
139 139
 
140 140
         $free_courses = self::get_free_courses();
141 141
         $paid_courses = self::get_paid_courses();
142 142
 
143
-        if ( empty( $free_courses ) || empty( $paid_courses )  ){
143
+        if (empty($free_courses) || empty($paid_courses)) {
144 144
             // do not show any WooCommerce filters if all courses are
145 145
             // free or if all courses are paid
146 146
             return $filter_links;
@@ -148,15 +148,15 @@  discard block
 block discarded – undo
148 148
         }
149 149
 
150 150
         $filter_links[] = array(
151
-            'id'=>'paid' ,
152
-            'url'=> add_query_arg( array( 'course_filter'=>'paid'), Sensei_Course::get_courses_page_url() ),
153
-            'title'=>__( 'Paid', 'woothemes-sensei' )
151
+            'id'=>'paid',
152
+            'url'=> add_query_arg(array('course_filter'=>'paid'), Sensei_Course::get_courses_page_url()),
153
+            'title'=>__('Paid', 'woothemes-sensei')
154 154
         );
155 155
 
156 156
         $filter_links[] = array(
157 157
             'id'=>'free',
158
-            'url'=> add_query_arg( array( 'course_filter'=>'free'), Sensei_Course::get_courses_page_url() ),
159
-            'title'=>__( 'Free', 'woothemes-sensei' )
158
+            'url'=> add_query_arg(array('course_filter'=>'free'), Sensei_Course::get_courses_page_url()),
159
+            'title'=>__('Free', 'woothemes-sensei')
160 160
         );
161 161
 
162 162
         return $filter_links;
@@ -173,24 +173,24 @@  discard block
 block discarded – undo
173 173
      * @param WP_Query $query
174 174
      * @return WP_Query $query
175 175
      */
176
-    public static function course_archive_wc_filter_free( $query ){
176
+    public static function course_archive_wc_filter_free($query) {
177 177
 
178
-        if( isset( $_GET['course_filter'] ) && 'free' == $_GET['course_filter']
179
-            && 'course' == $query->get( 'post_type') && $query->is_main_query()  ){
178
+        if (isset($_GET['course_filter']) && 'free' == $_GET['course_filter']
179
+            && 'course' == $query->get('post_type') && $query->is_main_query()) {
180 180
 
181 181
             // setup the course meta query
182 182
             $meta_query = self::get_free_courses_meta_query_args();
183 183
 
184 184
             // manipulate the query to return free courses
185
-            $query->set('meta_query', $meta_query );
185
+            $query->set('meta_query', $meta_query);
186 186
 
187 187
             // don't show any paid courses
188 188
             $courses = self::get_paid_courses();
189 189
             $ids = array();
190
-            foreach( $courses as $course ){
190
+            foreach ($courses as $course) {
191 191
                 $ids[] = $course->ID;
192 192
             }
193
-            $query->set( 'post__not_in', $ids );
193
+            $query->set('post__not_in', $ids);
194 194
 
195 195
         }// end if course_filter
196 196
 
@@ -209,16 +209,16 @@  discard block
 block discarded – undo
209 209
      * @param WP_Query $query
210 210
      * @return WP_Query $query
211 211
      */
212
-    public static function course_archive_wc_filter_paid( $query ){
212
+    public static function course_archive_wc_filter_paid($query) {
213 213
 
214
-        if( isset( $_GET['course_filter'] ) && 'paid' == $_GET['course_filter']
215
-            && 'course' == $query->get( 'post_type') && $query->is_main_query() ){
214
+        if (isset($_GET['course_filter']) && 'paid' == $_GET['course_filter']
215
+            && 'course' == $query->get('post_type') && $query->is_main_query()) {
216 216
 
217 217
             // setup the course meta query
218 218
             $meta_query = self::get_paid_courses_meta_query_args();
219 219
 
220 220
             // manipulate the query to return free courses
221
-            $query->set('meta_query', $meta_query );
221
+            $query->set('meta_query', $meta_query);
222 222
 
223 223
         }
224 224
 
@@ -231,14 +231,14 @@  discard block
 block discarded – undo
231 231
      * single courses if woocommerce is active allowing purchase
232 232
      * information and actions to be hooked from WooCommerce.
233 233
      */
234
-    public static function do_single_course_wc_single_product_action(){
234
+    public static function do_single_course_wc_single_product_action() {
235 235
 
236 236
         /**
237 237
          * this hooks is documented within the WooCommerce plugin.
238 238
          */
239
-        if ( Sensei_WC::is_woocommerce_active() ) {
239
+        if (Sensei_WC::is_woocommerce_active()) {
240 240
 
241
-            do_action( 'woocommerce_before_single_product' );
241
+            do_action('woocommerce_before_single_product');
242 242
 
243 243
         } // End If Statement
244 244
 
@@ -259,23 +259,23 @@  discard block
 block discarded – undo
259 259
      * @param $user_id
260 260
      * @return bool
261 261
      */
262
-    public static function alter_can_user_view_lesson ( $can_user_view_lesson, $lesson_id, $user_id  ){
262
+    public static function alter_can_user_view_lesson($can_user_view_lesson, $lesson_id, $user_id) {
263 263
 
264 264
         // check if the course has a valid product attached to it
265 265
         // which the user should have purchased if they want to access
266 266
         // the current lesson
267
-        $course_id = get_post_meta( $lesson_id , '_lesson_course', true);
268
-        $wc_post_id = get_post_meta( $course_id, '_course_woocommerce_product', true );
267
+        $course_id = get_post_meta($lesson_id, '_lesson_course', true);
268
+        $wc_post_id = get_post_meta($course_id, '_course_woocommerce_product', true);
269 269
         $product = Sensei()->sensei_get_woocommerce_product_object($wc_post_id);
270
-        if( isset ($product) && is_object($product) ){
270
+        if (isset ($product) && is_object($product)) {
271 271
 
272 272
             // valid product found
273
-            $order_id = self::get_learner_course_active_order_id( $user_id, $course_id );
273
+            $order_id = self::get_learner_course_active_order_id($user_id, $course_id);
274 274
 
275 275
             // product has a successful order so this user may access the content
276 276
             // this function may only return false or the default
277 277
             // returning true may override other negatives which we don't want
278
-            if( ! $order_id ){
278
+            if ( ! $order_id) {
279 279
 
280 280
                 return false;
281 281
 
@@ -298,23 +298,23 @@  discard block
 block discarded – undo
298 298
      */
299 299
     public static function course_link_from_order( ) {
300 300
 
301
-        if( ! is_order_received_page() ){
301
+        if ( ! is_order_received_page()) {
302 302
             return;
303 303
         }
304 304
 
305
-        $order_id = get_query_var( 'order-received' );
306
-		$order = new WC_Order( $order_id );
305
+        $order_id = get_query_var('order-received');
306
+		$order = new WC_Order($order_id);
307 307
 
308 308
 		// exit early if not wc-completed or wc-processing
309
-		if( 'wc-completed' != $order->post_status
310
-            && 'wc-processing' != $order->post_status  ) {
309
+		if ('wc-completed' != $order->post_status
310
+            && 'wc-processing' != $order->post_status) {
311 311
             return;
312 312
         }
313 313
 
314 314
         $course_links = array(); // store the for links for courses purchased
315
-		foreach ( $order->get_items() as $item ) {
315
+		foreach ($order->get_items() as $item) {
316 316
 
317
-            if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
317
+            if (isset($item['variation_id']) && (0 < $item['variation_id'])) {
318 318
 
319 319
                 // If item has variation_id then its a variation of the product
320 320
                 $item_id = $item['variation_id'];
@@ -326,28 +326,28 @@  discard block
 block discarded – undo
326 326
 
327 327
             } // End If Statement
328 328
 
329
-            $user_id = get_post_meta( $order->id, '_customer_user', true );
329
+            $user_id = get_post_meta($order->id, '_customer_user', true);
330 330
 
331
-            if( $user_id ) {
331
+            if ($user_id) {
332 332
 
333 333
                 // Get all courses for product
334 334
                 $args = Sensei_Course::get_default_query_args();
335
-                $args['meta_query'] = array( array(
335
+                $args['meta_query'] = array(array(
336 336
                             'key' => '_course_woocommerce_product',
337 337
                             'value' => $item_id
338
-                        ) );
338
+                        ));
339 339
                 $args['orderby'] = 'menu_order date';
340 340
                 $args['order'] = 'ASC';
341 341
 
342 342
                 // loop through courses
343
-                $courses = get_posts( $args );
344
-                if( $courses && count( $courses ) > 0 ) {
343
+                $courses = get_posts($args);
344
+                if ($courses && count($courses) > 0) {
345 345
 
346
-                    foreach( $courses as $course ) {
346
+                    foreach ($courses as $course) {
347 347
 
348 348
                         $title = $course->post_title;
349
-                        $permalink = get_permalink( $course->ID );
350
-                        $course_links[] .= '<a href="' . esc_url( $permalink ) . '" >' . $title . '</a> ';
349
+                        $permalink = get_permalink($course->ID);
350
+                        $course_links[] .= '<a href="'.esc_url($permalink).'" >'.$title.'</a> ';
351 351
 
352 352
                     } // end for each
353 353
 
@@ -358,24 +358,24 @@  discard block
 block discarded – undo
358 358
         }// end loop through orders
359 359
 
360 360
         // add the courses to the WooCommerce notice
361
-        if( ! empty( $course_links) ){
361
+        if ( ! empty($course_links)) {
362 362
 
363 363
             $courses_html = _nx(
364 364
                 'You have purchased the following course:',
365 365
                 'You have purchased the following courses:',
366
-                count( $course_links ),
366
+                count($course_links),
367 367
                 'Purchase thank you note on Checkout page. The course link(s) will be show', 'woothemes-sensei'
368 368
             );
369 369
 
370
-            foreach( $course_links as $link ){
370
+            foreach ($course_links as $link) {
371 371
 
372
-                $courses_html .= '<li>' . $link . '</li>';
372
+                $courses_html .= '<li>'.$link.'</li>';
373 373
 
374 374
             }
375 375
 
376 376
             $courses_html .= ' </ul>';
377 377
 
378
-            wc_add_notice( $courses_html, 'success' );
378
+            wc_add_notice($courses_html, 'success');
379 379
         }
380 380
 
381 381
 	} // end course_link_order_form
@@ -388,20 +388,20 @@  discard block
 block discarded – undo
388 388
      *
389 389
      * @since 1.9.0
390 390
      */
391
-    public static function course_in_cart_message(){
391
+    public static function course_in_cart_message() {
392 392
 
393 393
         global $post;
394 394
 
395
-        if( self::is_course_in_cart( $post->ID ) ){ ?>
395
+        if (self::is_course_in_cart($post->ID)) { ?>
396 396
 
397 397
             <div class="sensei-message info">
398 398
                 <?php
399 399
 
400
-                $cart_link =  '<a class="cart-complete" href="' . WC()->cart->get_checkout_url()
401
-                              . '" title="' . __('complete purchase', 'woothemes-sensei') . '">'
402
-                              . __('complete the purchase', 'woothemes-sensei') . '</a>';
400
+                $cart_link = '<a class="cart-complete" href="'.WC()->cart->get_checkout_url()
401
+                              . '" title="'.__('complete purchase', 'woothemes-sensei').'">'
402
+                              . __('complete the purchase', 'woothemes-sensei').'</a>';
403 403
 
404
-                echo sprintf(  __('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei'), $cart_link );
404
+                echo sprintf(__('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei'), $cart_link);
405 405
 
406 406
                 ?>
407 407
             </div>
@@ -415,14 +415,14 @@  discard block
 block discarded – undo
415 415
      * @param $course_id
416 416
      * @return bool
417 417
      */
418
-    public static function is_course_in_cart( $course_id ){
418
+    public static function is_course_in_cart($course_id) {
419 419
 
420
-        $wc_post_id = absint( get_post_meta( $course_id, '_course_woocommerce_product', true ) );
421
-        $user_course_status_id = Sensei_Utils::user_started_course( $course_id , get_current_user_id() );
420
+        $wc_post_id = absint(get_post_meta($course_id, '_course_woocommerce_product', true));
421
+        $user_course_status_id = Sensei_Utils::user_started_course($course_id, get_current_user_id());
422 422
 
423
-        if ( 0 < intval( $wc_post_id ) && ! $user_course_status_id ) {
423
+        if (0 < intval($wc_post_id) && ! $user_course_status_id) {
424 424
 
425
-            if ( self::is_product_in_cart( $wc_post_id ) ) {
425
+            if (self::is_product_in_cart($wc_post_id)) {
426 426
 
427 427
                 return true;
428 428
 
@@ -440,20 +440,20 @@  discard block
 block discarded – undo
440 440
      * @param $product_id
441 441
      * @return bool
442 442
      */
443
-    public static function is_product_in_cart( $product_id ){
443
+    public static function is_product_in_cart($product_id) {
444 444
 
445
-        if ( 0 < $product_id ) {
445
+        if (0 < $product_id) {
446 446
 
447
-            $product = wc_get_product( $product_id );
447
+            $product = wc_get_product($product_id);
448 448
 
449 449
             $parent_id = '';
450
-            if( isset( $product->variation_id ) && 0 < intval( $product->variation_id ) ) {
450
+            if (isset($product->variation_id) && 0 < intval($product->variation_id)) {
451 451
                 $wc_product_id = $product->parent->id;
452 452
             }
453
-            foreach( WC()->cart->get_cart() as $cart_item_key => $values ) {
453
+            foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
454 454
 
455 455
                 $cart_product = $values['data'];
456
-                if( $product_id == $cart_product->id ) {
456
+                if ($product_id == $cart_product->id) {
457 457
 
458 458
                     return true;
459 459
 
@@ -475,9 +475,9 @@  discard block
 block discarded – undo
475 475
      *  @type int $wp_post_id
476 476
      * }
477 477
      */
478
-    public static function get_free_product_ids(){
478
+    public static function get_free_product_ids() {
479 479
 
480
-        return  get_posts( array(
480
+        return  get_posts(array(
481 481
             'post_type' => 'product',
482 482
             'posts_per_page' => '1000',
483 483
             'fields' => 'ids',
@@ -502,7 +502,7 @@  discard block
 block discarded – undo
502 502
      * @since 1.9.0
503 503
      * @return array $wp_meta_query_param
504 504
      */
505
-    public static function get_free_courses_meta_query_args(){
505
+    public static function get_free_courses_meta_query_args() {
506 506
 
507 507
         return array(
508 508
             'relation' => 'OR',
@@ -526,7 +526,7 @@  discard block
 block discarded – undo
526 526
      * @since 1.9.0
527 527
      * @return array $wp_query_meta_query_args_param
528 528
      */
529
-    public static function get_paid_courses_meta_query_args(){
529
+    public static function get_paid_courses_meta_query_args() {
530 530
 
531 531
         $paid_product_ids = self::get_paid_product_ids();
532 532
 
@@ -535,7 +535,7 @@  discard block
 block discarded – undo
535 535
                 'key'     => '_course_woocommerce_product',
536 536
                 // when empty we give a false post_id to ensure the caller doesn't get any courses for their
537 537
                 // query
538
-                'value' => empty( $paid_product_ids  )? '-1000' : $paid_product_ids,
538
+                'value' => empty($paid_product_ids) ? '-1000' : $paid_product_ids,
539 539
                 'compare' => 'IN',
540 540
             ),
541 541
         );
@@ -549,7 +549,7 @@  discard block
 block discarded – undo
549 549
      * @since 1.9.0
550 550
      * @return array $product_query_args
551 551
      */
552
-    public static function get_paid_products_on_sale_query_args(){
552
+    public static function get_paid_products_on_sale_query_args() {
553 553
 
554 554
         $args = array(
555 555
                    'post_type' 		=> 'product',
@@ -559,9 +559,9 @@  discard block
 block discarded – undo
559 559
                    'suppress_filters' 	=> 0
560 560
         );
561 561
 
562
-        $args[ 'fields' ]     = 'ids';
562
+        $args['fields']     = 'ids';
563 563
 
564
-        $args[ 'meta_query' ] = array(
564
+        $args['meta_query'] = array(
565 565
             'relation' => 'AND',
566 566
             array(
567 567
                 'key'=> '_regular_price',
@@ -588,7 +588,7 @@  discard block
 block discarded – undo
588 588
      *
589 589
      * @return array
590 590
      */
591
-    public static function get_paid_products_not_on_sale_query_args(){
591
+    public static function get_paid_products_not_on_sale_query_args() {
592 592
 
593 593
         $args = array(
594 594
             'post_type' 		=> 'product',
@@ -598,8 +598,8 @@  discard block
 block discarded – undo
598 598
             'suppress_filters' 	=> 0
599 599
         );
600 600
 
601
-        $args[ 'fields' ]     = 'ids';
602
-        $args[ 'meta_query' ] = array(
601
+        $args['fields']     = 'ids';
602
+        $args['meta_query'] = array(
603 603
             'relation' => 'AND',
604 604
             array(
605 605
                 'key'=> '_regular_price',
@@ -625,24 +625,24 @@  discard block
 block discarded – undo
625 625
      *
626 626
      * @return array $woocommerce_paid_product_ids
627 627
      */
628
-    public static function get_paid_product_ids(){
628
+    public static function get_paid_product_ids() {
629 629
 
630 630
         // get all the paid WooCommerce products that has regular
631 631
         // and sale price greater than 0
632 632
         // will be used later to check for course with the id as meta
633
-        $paid_product_ids_with_sale =  get_posts( self::get_paid_products_on_sale_query_args() );
633
+        $paid_product_ids_with_sale = get_posts(self::get_paid_products_on_sale_query_args());
634 634
 
635 635
         // get all the paid WooCommerce products that has regular price
636 636
         // greater than 0 without a sale price
637 637
         // will be used later to check for course with the id as meta
638
-        $paid_product_ids_without_sale = get_posts( self::get_paid_products_not_on_sale_query_args() );
638
+        $paid_product_ids_without_sale = get_posts(self::get_paid_products_not_on_sale_query_args());
639 639
 
640 640
         // combine products ID's with regular and sale price grater than zero and those without
641 641
         // sale but regular price greater than zero
642
-        $woocommerce_paid_product_ids = array_merge( $paid_product_ids_with_sale, $paid_product_ids_without_sale );
642
+        $woocommerce_paid_product_ids = array_merge($paid_product_ids_with_sale, $paid_product_ids_without_sale);
643 643
 
644 644
         // if
645
-        if( empty($woocommerce_paid_product_ids) ){
645
+        if (empty($woocommerce_paid_product_ids)) {
646 646
             return array( );
647 647
         }
648 648
         return $woocommerce_paid_product_ids;
@@ -661,20 +661,20 @@  discard block
 block discarded – undo
661 661
      *
662 662
      * @return array
663 663
      */
664
-    public static function get_free_courses(){
664
+    public static function get_free_courses() {
665 665
 
666 666
         $free_course_query_args = Sensei_Course::get_default_query_args();
667
-        $free_course_query_args[ 'meta_query' ] = self::get_free_courses_meta_query_args();
667
+        $free_course_query_args['meta_query'] = self::get_free_courses_meta_query_args();
668 668
 
669 669
         // don't show any paid courses
670 670
         $courses = self::get_paid_courses();
671 671
         $ids = array();
672
-        foreach( $courses as $course ){
672
+        foreach ($courses as $course) {
673 673
             $ids[] = $course->ID;
674 674
         }
675
-        $free_course_query_args[ 'post__not_in' ] =  $ids;
675
+        $free_course_query_args['post__not_in'] = $ids;
676 676
 
677
-        return get_posts( $free_course_query_args );
677
+        return get_posts($free_course_query_args);
678 678
 
679 679
     }
680 680
 
@@ -684,13 +684,13 @@  discard block
 block discarded – undo
684 684
      * @since 1.9.0
685 685
      * @return array
686 686
      */
687
-    public static function get_paid_courses(){
687
+    public static function get_paid_courses() {
688 688
 
689 689
         $paid_course_query_args = Sensei_Course::get_default_query_args();
690 690
 
691
-        $paid_course_query_args[ 'meta_query' ] = self::get_paid_courses_meta_query_args();
691
+        $paid_course_query_args['meta_query'] = self::get_paid_courses_meta_query_args();
692 692
 
693
-        return get_posts(  $paid_course_query_args );
693
+        return get_posts($paid_course_query_args);
694 694
     }
695 695
 
696 696
     /**
@@ -705,17 +705,17 @@  discard block
 block discarded – undo
705 705
      * @param int $course_id
706 706
      * @return string $html markup for the button or nothing if user not allowed to buy
707 707
      */
708
-    public static function the_add_to_cart_button_html( $course_id ){
708
+    public static function the_add_to_cart_button_html($course_id) {
709 709
 
710
-        if ( ! Sensei_Course::is_prerequisite_complete( $course_id )) {
710
+        if ( ! Sensei_Course::is_prerequisite_complete($course_id)) {
711 711
             return '';
712 712
         }
713 713
 
714
-        $wc_post_id = self::get_course_product_id( $course_id );
714
+        $wc_post_id = self::get_course_product_id($course_id);
715 715
 
716 716
         // Check if customer purchased the product
717
-        if ( self::has_customer_bought_product(  get_current_user_id(), $wc_post_id )
718
-            || empty( $wc_post_id ) ) {
717
+        if (self::has_customer_bought_product(get_current_user_id(), $wc_post_id)
718
+            || empty($wc_post_id)) {
719 719
 
720 720
             return '';
721 721
 
@@ -723,15 +723,15 @@  discard block
 block discarded – undo
723 723
 
724 724
         // based on simple.php in WC templates/single-product/add-to-cart/
725 725
         // Get the product
726
-        $product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id );
726
+        $product = Sensei()->sensei_get_woocommerce_product_object($wc_post_id);
727 727
 
728 728
         // do not show the button for invalid products, non purchasable products, out
729 729
         // of stock product or if course is already in cart
730
-        if ( ! isset ( $product )
731
-            || ! is_object( $product )
730
+        if ( ! isset ($product)
731
+            || ! is_object($product)
732 732
             || ! $product->is_purchasable()
733 733
             || ! $product->is_in_stock()
734
-            || self::is_course_in_cart( $wc_post_id ) ) {
734
+            || self::is_course_in_cart($wc_post_id)) {
735 735
 
736 736
             return '';
737 737
 
@@ -742,23 +742,23 @@  discard block
 block discarded – undo
742 742
         //
743 743
         ?>
744 744
 
745
-        <form action="<?php echo esc_url( $product->add_to_cart_url() ); ?>"
745
+        <form action="<?php echo esc_url($product->add_to_cart_url()); ?>"
746 746
               class="cart"
747 747
               method="post"
748 748
               enctype="multipart/form-data">
749 749
 
750
-            <input type="hidden" name="product_id" value="<?php echo esc_attr( $product->id ); ?>" />
750
+            <input type="hidden" name="product_id" value="<?php echo esc_attr($product->id); ?>" />
751 751
 
752 752
             <input type="hidden" name="quantity" value="1" />
753 753
 
754
-            <?php if ( isset( $product->variation_id ) && 0 < intval( $product->variation_id ) ) { ?>
754
+            <?php if (isset($product->variation_id) && 0 < intval($product->variation_id)) { ?>
755 755
 
756 756
                 <input type="hidden" name="variation_id" value="<?php echo $product->variation_id; ?>" />
757
-                <?php if( isset( $product->variation_data ) && is_array( $product->variation_data ) && count( $product->variation_data ) > 0 ) { ?>
757
+                <?php if (isset($product->variation_data) && is_array($product->variation_data) && count($product->variation_data) > 0) { ?>
758 758
 
759
-                    <?php foreach( $product->variation_data as $att => $val ) { ?>
759
+                    <?php foreach ($product->variation_data as $att => $val) { ?>
760 760
 
761
-                        <input type="hidden" name="<?php echo esc_attr( $att ); ?>" id="<?php echo esc_attr( str_replace( 'attribute_', '', $att ) ); ?>" value="<?php echo esc_attr( $val ); ?>" />
761
+                        <input type="hidden" name="<?php echo esc_attr($att); ?>" id="<?php echo esc_attr(str_replace('attribute_', '', $att)); ?>" value="<?php echo esc_attr($val); ?>" />
762 762
 
763 763
                     <?php } ?>
764 764
 
@@ -786,26 +786,26 @@  discard block
 block discarded – undo
786 786
      *
787 787
      * @return string $message
788 788
      */
789
-    public static function alter_no_permissions_message( $message, $post_id ){
789
+    public static function alter_no_permissions_message($message, $post_id) {
790 790
 
791
-        if( empty( $post_id ) || 'course'!=get_post_type( $post_id ) ){
791
+        if (empty($post_id) || 'course' != get_post_type($post_id)) {
792 792
             return  $message;
793 793
         }
794 794
 
795
-        $product_id = self::get_course_product_id( $post_id );
795
+        $product_id = self::get_course_product_id($post_id);
796 796
 
797
-        if( ! $product_id
798
-            || self::has_customer_bought_product( get_current_user_id(),$product_id ) ){
797
+        if ( ! $product_id
798
+            || self::has_customer_bought_product(get_current_user_id(), $product_id)) {
799 799
 
800 800
             return $message;
801 801
 
802 802
         }
803 803
 
804 804
         ob_start();
805
-        self::the_course_no_permissions_message( $post_id );
805
+        self::the_course_no_permissions_message($post_id);
806 806
         $woocommerce_course_no_permissions_message = ob_get_clean();
807 807
 
808
-        return $woocommerce_course_no_permissions_message ;
808
+        return $woocommerce_course_no_permissions_message;
809 809
 
810 810
     }
811 811
     /**
@@ -814,16 +814,16 @@  discard block
 block discarded – undo
814 814
      *
815 815
      * @since 1.9.0
816 816
      */
817
-    public static function the_course_no_permissions_message( $course_id ){
817
+    public static function the_course_no_permissions_message($course_id) {
818 818
 
819 819
         // login link
820
-        $my_courses_page_id = intval( Sensei()->settings->settings[ 'my_course_page' ] );
821
-        $login_link =  '<a href="' . esc_url( get_permalink( $my_courses_page_id ) ) . '">' . __( 'log in', 'woothemes-sensei' ) . '</a>';
820
+        $my_courses_page_id = intval(Sensei()->settings->settings['my_course_page']);
821
+        $login_link = '<a href="'.esc_url(get_permalink($my_courses_page_id)).'">'.__('log in', 'woothemes-sensei').'</a>';
822 822
 
823 823
         ?>
824 824
 
825 825
         <span class="add-to-cart-login">
826
-            <?php echo sprintf( __( 'Or %1$s to access your purchased courses', 'woothemes-sensei' ), $login_link ); ?>
826
+            <?php echo sprintf(__('Or %1$s to access your purchased courses', 'woothemes-sensei'), $login_link); ?>
827 827
         </span>
828 828
 
829 829
     <?php }
@@ -838,43 +838,43 @@  discard block
 block discarded – undo
838 838
      *
839 839
      * @return bool
840 840
      */
841
-    public static function has_customer_bought_product ( $user_id, $product_id ){
841
+    public static function has_customer_bought_product($user_id, $product_id) {
842 842
 
843
-        $orders = get_posts( array(
843
+        $orders = get_posts(array(
844 844
             'posts_per_page' => -1,
845 845
             'meta_key'    => '_customer_user',
846
-            'meta_value'  => intval( $user_id ),
846
+            'meta_value'  => intval($user_id),
847 847
             'post_type'   => 'shop_order',
848
-            'post_status' =>  array( 'wc-processing', 'wc-completed' ),
849
-        ) );
848
+            'post_status' =>  array('wc-processing', 'wc-completed'),
849
+        ));
850 850
 
851
-        foreach ( $orders as $order_id ) {
851
+        foreach ($orders as $order_id) {
852 852
 
853
-            $order = new WC_Order( $order_id->ID );
853
+            $order = new WC_Order($order_id->ID);
854 854
 
855
-            if ( $order->post_status != 'wc-completed' && $order->post_status != 'wc-processing' ) {
855
+            if ($order->post_status != 'wc-completed' && $order->post_status != 'wc-processing') {
856 856
 
857 857
                 continue;
858 858
             }
859 859
 
860
-            if ( ! ( 0 < sizeof( $order->get_items() ) ) ) {
860
+            if ( ! (0 < sizeof($order->get_items()))) {
861 861
 
862 862
                 continue;
863 863
 
864 864
             }
865 865
 
866
-            foreach( $order->get_items() as $item ) {
866
+            foreach ($order->get_items() as $item) {
867 867
 
868 868
                 // Check if user has bought product
869
-                if ( $item['product_id'] == $product_id || $item['variation_id'] == $product_id ) {
869
+                if ($item['product_id'] == $product_id || $item['variation_id'] == $product_id) {
870 870
 
871 871
                     // Check if user has an active subscription for product
872
-                    if( class_exists( 'WC_Subscriptions_Manager' ) ) {
873
-                        $sub_key = WC_Subscriptions_Manager::get_subscription_key( $order_id->ID, $product_id );
874
-                        if( $sub_key ) {
875
-                            $sub = WC_Subscriptions_Manager::get_subscription( $sub_key );
876
-                            if( $sub && isset( $sub['status'] ) ) {
877
-                                if( 'active' == $sub['status'] ) {
872
+                    if (class_exists('WC_Subscriptions_Manager')) {
873
+                        $sub_key = WC_Subscriptions_Manager::get_subscription_key($order_id->ID, $product_id);
874
+                        if ($sub_key) {
875
+                            $sub = WC_Subscriptions_Manager::get_subscription($sub_key);
876
+                            if ($sub && isset($sub['status'])) {
877
+                                if ('active' == $sub['status']) {
878 878
                                     return true;
879 879
                                 } else {
880 880
                                     return false;
@@ -903,11 +903,11 @@  discard block
 block discarded – undo
903 903
      * @return string $woocommerce_product_id or false if none exist
904 904
      *
905 905
      */
906
-    public static function get_course_product_id( $course_id ){
906
+    public static function get_course_product_id($course_id) {
907 907
 
908
-        $product_id =  get_post_meta( $course_id, '_course_woocommerce_product', true );
908
+        $product_id = get_post_meta($course_id, '_course_woocommerce_product', true);
909 909
 
910
-        if( empty( $product_id ) || 'product' != get_post_type( $product_id ) ){
910
+        if (empty($product_id) || 'product' != get_post_type($product_id)) {
911 911
             return false;
912 912
         }
913 913
 
@@ -921,11 +921,11 @@  discard block
 block discarded – undo
921 921
      * @param array $classes
922 922
      * @return array
923 923
      */
924
-    public static function add_woocommerce_body_class( $classes ){
924
+    public static function add_woocommerce_body_class($classes) {
925 925
 
926
-        if( ! in_array( 'woocommerce', $classes ) ){
926
+        if ( ! in_array('woocommerce', $classes)) {
927 927
 
928
-            $classes[] ='woocommerce';
928
+            $classes[] = 'woocommerce';
929 929
 
930 930
         }
931 931
 
Please login to merge, or discard this patch.
includes/class-sensei-course.php 2 patches
Indentation   +1414 added lines, -1414 removed lines patch added patch discarded remove patch
@@ -13,21 +13,21 @@  discard block
 block discarded – undo
13 13
  * @since 1.0.0
14 14
  */
15 15
 class Sensei_Course {
16
-    /**
17
-     * @var $token
18
-     */
16
+	/**
17
+	 * @var $token
18
+	 */
19 19
 	public $token;
20 20
 
21
-    /**
22
-     * @var array $meta_fields
23
-     */
21
+	/**
22
+	 * @var array $meta_fields
23
+	 */
24 24
 	public $meta_fields;
25 25
 
26
-    /**
27
-     * @var string|bool $my_courses_page reference to the sites
28
-     * my courses page, false if none was set
29
-     */
30
-    public  $my_courses_page;
26
+	/**
27
+	 * @var string|bool $my_courses_page reference to the sites
28
+	 * my courses page, false if none was set
29
+	 */
30
+	public  $my_courses_page;
31 31
 
32 32
 	/**
33 33
 	 * Constructor.
@@ -35,14 +35,14 @@  discard block
 block discarded – undo
35 35
 	 */
36 36
 	public function __construct () {
37 37
 
38
-        $this->token = 'course';
38
+		$this->token = 'course';
39 39
 
40 40
 		// Setup meta fields for this post type
41 41
 		$this->meta_fields = array( 'course_prerequisite', 'course_featured', 'course_video_embed', 'course_woocommerce_product' );
42 42
 		// Admin actions
43 43
 		if ( is_admin() ) {
44 44
 			// Metabox functions
45
-            add_action( 'add_meta_boxes', array( $this, 'meta_box_setup' ), 20 );
45
+			add_action( 'add_meta_boxes', array( $this, 'meta_box_setup' ), 20 );
46 46
 			add_action( 'save_post', array( $this, 'meta_box_save' ) );
47 47
 			// Custom Write Panel Columns
48 48
 			add_filter( 'manage_edit-course_columns', array( $this, 'add_column_headings' ), 10, 1 );
@@ -58,47 +58,47 @@  discard block
 block discarded – undo
58 58
 		// Update course completion upon grading of a quiz
59 59
 		add_action( 'sensei_user_quiz_grade', array( $this, 'update_status_after_quiz_submission' ), 10, 2 );
60 60
 
61
-        // show the progress bar ont he single course page
62
-        add_action( 'sensei_single_course_content_inside_before' , array( $this, 'the_progress_statement' ), 15 );
63
-        add_action( 'sensei_single_course_content_inside_before' , array( $this, 'the_progress_meter' ), 16 );
61
+		// show the progress bar ont he single course page
62
+		add_action( 'sensei_single_course_content_inside_before' , array( $this, 'the_progress_statement' ), 15 );
63
+		add_action( 'sensei_single_course_content_inside_before' , array( $this, 'the_progress_meter' ), 16 );
64 64
 
65
-        // provide an option to block all emails related to a selected course
66
-        add_filter( 'sensei_send_emails', array( $this, 'block_notification_emails' ) );
67
-        add_action( 'save_post', array( $this, 'save_course_notification_meta_box' ) );
65
+		// provide an option to block all emails related to a selected course
66
+		add_filter( 'sensei_send_emails', array( $this, 'block_notification_emails' ) );
67
+		add_action( 'save_post', array( $this, 'save_course_notification_meta_box' ) );
68 68
 
69
-        // preview lessons on the course content
70
-        add_action( 'sensei_course_content_inside_after',array( $this, 'the_course_free_lesson_preview' ) );
69
+		// preview lessons on the course content
70
+		add_action( 'sensei_course_content_inside_after',array( $this, 'the_course_free_lesson_preview' ) );
71 71
 
72
-        // the course meta
73
-        add_action('sensei_course_content_inside_before', array( $this, 'the_course_meta' ) );
72
+		// the course meta
73
+		add_action('sensei_course_content_inside_before', array( $this, 'the_course_meta' ) );
74 74
 
75
-        // backwards compatible template hooks
76
-        add_action('sensei_course_content_inside_before', array( $this, 'content_before_backwards_compatibility_hooks' ));
77
-        add_action('sensei_loop_course_before', array( $this,'loop_before_backwards_compatibility_hooks' ) );
75
+		// backwards compatible template hooks
76
+		add_action('sensei_course_content_inside_before', array( $this, 'content_before_backwards_compatibility_hooks' ));
77
+		add_action('sensei_loop_course_before', array( $this,'loop_before_backwards_compatibility_hooks' ) );
78 78
 
79
-        // add the user status on the course to the markup as a class
80
-        add_filter('post_class', array( __CLASS__ , 'add_course_user_status_class' ), 20, 3 );
79
+		// add the user status on the course to the markup as a class
80
+		add_filter('post_class', array( __CLASS__ , 'add_course_user_status_class' ), 20, 3 );
81 81
 
82
-        //filter the course query in Sensei specific instances
83
-        add_filter( 'pre_get_posts', array( __CLASS__, 'course_query_filter' ) );
82
+		//filter the course query in Sensei specific instances
83
+		add_filter( 'pre_get_posts', array( __CLASS__, 'course_query_filter' ) );
84 84
 
85
-        //attache the sorting to the course archive
86
-        add_action ( 'sensei_archive_before_course_loop' , array( 'Sensei_Course', 'course_archive_sorting' ) );
85
+		//attache the sorting to the course archive
86
+		add_action ( 'sensei_archive_before_course_loop' , array( 'Sensei_Course', 'course_archive_sorting' ) );
87 87
 
88
-        //attach the filter links to the course archive
89
-        add_action ( 'sensei_archive_before_course_loop' , array( 'Sensei_Course', 'course_archive_filters' ) );
88
+		//attach the filter links to the course archive
89
+		add_action ( 'sensei_archive_before_course_loop' , array( 'Sensei_Course', 'course_archive_filters' ) );
90 90
 
91
-        //filter the course query when featured filter is applied
92
-        add_filter( 'pre_get_posts',  array( __CLASS__, 'course_archive_featured_filter'));
91
+		//filter the course query when featured filter is applied
92
+		add_filter( 'pre_get_posts',  array( __CLASS__, 'course_archive_featured_filter'));
93 93
 
94
-        // handle the order by title post submission
95
-        add_filter( 'pre_get_posts',  array( __CLASS__, 'course_archive_order_by_title'));
94
+		// handle the order by title post submission
95
+		add_filter( 'pre_get_posts',  array( __CLASS__, 'course_archive_order_by_title'));
96 96
 
97
-        // ensure the course category page respects the manual order set for courses
98
-        add_filter( 'pre_get_posts',  array( __CLASS__, 'alter_course_category_order'));
97
+		// ensure the course category page respects the manual order set for courses
98
+		add_filter( 'pre_get_posts',  array( __CLASS__, 'alter_course_category_order'));
99 99
 
100
-        // flush rewrite rules when saving a course
101
-        add_action('save_post', array( 'Sensei_Course', 'flush_rewrite_rules' ) );
100
+		// flush rewrite rules when saving a course
101
+		add_action('save_post', array( 'Sensei_Course', 'flush_rewrite_rules' ) );
102 102
 
103 103
 	} // End __construct()
104 104
 
@@ -151,13 +151,13 @@  discard block
 block discarded – undo
151 151
 		add_meta_box( 'course-video', __( 'Course Video', 'woothemes-sensei' ), array( $this, 'course_video_meta_box_content' ), $this->token, 'normal', 'default' );
152 152
 		// Add Meta Box for Course Lessons
153 153
 		add_meta_box( 'course-lessons', __( 'Course Lessons', 'woothemes-sensei' ), array( $this, 'course_lessons_meta_box_content' ), $this->token, 'normal', 'default' );
154
-        // Add Meta Box to link to Manage Learners
155
-        add_meta_box( 'course-manage', __( 'Course Management', 'woothemes-sensei' ), array( $this, 'course_manage_meta_box_content' ), $this->token, 'side', 'default' );
156
-        // Remove "Custom Settings" meta box.
154
+		// Add Meta Box to link to Manage Learners
155
+		add_meta_box( 'course-manage', __( 'Course Management', 'woothemes-sensei' ), array( $this, 'course_manage_meta_box_content' ), $this->token, 'side', 'default' );
156
+		// Remove "Custom Settings" meta box.
157 157
 		remove_meta_box( 'woothemes-settings', $this->token, 'normal' );
158 158
 
159
-        // add Disable email notification box
160
-        add_meta_box( 'course-notifications', __( 'Course Notifications', 'woothemes-sensei' ), array( $this, 'course_notification_meta_box_content' ), 'course', 'normal', 'default' );
159
+		// add Disable email notification box
160
+		add_meta_box( 'course-notifications', __( 'Course Notifications', 'woothemes-sensei' ), array( $this, 'course_notification_meta_box_content' ), 'course', 'normal', 'default' );
161 161
 
162 162
 	} // End meta_box_setup()
163 163
 
@@ -175,10 +175,10 @@  discard block
 block discarded – undo
175 175
 		$post_args = array(	'post_type' 		=> array( 'product', 'product_variation' ),
176 176
 							'posts_per_page' 		=> -1,
177 177
 							'orderby'         	=> 'title',
178
-    						'order'           	=> 'DESC',
179
-    						'exclude' 			=> $post->ID,
180
-    						'post_status'		=> array( 'publish', 'private', 'draft' ),
181
-    						'tax_query'			=> array(
178
+							'order'           	=> 'DESC',
179
+							'exclude' 			=> $post->ID,
180
+							'post_status'		=> array( 'publish', 'private', 'draft' ),
181
+							'tax_query'			=> array(
182 182
 								array(
183 183
 									'taxonomy'	=> 'product_type',
184 184
 									'field'		=> 'slug',
@@ -206,21 +206,21 @@  discard block
 block discarded – undo
206 206
 						$product_object = get_product( $post_item->ID );
207 207
 						$parent_id = wp_get_post_parent_id( $post_item->ID );
208 208
 
209
-                        if( sensei_check_woocommerce_version( '2.1' ) ) {
209
+						if( sensei_check_woocommerce_version( '2.1' ) ) {
210 210
 							$formatted_variation = wc_get_formatted_variation( $product_object->variation_data, true );
211 211
 
212 212
 						} else {
213
-                            // fall back to pre wc 2.1
213
+							// fall back to pre wc 2.1
214 214
 							$formatted_variation = woocommerce_get_formatted_variation( $product_object->variation_data, true );
215 215
 
216 216
 						}
217 217
 
218
-                        $product_name = ucwords( $formatted_variation );
219
-                        if( empty( $product_name ) ){
218
+						$product_name = ucwords( $formatted_variation );
219
+						if( empty( $product_name ) ){
220 220
 
221
-                            $product_name = __( 'Variation #', 'woothemes-sensei' ) . $product_object->variation_id;
221
+							$product_name = __( 'Variation #', 'woothemes-sensei' ) . $product_object->variation_id;
222 222
 
223
-                        }
223
+						}
224 224
 
225 225
 					} else {
226 226
 
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
 
271 271
 			} else {
272 272
 
273
-                $html .= '<p>' . "\n";
273
+				$html .= '<p>' . "\n";
274 274
 					$html .= esc_html( __( 'No products exist yet.', 'woothemes-sensei' ) ) . "\n";
275 275
 				$html .= '</p>'."\n";
276 276
 
@@ -296,8 +296,8 @@  discard block
 block discarded – undo
296 296
 		$post_args = array(	'post_type' 		=> 'course',
297 297
 							'posts_per_page' 		=> -1,
298 298
 							'orderby'         	=> 'title',
299
-    						'order'           	=> 'DESC',
300
-    						'exclude' 			=> $post->ID,
299
+							'order'           	=> 'DESC',
300
+							'exclude' 			=> $post->ID,
301 301
 							'suppress_filters' 	=> 0
302 302
 							);
303 303
 		$posts_array = get_posts( $post_args );
@@ -338,7 +338,7 @@  discard block
 block discarded – undo
338 338
 
339 339
 		$checked = '';
340 340
 		if ( isset( $course_featured ) && ( '' != $course_featured ) ) {
341
-	 	    $checked = checked( 'featured', $course_featured, false );
341
+	 		$checked = checked( 'featured', $course_featured, false );
342 342
 	 	} // End If Statement
343 343
 
344 344
 	 	$html .= '<input type="checkbox" name="course_featured" value="featured" ' . $checked . '>&nbsp;' . __( 'Feature this course', 'woothemes-sensei' ) . '<br>';
@@ -433,8 +433,8 @@  discard block
 block discarded – undo
433 433
 			$new_meta_value = ( isset( $_POST[$post_key] ) ? sanitize_html_class( $_POST[$post_key] ) : '' );
434 434
 		} // End If Statement
435 435
 
436
-        // update field with the new value
437
-        return update_post_meta( $post_id, $meta_key, $new_meta_value );
436
+		// update field with the new value
437
+		return update_post_meta( $post_id, $meta_key, $new_meta_value );
438 438
 
439 439
 	} // End save_post_meta()
440 440
 
@@ -458,8 +458,8 @@  discard block
 block discarded – undo
458 458
 
459 459
 		$html = '';
460 460
 		$html .= '<input type="hidden" name="' . esc_attr( 'woo_' . $this->token . '_noonce' ) . '" id="'
461
-                 . esc_attr( 'woo_' . $this->token . '_noonce' )
462
-                 . '" value="' . esc_attr( wp_create_nonce( plugin_basename(__FILE__) ) ) . '" />';
461
+				 . esc_attr( 'woo_' . $this->token . '_noonce' )
462
+				 . '" value="' . esc_attr( wp_create_nonce( plugin_basename(__FILE__) ) ) . '" />';
463 463
 
464 464
 		if ( count( $posts_array ) > 0 ) {
465 465
 
@@ -480,8 +480,8 @@  discard block
 block discarded – undo
480 480
 			$html .= '<p>' . esc_html( __( 'No lessons exist yet for this course.', 'woothemes-sensei' ) ) . "\n";
481 481
 
482 482
 				$html .= '<a href="' . admin_url( 'post-new.php?post_type=lesson' . $course_id )
483
-                         . '" title="' . esc_attr( __( 'Add a Lesson', 'woothemes-sensei' ) ) . '">'
484
-                         . __( 'Please add some.', 'woothemes-sensei' ) . '</a>' . "\n";
483
+						 . '" title="' . esc_attr( __( 'Add a Lesson', 'woothemes-sensei' ) ) . '">'
484
+						 . __( 'Please add some.', 'woothemes-sensei' ) . '</a>' . "\n";
485 485
 
486 486
 			$html .= '</p>'."\n";
487 487
 		} // End If Statement
@@ -490,29 +490,29 @@  discard block
 block discarded – undo
490 490
 
491 491
 	} // End course_lessons_meta_box_content()
492 492
 
493
-    /**
494
-     * course_manage_meta_box_content function.
495
-     *
496
-     * @since 1.9.0
497
-     * @access public
498
-     * @return void
499
-     */
493
+	/**
494
+	 * course_manage_meta_box_content function.
495
+	 *
496
+	 * @since 1.9.0
497
+	 * @access public
498
+	 * @return void
499
+	 */
500 500
 
501
-    public function course_manage_meta_box_content () {
502
-        global $post;
501
+	public function course_manage_meta_box_content () {
502
+		global $post;
503 503
         
504
-        $manage_url = esc_url( add_query_arg( array( 'page' => 'sensei_learners', 'course_id' => $post->ID, 'view' => 'learners' ), admin_url( 'admin.php') ) );
504
+		$manage_url = esc_url( add_query_arg( array( 'page' => 'sensei_learners', 'course_id' => $post->ID, 'view' => 'learners' ), admin_url( 'admin.php') ) );
505 505
 
506
-        $grading_url = esc_url( add_query_arg( array( 'page' => 'sensei_grading', 'course_id' => $post->ID, 'view' => 'learners' ), admin_url( 'admin.php') ) );
506
+		$grading_url = esc_url( add_query_arg( array( 'page' => 'sensei_grading', 'course_id' => $post->ID, 'view' => 'learners' ), admin_url( 'admin.php') ) );
507 507
 
508 508
 
509
-        echo "<ul><li><a href='$manage_url'>".__("Manage Learners", 'woothemes-sensei')."</a></li>";
509
+		echo "<ul><li><a href='$manage_url'>".__("Manage Learners", 'woothemes-sensei')."</a></li>";
510 510
 
511
-        echo "<li><a href='$grading_url'>".__("Manage Grading", 'woothemes-sensei')."</a></li></ul>";
511
+		echo "<li><a href='$grading_url'>".__("Manage Grading", 'woothemes-sensei')."</a></li></ul>";
512 512
 
513 513
 
514 514
 
515
-    } // End course_manage_meta_box_content()
515
+	} // End course_manage_meta_box_content()
516 516
 
517 517
 	/**
518 518
 	 * Add column headings to the "lesson" post list screen.
@@ -653,92 +653,92 @@  discard block
 block discarded – undo
653 653
 			} // End If Statement
654 654
 		} // End If Statement
655 655
 
656
-        $stored_order = get_option( 'sensei_course_order', '' );
657
-        $order = 'ASC';
658
-        $orderby = 'menu_order';
659
-        if( empty( $stored_order ) ){
656
+		$stored_order = get_option( 'sensei_course_order', '' );
657
+		$order = 'ASC';
658
+		$orderby = 'menu_order';
659
+		if( empty( $stored_order ) ){
660 660
 
661
-            $order = 'DESC';
662
-            $orderby = 'date';
661
+			$order = 'DESC';
662
+			$orderby = 'date';
663 663
 
664
-        }
664
+		}
665 665
 
666 666
 		switch ($type) {
667 667
 
668 668
 			case 'usercourses':
669 669
 				$post_args = array(	'post_type' 		=> 'course',
670 670
 									'orderby'         	=> $orderby,
671
-    								'order'           	=> $order,
672
-    								'post_status'      	=> 'publish',
673
-    								'include'			=> $includes,
674
-    								'exclude'			=> $excludes,
675
-    								'suppress_filters' 	=> 0
671
+									'order'           	=> $order,
672
+									'post_status'      	=> 'publish',
673
+									'include'			=> $includes,
674
+									'exclude'			=> $excludes,
675
+									'suppress_filters' 	=> 0
676 676
 									);
677 677
 				break;
678 678
 			case 'freecourses':
679 679
 
680
-                $post_args = array(
681
-                    'post_type' 		=> 'course',
682
-                    'orderby'         	=> $orderby,
683
-                    'order'           	=> $order,
684
-                    'post_status'      	=> 'publish',
685
-                    'exclude'			=> $excludes,
686
-                    'suppress_filters' 	=> 0
687
-                );
688
-                // Sub Query to get all WooCommerce Products that have Zero price
689
-                $post_args['meta_query'] = Sensei_WC::get_free_courses_meta_query_args();
680
+				$post_args = array(
681
+					'post_type' 		=> 'course',
682
+					'orderby'         	=> $orderby,
683
+					'order'           	=> $order,
684
+					'post_status'      	=> 'publish',
685
+					'exclude'			=> $excludes,
686
+					'suppress_filters' 	=> 0
687
+				);
688
+				// Sub Query to get all WooCommerce Products that have Zero price
689
+				$post_args['meta_query'] = Sensei_WC::get_free_courses_meta_query_args();
690 690
 
691
-                break;
691
+				break;
692 692
 
693 693
 			case 'paidcourses':
694 694
 
695
-                $post_args = array(
696
-                    'post_type' 		=> 'course',
697
-                    'orderby'         	=> $orderby,
698
-                    'order'           	=> $order,
699
-                    'post_status'      	=> 'publish',
700
-                    'exclude'			=> $excludes,
701
-                    'suppress_filters' 	=> 0
702
-                );
695
+				$post_args = array(
696
+					'post_type' 		=> 'course',
697
+					'orderby'         	=> $orderby,
698
+					'order'           	=> $order,
699
+					'post_status'      	=> 'publish',
700
+					'exclude'			=> $excludes,
701
+					'suppress_filters' 	=> 0
702
+				);
703 703
 
704
-                // Sub Query to get all WooCommerce Products that have price greater than zero
705
-                $post_args['meta_query'] = Sensei_WC::get_paid_courses_meta_query_args();
704
+				// Sub Query to get all WooCommerce Products that have price greater than zero
705
+				$post_args['meta_query'] = Sensei_WC::get_paid_courses_meta_query_args();
706 706
 
707 707
 				break;
708 708
 
709 709
 			case 'featuredcourses':
710
-                $post_args = array(	'post_type' 		=> 'course',
711
-                                    'orderby'         	=> $orderby,
712
-                                    'order'           	=> $order,
713
-    								'post_status'      	=> 'publish',
714
-    								'meta_value' 		=> 'featured',
715
-    								'meta_key' 			=> '_course_featured',
716
-    								'meta_compare' 		=> '=',
717
-    								'exclude'			=> $excludes,
718
-    								'suppress_filters' 	=> 0
710
+				$post_args = array(	'post_type' 		=> 'course',
711
+									'orderby'         	=> $orderby,
712
+									'order'           	=> $order,
713
+									'post_status'      	=> 'publish',
714
+									'meta_value' 		=> 'featured',
715
+									'meta_key' 			=> '_course_featured',
716
+									'meta_compare' 		=> '=',
717
+									'exclude'			=> $excludes,
718
+									'suppress_filters' 	=> 0
719 719
 									);
720 720
 				break;
721 721
 			default:
722 722
 				$post_args = array(	'post_type' 		=> 'course',
723
-                                    'orderby'         	=> $orderby,
724
-                                    'order'           	=> $order,
725
-    								'post_status'      	=> 'publish',
726
-    								'exclude'			=> $excludes,
727
-    								'suppress_filters' 	=> 0
723
+									'orderby'         	=> $orderby,
724
+									'order'           	=> $order,
725
+									'post_status'      	=> 'publish',
726
+									'exclude'			=> $excludes,
727
+									'suppress_filters' 	=> 0
728 728
 									);
729 729
 				break;
730 730
 
731 731
 		}
732 732
 
733
-        $post_args['posts_per_page'] = $amount;
734
-        $paged = $wp_query->get( 'paged' );
735
-        $post_args['paged'] = empty( $paged) ? 1 : $paged;
733
+		$post_args['posts_per_page'] = $amount;
734
+		$paged = $wp_query->get( 'paged' );
735
+		$post_args['paged'] = empty( $paged) ? 1 : $paged;
736 736
 
737
-        if( 'newcourses' == $type ){
737
+		if( 'newcourses' == $type ){
738 738
 
739
-            $post_args[ 'orderby' ] = 'date';
740
-            $post_args[ 'order' ] = 'DESC';
741
-        }
739
+			$post_args[ 'orderby' ] = 'date';
740
+			$post_args[ 'order' ] = 'DESC';
741
+		}
742 742
 
743 743
 		return $post_args;
744 744
 	}
@@ -748,22 +748,22 @@  discard block
 block discarded – undo
748 748
 	 * course_image function.
749 749
 	 *
750 750
 	 * Outputs the courses image, or first image from a lesson within a course
751
-     *
752
-     * Will echo the image unless return true is specified.
751
+	 *
752
+	 * Will echo the image unless return true is specified.
753 753
 	 *
754 754
 	 * @access public
755 755
 	 * @param int | WP_Post $course_id (default: 0)
756 756
 	 * @param string $width (default: '100')
757 757
 	 * @param string $height (default: '100')
758
-     * @param bool $return default false
759
-     *
758
+	 * @param bool $return default false
759
+	 *
760 760
 	 * @return string | void
761 761
 	 */
762 762
 	public function course_image( $course_id = 0, $width = '100', $height = '100', $return = false ) {
763 763
 
764
-        if( is_a( $course_id, 'WP_Post' ) ){
765
-            $course_id = $course_id->ID;
766
-        }
764
+		if( is_a( $course_id, 'WP_Post' ) ){
765
+			$course_id = $course_id->ID;
766
+		}
767 767
 
768 768
 		$html = '';
769 769
 
@@ -820,7 +820,7 @@  discard block
 block discarded – undo
820 820
  				// Display Image Placeholder if none
821 821
 				if ( Sensei()->settings->get( 'placeholder_images_enable' ) ) {
822 822
 
823
-                    $img_url = apply_filters( 'sensei_course_placeholder_image_url', '<img src="http://placehold.it/' . $width . 'x' . $height . '" class="woo-image thumbnail alignleft" />' );
823
+					$img_url = apply_filters( 'sensei_course_placeholder_image_url', '<img src="http://placehold.it/' . $width . 'x' . $height . '" class="woo-image thumbnail alignleft" />' );
824 824
 
825 825
 				} // End If Statement
826 826
 
@@ -834,15 +834,15 @@  discard block
 block discarded – undo
834 834
 
835 835
 		} // End If Statement
836 836
 
837
-        if( $return ){
837
+		if( $return ){
838 838
 
839
-            return $html;
839
+			return $html;
840 840
 
841
-        }else{
841
+		}else{
842 842
 
843
-            echo $html;
843
+			echo $html;
844 844
 
845
-        }
845
+		}
846 846
 
847 847
 	} // End course_image()
848 848
 
@@ -886,9 +886,9 @@  discard block
 block discarded – undo
886 886
 	 */
887 887
 	public function course_lessons( $course_id = 0, $post_status = 'publish', $fields = 'all' ) {
888 888
 
889
-        if( is_a( $course_id, 'WP_Post' ) ){
890
-            $course_id = $course_id->ID;
891
-        }
889
+		if( is_a( $course_id, 'WP_Post' ) ){
890
+			$course_id = $course_id->ID;
891
+		}
892 892
 
893 893
 		$post_args = array(	'post_type'         => 'lesson',
894 894
 							'posts_per_page'       => -1,
@@ -904,67 +904,67 @@  discard block
 block discarded – undo
904 904
 							'suppress_filters'  => 0,
905 905
 							);
906 906
 		$query_results = new WP_Query( $post_args );
907
-        $lessons = $query_results->posts;
908
-
909
-        // re order the lessons. This could not be done via the OR meta query as there may be lessons
910
-        // with the course order for a different course and this should not be included. It could also not
911
-        // be done via the AND meta query as it excludes lesson that does not have the _order_$course_id but
912
-        // that have been added to the course.
913
-        if( count( $lessons) > 1  ){
914
-
915
-            foreach( $lessons as $lesson ){
916
-
917
-                $order = intval( get_post_meta( $lesson->ID, '_order_'. $course_id, true ) );
918
-                // for lessons with no order set it to be 10000 so that it show up at the end
919
-                $lesson->course_order = $order ? $order : 100000;
920
-            }
921
-
922
-            uasort( $lessons, array( $this, '_short_course_lessons_callback' )   );
923
-        }
924
-
925
-        /**
926
-         * Filter runs inside Sensei_Course::course_lessons function
927
-         *
928
-         * Returns all lessons for a given course
929
-         *
930
-         * @param array $lessons
931
-         * @param int $course_id
932
-         */
933
-        $lessons = apply_filters( 'sensei_course_get_lessons', $lessons, $course_id  );
934
-
935
-        //return the requested fields
936
-        // runs after the sensei_course_get_lessons filter so the filter always give an array of lesson
937
-        // objects
938
-        if( 'ids' == $fields ) {
939
-            $lesson_objects = $lessons;
940
-            $lessons = array();
941
-
942
-            foreach ($lesson_objects as $lesson) {
943
-                $lessons[] = $lesson->ID;
944
-            }
945
-        }
946
-
947
-        return $lessons;
907
+		$lessons = $query_results->posts;
908
+
909
+		// re order the lessons. This could not be done via the OR meta query as there may be lessons
910
+		// with the course order for a different course and this should not be included. It could also not
911
+		// be done via the AND meta query as it excludes lesson that does not have the _order_$course_id but
912
+		// that have been added to the course.
913
+		if( count( $lessons) > 1  ){
914
+
915
+			foreach( $lessons as $lesson ){
916
+
917
+				$order = intval( get_post_meta( $lesson->ID, '_order_'. $course_id, true ) );
918
+				// for lessons with no order set it to be 10000 so that it show up at the end
919
+				$lesson->course_order = $order ? $order : 100000;
920
+			}
921
+
922
+			uasort( $lessons, array( $this, '_short_course_lessons_callback' )   );
923
+		}
924
+
925
+		/**
926
+		 * Filter runs inside Sensei_Course::course_lessons function
927
+		 *
928
+		 * Returns all lessons for a given course
929
+		 *
930
+		 * @param array $lessons
931
+		 * @param int $course_id
932
+		 */
933
+		$lessons = apply_filters( 'sensei_course_get_lessons', $lessons, $course_id  );
934
+
935
+		//return the requested fields
936
+		// runs after the sensei_course_get_lessons filter so the filter always give an array of lesson
937
+		// objects
938
+		if( 'ids' == $fields ) {
939
+			$lesson_objects = $lessons;
940
+			$lessons = array();
941
+
942
+			foreach ($lesson_objects as $lesson) {
943
+				$lessons[] = $lesson->ID;
944
+			}
945
+		}
946
+
947
+		return $lessons;
948 948
 
949 949
 	} // End course_lessons()
950 950
 
951
-    /**
952
-     * Used for the uasort in $this->course_lessons()
953
-     * @since 1.8.0
954
-     * @access protected
955
-     *
956
-     * @param array $lesson_1
957
-     * @param array $lesson_2
958
-     * @return int
959
-     */
960
-    protected function _short_course_lessons_callback( $lesson_1, $lesson_2 ){
951
+	/**
952
+	 * Used for the uasort in $this->course_lessons()
953
+	 * @since 1.8.0
954
+	 * @access protected
955
+	 *
956
+	 * @param array $lesson_1
957
+	 * @param array $lesson_2
958
+	 * @return int
959
+	 */
960
+	protected function _short_course_lessons_callback( $lesson_1, $lesson_2 ){
961 961
 
962
-        if ( $lesson_1->course_order == $lesson_2->course_order ) {
963
-            return 0;
964
-        }
962
+		if ( $lesson_1->course_order == $lesson_2->course_order ) {
963
+			return 0;
964
+		}
965 965
 
966
-        return ($lesson_1->course_order < $lesson_2->course_order) ? -1 : 1;
967
-    }
966
+		return ($lesson_1->course_order < $lesson_2->course_order) ? -1 : 1;
967
+	}
968 968
 
969 969
 	/**
970 970
 	 * Fetch all quiz ids in a course
@@ -1027,15 +1027,15 @@  discard block
 block discarded – undo
1027 1027
 	 */
1028 1028
 	public function course_author_lesson_count( $author_id = 0, $course_id = 0 ) {
1029 1029
 
1030
-        $lesson_args = array(	'post_type' 		=> 'lesson',
1030
+		$lesson_args = array(	'post_type' 		=> 'lesson',
1031 1031
 								'posts_per_page' 		=> -1,
1032
-		    					'author'         	=> $author_id,
1033
-		    					'meta_key'        	=> '_lesson_course',
1034
-    							'meta_value'      	=> $course_id,
1035
-    	    					'post_status'      	=> 'publish',
1036
-    	    					'suppress_filters' 	=> 0,
1032
+								'author'         	=> $author_id,
1033
+								'meta_key'        	=> '_lesson_course',
1034
+								'meta_value'      	=> $course_id,
1035
+								'post_status'      	=> 'publish',
1036
+								'suppress_filters' 	=> 0,
1037 1037
 								'fields'            => 'ids', // less data to retrieve
1038
-		    				);
1038
+							);
1039 1039
 		$lessons_array = get_posts( $lesson_args );
1040 1040
 		$count = count( $lessons_array );
1041 1041
 		return $count;
@@ -1053,17 +1053,17 @@  discard block
 block discarded – undo
1053 1053
 
1054 1054
 		$lesson_args = array(	'post_type' 		=> 'lesson',
1055 1055
 								'posts_per_page' 		=> -1,
1056
-		    					'meta_key'        	=> '_lesson_course',
1057
-    							'meta_value'      	=> $course_id,
1058
-    	    					'post_status'      	=> 'publish',
1059
-    	    					'suppress_filters' 	=> 0,
1056
+								'meta_key'        	=> '_lesson_course',
1057
+								'meta_value'      	=> $course_id,
1058
+								'post_status'      	=> 'publish',
1059
+								'suppress_filters' 	=> 0,
1060 1060
 								'fields'            => 'ids', // less data to retrieve
1061
-		    				);
1061
+							);
1062 1062
 		$lessons_array = get_posts( $lesson_args );
1063 1063
 
1064
-        $count = count( $lessons_array );
1064
+		$count = count( $lessons_array );
1065 1065
 
1066
-        return $count;
1066
+		return $count;
1067 1067
 
1068 1068
 	} // End course_lesson_count()
1069 1069
 
@@ -1078,9 +1078,9 @@  discard block
 block discarded – undo
1078 1078
 
1079 1079
 		$lesson_args = array(	'post_type' 		=> 'lesson',
1080 1080
 								'posts_per_page' 		=> -1,
1081
-    	    					'post_status'      	=> 'publish',
1082
-    	    					'suppress_filters' 	=> 0,
1083
-    	    					'meta_query' => array(
1081
+								'post_status'      	=> 'publish',
1082
+								'suppress_filters' 	=> 0,
1083
+								'meta_query' => array(
1084 1084
 									array(
1085 1085
 										'key' => '_lesson_course',
1086 1086
 										'value' => $course_id
@@ -1091,12 +1091,12 @@  discard block
 block discarded – undo
1091 1091
 									)
1092 1092
 								),
1093 1093
 								'fields'            => 'ids', // less data to retrieve
1094
-		    				);
1094
+							);
1095 1095
 		$lessons_array = get_posts( $lesson_args );
1096 1096
 
1097 1097
 		$count = count( $lessons_array );
1098 1098
 
1099
-        return $count;
1099
+		return $count;
1100 1100
 
1101 1101
 	} // End course_lesson_count()
1102 1102
 
@@ -1115,8 +1115,8 @@  discard block
 block discarded – undo
1115 1115
 			$post_args = array(	'post_type' 		=> 'course',
1116 1116
 								'posts_per_page' 		=> -1,
1117 1117
 								'meta_key'        	=> '_course_woocommerce_product',
1118
-	    						'meta_value'      	=> $product_id,
1119
-	    						'post_status'       => 'publish',
1118
+								'meta_value'      	=> $product_id,
1119
+								'post_status'       => 'publish',
1120 1120
 								'suppress_filters' 	=> 0,
1121 1121
 								'orderby' 			=> 'menu_order date',
1122 1122
 								'order' 			=> 'ASC',
@@ -1157,9 +1157,9 @@  discard block
 block discarded – undo
1157 1157
 
1158 1158
 	/**
1159 1159
 	 * load_user_courses_content generates HTML for user's active & completed courses
1160
-     *
1161
-     * This function also ouputs the html so no need to echo the content.
1162
-     *
1160
+	 *
1161
+	 * This function also ouputs the html so no need to echo the content.
1162
+	 *
1163 1163
 	 * @since  1.4.0
1164 1164
 	 * @param  object  $user   Queried user object
1165 1165
 	 * @param  boolean $manage Whether the user has permission to manage the courses
@@ -1168,17 +1168,17 @@  discard block
 block discarded – undo
1168 1168
 	public function load_user_courses_content( $user = false ) {
1169 1169
 		global $course, $my_courses_page, $my_courses_section;
1170 1170
 
1171
-        if( ! isset( Sensei()->settings->settings[ 'learner_profile_show_courses' ] )
1172
-            || ! Sensei()->settings->settings[ 'learner_profile_show_courses' ] ) {
1171
+		if( ! isset( Sensei()->settings->settings[ 'learner_profile_show_courses' ] )
1172
+			|| ! Sensei()->settings->settings[ 'learner_profile_show_courses' ] ) {
1173 1173
 
1174
-            // do not show the content if the settings doesn't allow for it
1175
-            return;
1174
+			// do not show the content if the settings doesn't allow for it
1175
+			return;
1176 1176
 
1177
-        }
1177
+		}
1178 1178
 
1179
-        $manage = ( $user->ID == get_current_user_id() ) ? true : false;
1179
+		$manage = ( $user->ID == get_current_user_id() ) ? true : false;
1180 1180
 
1181
-        do_action( 'sensei_before_learner_course_content', $user );
1181
+		do_action( 'sensei_before_learner_course_content', $user );
1182 1182
 
1183 1183
 		// Build Output HTML
1184 1184
 		$complete_html = $active_html = '';
@@ -1193,7 +1193,7 @@  discard block
 block discarded – undo
1193 1193
 			// Logic for Active and Completed Courses
1194 1194
 			$per_page = 20;
1195 1195
 			if ( isset( Sensei()->settings->settings[ 'my_course_amount' ] )
1196
-                && ( 0 < absint( Sensei()->settings->settings[ 'my_course_amount' ] ) ) ) {
1196
+				&& ( 0 < absint( Sensei()->settings->settings[ 'my_course_amount' ] ) ) ) {
1197 1197
 
1198 1198
 				$per_page = absint( Sensei()->settings->settings[ 'my_course_amount' ] );
1199 1199
 
@@ -1239,111 +1239,111 @@  discard block
 block discarded – undo
1239 1239
 					}
1240 1240
 				}
1241 1241
 
1242
-			    // Get Course Categories
1243
-			    $category_output = get_the_term_list( $course_item->ID, 'course-category', '', ', ', '' );
1242
+				// Get Course Categories
1243
+				$category_output = get_the_term_list( $course_item->ID, 'course-category', '', ', ', '' );
1244 1244
 
1245
-                $active_html .= '<article class="' . esc_attr( join( ' ', get_post_class( array( 'course', 'post' ), $course_item->ID ) ) ) . '">';
1245
+				$active_html .= '<article class="' . esc_attr( join( ' ', get_post_class( array( 'course', 'post' ), $course_item->ID ) ) ) . '">';
1246 1246
 
1247
-                // Image
1248
-                $active_html .= Sensei()->course->course_image( absint( $course_item->ID ), '100','100', true );
1247
+				// Image
1248
+				$active_html .= Sensei()->course->course_image( absint( $course_item->ID ), '100','100', true );
1249 1249
 
1250
-                // Title
1251
-                $active_html .= '<header>';
1250
+				// Title
1251
+				$active_html .= '<header>';
1252 1252
 
1253
-                $active_html .= '<h2><a href="' . esc_url( get_permalink( absint( $course_item->ID ) ) ) . '" title="' . esc_attr( $course_item->post_title ) . '">' . esc_html( $course_item->post_title ) . '</a></h2>';
1253
+				$active_html .= '<h2><a href="' . esc_url( get_permalink( absint( $course_item->ID ) ) ) . '" title="' . esc_attr( $course_item->post_title ) . '">' . esc_html( $course_item->post_title ) . '</a></h2>';
1254 1254
 
1255
-                $active_html .= '</header>';
1255
+				$active_html .= '</header>';
1256 1256
 
1257
-                $active_html .= '<section class="entry">';
1257
+				$active_html .= '<section class="entry">';
1258 1258
 
1259
-                $active_html .= '<p class="sensei-course-meta">';
1259
+				$active_html .= '<p class="sensei-course-meta">';
1260 1260
 
1261
-                // Author
1262
-                $user_info = get_userdata( absint( $course_item->post_author ) );
1263
-                if ( isset( Sensei()->settings->settings[ 'course_author' ] )
1264
-                    && ( Sensei()->settings->settings[ 'course_author' ] ) ) {
1261
+				// Author
1262
+				$user_info = get_userdata( absint( $course_item->post_author ) );
1263
+				if ( isset( Sensei()->settings->settings[ 'course_author' ] )
1264
+					&& ( Sensei()->settings->settings[ 'course_author' ] ) ) {
1265 1265
 
1266
-                    $active_html .= '<span class="course-author">'
1267
-                        . __( 'by ', 'woothemes-sensei' )
1268
-                        . '<a href="' . esc_url( get_author_posts_url( absint( $course_item->post_author ) ) )
1269
-                        . '" title="' . esc_attr( $user_info->display_name ) . '">'
1270
-                        . esc_html( $user_info->display_name )
1271
-                        . '</a></span>';
1266
+					$active_html .= '<span class="course-author">'
1267
+						. __( 'by ', 'woothemes-sensei' )
1268
+						. '<a href="' . esc_url( get_author_posts_url( absint( $course_item->post_author ) ) )
1269
+						. '" title="' . esc_attr( $user_info->display_name ) . '">'
1270
+						. esc_html( $user_info->display_name )
1271
+						. '</a></span>';
1272 1272
 
1273
-                } // End If Statement
1273
+				} // End If Statement
1274 1274
 
1275
-                // Lesson count for this author
1276
-                $lesson_count = Sensei()->course->course_lesson_count( absint( $course_item->ID ) );
1277
-                // Handle Division by Zero
1278
-                if ( 0 == $lesson_count ) {
1275
+				// Lesson count for this author
1276
+				$lesson_count = Sensei()->course->course_lesson_count( absint( $course_item->ID ) );
1277
+				// Handle Division by Zero
1278
+				if ( 0 == $lesson_count ) {
1279 1279
 
1280
-                    $lesson_count = 1;
1280
+					$lesson_count = 1;
1281 1281
 
1282
-                } // End If Statement
1283
-                $active_html .= '<span class="course-lesson-count">' . $lesson_count . '&nbsp;' .  __( 'Lessons', 'woothemes-sensei' ) . '</span>';
1284
-                // Course Categories
1285
-                if ( '' != $category_output ) {
1282
+				} // End If Statement
1283
+				$active_html .= '<span class="course-lesson-count">' . $lesson_count . '&nbsp;' .  __( 'Lessons', 'woothemes-sensei' ) . '</span>';
1284
+				// Course Categories
1285
+				if ( '' != $category_output ) {
1286 1286
 
1287
-                    $active_html .= '<span class="course-category">' . sprintf( __( 'in %s', 'woothemes-sensei' ), $category_output ) . '</span>';
1287
+					$active_html .= '<span class="course-category">' . sprintf( __( 'in %s', 'woothemes-sensei' ), $category_output ) . '</span>';
1288 1288
 
1289
-                } // End If Statement
1290
-                $active_html .= '<span class="course-lesson-progress">' . sprintf( __( '%1$d of %2$d lessons completed', 'woothemes-sensei' ) , $lessons_completed, $lesson_count  ) . '</span>';
1289
+				} // End If Statement
1290
+				$active_html .= '<span class="course-lesson-progress">' . sprintf( __( '%1$d of %2$d lessons completed', 'woothemes-sensei' ) , $lessons_completed, $lesson_count  ) . '</span>';
1291 1291
 
1292
-                $active_html .= '</p>';
1292
+				$active_html .= '</p>';
1293 1293
 
1294
-                $active_html .= '<p class="course-excerpt">' . $course_item->post_excerpt . '</p>';
1294
+				$active_html .= '<p class="course-excerpt">' . $course_item->post_excerpt . '</p>';
1295 1295
 
1296 1296
 
1297 1297
 
1298
-                $progress_percentage = abs( round( ( doubleval( $lessons_completed ) * 100 ) / ( $lesson_count ), 0 ) );
1298
+				$progress_percentage = abs( round( ( doubleval( $lessons_completed ) * 100 ) / ( $lesson_count ), 0 ) );
1299 1299
 
1300
-                $active_html .= $this->get_progress_meter( $progress_percentage );
1300
+				$active_html .= $this->get_progress_meter( $progress_percentage );
1301 1301
 
1302
-                $active_html .= '</section>';
1302
+				$active_html .= '</section>';
1303 1303
 
1304
-                if( is_user_logged_in() ) {
1304
+				if( is_user_logged_in() ) {
1305 1305
 
1306
-                    $active_html .= '<section class="entry-actions">';
1306
+					$active_html .= '<section class="entry-actions">';
1307 1307
 
1308
-                    $active_html .= '<form method="POST" action="' . esc_url( remove_query_arg( array( 'active_page', 'completed_page' ) ) ) . '">';
1308
+					$active_html .= '<form method="POST" action="' . esc_url( remove_query_arg( array( 'active_page', 'completed_page' ) ) ) . '">';
1309 1309
 
1310
-                    $active_html .= '<input type="hidden" name="' . esc_attr( 'woothemes_sensei_complete_course_noonce' ) . '" id="' . esc_attr( 'woothemes_sensei_complete_course_noonce' ) . '" value="' . esc_attr( wp_create_nonce( 'woothemes_sensei_complete_course_noonce' ) ) . '" />';
1310
+					$active_html .= '<input type="hidden" name="' . esc_attr( 'woothemes_sensei_complete_course_noonce' ) . '" id="' . esc_attr( 'woothemes_sensei_complete_course_noonce' ) . '" value="' . esc_attr( wp_create_nonce( 'woothemes_sensei_complete_course_noonce' ) ) . '" />';
1311 1311
 
1312
-                    $active_html .= '<input type="hidden" name="course_complete_id" id="course-complete-id" value="' . esc_attr( absint( $course_item->ID ) ) . '" />';
1312
+					$active_html .= '<input type="hidden" name="course_complete_id" id="course-complete-id" value="' . esc_attr( absint( $course_item->ID ) ) . '" />';
1313 1313
 
1314
-                    if ( 0 < absint( count( $course_lessons ) ) && Sensei()->settings->settings['course_completion'] == 'complete' ) {
1314
+					if ( 0 < absint( count( $course_lessons ) ) && Sensei()->settings->settings['course_completion'] == 'complete' ) {
1315 1315
 
1316
-                        $active_html .= '<span><input name="course_complete" type="submit" class="course-complete" value="'
1317
-                            .  __( 'Mark as Complete', 'woothemes-sensei' ) . '"/> </span>';
1316
+						$active_html .= '<span><input name="course_complete" type="submit" class="course-complete" value="'
1317
+							.  __( 'Mark as Complete', 'woothemes-sensei' ) . '"/> </span>';
1318 1318
 
1319
-                    } // End If Statement
1319
+					} // End If Statement
1320 1320
 
1321
-                    $course_purchased = false;
1322
-                    if ( Sensei_WC::is_woocommerce_active() ) {
1321
+					$course_purchased = false;
1322
+					if ( Sensei_WC::is_woocommerce_active() ) {
1323 1323
 
1324
-                        // Get the product ID
1325
-                        $wc_post_id = get_post_meta( absint( $course_item->ID ), '_course_woocommerce_product', true );
1326
-                        if ( 0 < $wc_post_id ) {
1324
+						// Get the product ID
1325
+						$wc_post_id = get_post_meta( absint( $course_item->ID ), '_course_woocommerce_product', true );
1326
+						if ( 0 < $wc_post_id ) {
1327 1327
 
1328
-                            $course_purchased = Sensei_WC::has_customer_bought_product(  $user->ID, $wc_post_id );
1328
+							$course_purchased = Sensei_WC::has_customer_bought_product(  $user->ID, $wc_post_id );
1329 1329
 
1330
-                        } // End If Statement
1330
+						} // End If Statement
1331 1331
 
1332
-                    } // End If Statement
1332
+					} // End If Statement
1333 1333
 
1334
-                    if ( false == $course_purchased ) {
1334
+					if ( false == $course_purchased ) {
1335 1335
 
1336
-                        $active_html .= '<span><input name="course_complete" type="submit" class="course-delete" value="'
1337
-                            .  __( 'Delete Course', 'woothemes-sensei' ) . '"/></span>';
1336
+						$active_html .= '<span><input name="course_complete" type="submit" class="course-delete" value="'
1337
+							.  __( 'Delete Course', 'woothemes-sensei' ) . '"/></span>';
1338 1338
 
1339
-                    } // End If Statement
1339
+					} // End If Statement
1340 1340
 
1341
-                    $active_html .= '</form>';
1341
+					$active_html .= '</form>';
1342 1342
 
1343
-                    $active_html .= '</section>';
1344
-                }
1343
+					$active_html .= '</section>';
1344
+				}
1345 1345
 
1346
-                $active_html .= '</article>';
1346
+				$active_html .= '</article>';
1347 1347
 			}
1348 1348
 
1349 1349
 			// Active pagination
@@ -1383,49 +1383,49 @@  discard block
 block discarded – undo
1383 1383
 			foreach ( $completed_courses as $course_item ) {
1384 1384
 				$course = $course_item;
1385 1385
 
1386
-			    // Get Course Categories
1387
-			    $category_output = get_the_term_list( $course_item->ID, 'course-category', '', ', ', '' );
1386
+				// Get Course Categories
1387
+				$category_output = get_the_term_list( $course_item->ID, 'course-category', '', ', ', '' );
1388 1388
 
1389
-		    	$complete_html .= '<article class="' . join( ' ', get_post_class( array( 'course', 'post' ), $course_item->ID ) ) . '">';
1389
+				$complete_html .= '<article class="' . join( ' ', get_post_class( array( 'course', 'post' ), $course_item->ID ) ) . '">';
1390 1390
 
1391
-		    	    // Image
1392
-		    		$complete_html .= Sensei()->course->course_image( absint( $course_item->ID ),100, 100, true );
1391
+					// Image
1392
+					$complete_html .= Sensei()->course->course_image( absint( $course_item->ID ),100, 100, true );
1393 1393
 
1394
-		    		// Title
1395
-		    		$complete_html .= '<header>';
1394
+					// Title
1395
+					$complete_html .= '<header>';
1396 1396
 
1397
-		    		    $complete_html .= '<h2><a href="' . esc_url( get_permalink( absint( $course_item->ID ) ) ) . '" title="' . esc_attr( $course_item->post_title ) . '">' . esc_html( $course_item->post_title ) . '</a></h2>';
1397
+						$complete_html .= '<h2><a href="' . esc_url( get_permalink( absint( $course_item->ID ) ) ) . '" title="' . esc_attr( $course_item->post_title ) . '">' . esc_html( $course_item->post_title ) . '</a></h2>';
1398 1398
 
1399
-		    		$complete_html .= '</header>';
1399
+					$complete_html .= '</header>';
1400 1400
 
1401
-		    		$complete_html .= '<section class="entry">';
1401
+					$complete_html .= '<section class="entry">';
1402 1402
 
1403
-		    			$complete_html .= '<p class="sensei-course-meta">';
1403
+						$complete_html .= '<p class="sensei-course-meta">';
1404 1404
 
1405
-		    		    	// Author
1406
-		    		    	$user_info = get_userdata( absint( $course_item->post_author ) );
1407
-		    		    	if ( isset( Sensei()->settings->settings[ 'course_author' ] ) && ( Sensei()->settings->settings[ 'course_author' ] ) ) {
1408
-		    		    		$complete_html .= '<span class="course-author">' . __( 'by ', 'woothemes-sensei' ) . '<a href="' . esc_url( get_author_posts_url( absint( $course_item->post_author ) ) ) . '" title="' . esc_attr( $user_info->display_name ) . '">' . esc_html( $user_info->display_name ) . '</a></span>';
1409
-		    		    	} // End If Statement
1405
+							// Author
1406
+							$user_info = get_userdata( absint( $course_item->post_author ) );
1407
+							if ( isset( Sensei()->settings->settings[ 'course_author' ] ) && ( Sensei()->settings->settings[ 'course_author' ] ) ) {
1408
+								$complete_html .= '<span class="course-author">' . __( 'by ', 'woothemes-sensei' ) . '<a href="' . esc_url( get_author_posts_url( absint( $course_item->post_author ) ) ) . '" title="' . esc_attr( $user_info->display_name ) . '">' . esc_html( $user_info->display_name ) . '</a></span>';
1409
+							} // End If Statement
1410 1410
 
1411
-		    		    	// Lesson count for this author
1412
-		    		    	$complete_html .= '<span class="course-lesson-count">'
1413
-                                . Sensei()->course->course_lesson_count( absint( $course_item->ID ) )
1414
-                                . '&nbsp;' .  __( 'Lessons', 'woothemes-sensei' )
1415
-                                . '</span>';
1411
+							// Lesson count for this author
1412
+							$complete_html .= '<span class="course-lesson-count">'
1413
+								. Sensei()->course->course_lesson_count( absint( $course_item->ID ) )
1414
+								. '&nbsp;' .  __( 'Lessons', 'woothemes-sensei' )
1415
+								. '</span>';
1416 1416
 
1417
-		    		    	// Course Categories
1418
-		    		    	if ( '' != $category_output ) {
1417
+							// Course Categories
1418
+							if ( '' != $category_output ) {
1419 1419
 
1420
-		    		    		$complete_html .= '<span class="course-category">' . sprintf( __( 'in %s', 'woothemes-sensei' ), $category_output ) . '</span>';
1420
+								$complete_html .= '<span class="course-category">' . sprintf( __( 'in %s', 'woothemes-sensei' ), $category_output ) . '</span>';
1421 1421
 
1422
-		    		    	} // End If Statement
1422
+							} // End If Statement
1423 1423
 
1424 1424
 						$complete_html .= '</p>';
1425 1425
 
1426 1426
 						$complete_html .= '<p class="course-excerpt">' . $course_item->post_excerpt . '</p>';
1427 1427
 
1428
-                        $complete_html .= $this->get_progress_meter( 100 );
1428
+						$complete_html .= $this->get_progress_meter( 100 );
1429 1429
 
1430 1430
 						if( $manage ) {
1431 1431
 							$has_quizzes = Sensei()->course->course_quizzes( $course_item->ID, true );
@@ -1438,9 +1438,9 @@  discard block
 block discarded – undo
1438 1438
 								if( $has_quizzes ) {
1439 1439
 
1440 1440
 									$results_link = '<a class="button view-results" href="'
1441
-                                        . Sensei()->course_results->get_permalink( $course_item->ID )
1442
-                                        . '">' . __( 'View results', 'woothemes-sensei' )
1443
-                                        . '</a>';
1441
+										. Sensei()->course_results->get_permalink( $course_item->ID )
1442
+										. '">' . __( 'View results', 'woothemes-sensei' )
1443
+										. '</a>';
1444 1444
 								}
1445 1445
 								$complete_html .= apply_filters( 'sensei_results_links', $results_link );
1446 1446
 								$complete_html .= '</p>';
@@ -1448,9 +1448,9 @@  discard block
 block discarded – undo
1448 1448
 							}
1449 1449
 						}
1450 1450
 
1451
-		    		$complete_html .= '</section>';
1451
+					$complete_html .= '</section>';
1452 1452
 
1453
-		    	$complete_html .= '</article>';
1453
+				$complete_html .= '</article>';
1454 1454
 			}
1455 1455
 
1456 1456
 			// Active pagination
@@ -1525,16 +1525,16 @@  discard block
 block discarded – undo
1525 1525
 		    <?php do_action( 'sensei_before_active_user_courses' ); ?>
1526 1526
 
1527 1527
 		    <?php
1528
-            $course_page_url = Sensei_Course::get_courses_page_url();
1529
-            ?>
1528
+			$course_page_url = Sensei_Course::get_courses_page_url();
1529
+			?>
1530 1530
 
1531 1531
 		    <div id="active-courses">
1532 1532
 
1533 1533
 		    	<?php if ( '' != $active_html ) {
1534 1534
 
1535
-		    		echo $active_html;
1535
+					echo $active_html;
1536 1536
 
1537
-		    	} else { ?>
1537
+				} else { ?>
1538 1538
 
1539 1539
 		    		<div class="sensei-message info">
1540 1540
 
@@ -1560,9 +1560,9 @@  discard block
 block discarded – undo
1560 1560
 
1561 1561
 		    	<?php if ( '' != $complete_html ) {
1562 1562
 
1563
-		    		echo $complete_html;
1563
+					echo $complete_html;
1564 1564
 
1565
-		    	} else { ?>
1565
+				} else { ?>
1566 1566
 
1567 1567
 		    		<div class="sensei-message info">
1568 1568
 
@@ -1581,355 +1581,355 @@  discard block
 block discarded – undo
1581 1581
 		<?php do_action( 'sensei_after_user_courses' ); ?>
1582 1582
 
1583 1583
 		<?php
1584
-        echo ob_get_clean();
1584
+		echo ob_get_clean();
1585 1585
 
1586
-        do_action( 'sensei_after_learner_course_content', $user );
1586
+		do_action( 'sensei_after_learner_course_content', $user );
1587 1587
 
1588 1588
 	} // end load_user_courses_content
1589 1589
 
1590
-    /**
1591
-     * Returns a list of all courses
1592
-     *
1593
-     * @since 1.8.0
1594
-     * @return array $courses{
1595
-     *  @type $course WP_Post
1596
-     * }
1597
-     */
1598
-    public static function get_all_courses(){
1599
-
1600
-        $args = array(
1601
-               'post_type' => 'course',
1602
-                'posts_per_page' 		=> -1,
1603
-                'orderby'         	=> 'title',
1604
-                'order'           	=> 'ASC',
1605
-                'post_status'      	=> 'any',
1606
-                'suppress_filters' 	=> 0,
1607
-        );
1608
-
1609
-        $wp_query_obj =  new WP_Query( $args );
1610
-
1611
-        /**
1612
-         * sensei_get_all_courses filter
1613
-         *
1614
-         * This filter runs inside Sensei_Course::get_all_courses.
1615
-         *
1616
-         * @param array $courses{
1617
-         *  @type WP_Post
1618
-         * }
1619
-         * @param array $attributes
1620
-         */
1621
-        return apply_filters( 'sensei_get_all_courses' , $wp_query_obj->posts );
1622
-
1623
-    }// end get_all_courses
1624
-
1625
-    /**
1626
-     * Generate the course meter component
1627
-     *
1628
-     * @since 1.8.0
1629
-     * @param int $progress_percentage 0 - 100
1630
-     * @return string $progress_bar_html
1631
-     */
1632
-    public function get_progress_meter( $progress_percentage ){
1633
-
1634
-        if ( 50 < $progress_percentage ) {
1635
-            $class = ' green';
1636
-        } elseif ( 25 <= $progress_percentage && 50 >= $progress_percentage ) {
1637
-            $class = ' orange';
1638
-        } else {
1639
-            $class = ' red';
1640
-        }
1641
-        $progress_bar_html = '<div class="meter' . esc_attr( $class ) . '"><span style="width: ' . $progress_percentage . '%">' . round( $progress_percentage ) . '%</span></div>';
1642
-
1643
-        return $progress_bar_html;
1644
-
1645
-    }// end get_progress_meter
1646
-
1647
-    /**
1648
-     * Generate a statement that tells users
1649
-     * how far they are in the course.
1650
-     *
1651
-     * @param int $course_id
1652
-     * @param int $user_id
1653
-     *
1654
-     * @return string $statement_html
1655
-     */
1656
-    public function get_progress_statement( $course_id, $user_id ){
1657
-
1658
-        if( empty( $course_id ) || empty( $user_id )
1659
-        || ! Sensei_Utils::user_started_course( $course_id, $user_id ) ){
1660
-            return '';
1661
-        }
1662
-
1663
-        $completed = count( $this->get_completed_lesson_ids( $course_id, $user_id ) );
1664
-        $total_lessons = count( $this->course_lessons( $course_id ) );
1665
-
1666
-        $statement = sprintf( _n('Currently completed %s lesson of %s in total', 'Currently completed %s lessons of %s in total', $completed, 'woothemes-sensei'), $completed, $total_lessons );
1667
-
1668
-        /**
1669
-         * Filter the course completion statement.
1670
-         * Default Currently completed $var lesson($plural) of $var in total
1671
-         *
1672
-         * @param string $statement
1673
-         */
1674
-        return apply_filters( 'sensei_course_completion_statement', $statement );
1675
-
1676
-    }// end generate_progress_statement
1677
-
1678
-    /**
1679
-     * Output the course progress statement
1680
-     *
1681
-     * @param $course_id
1682
-     * @return void
1683
-     */
1684
-    public function the_progress_statement( $course_id = 0, $user_id = 0 ){
1685
-        if( empty( $course_id ) ){
1686
-            global $post;
1687
-            $course_id = $post->ID;
1688
-        }
1689
-
1690
-        if( empty( $user_id ) ){
1691
-            $user_id = get_current_user_id();
1692
-        }
1693
-
1694
-        echo '<span class="progress statement  course-completion-rate">' . $this->get_progress_statement( $course_id, $user_id  ) . '</span>';
1695
-    }
1696
-
1697
-    /**
1698
-     * Output the course progress bar
1699
-     *
1700
-     * @param $course_id
1701
-     * @return void
1702
-     */
1703
-    public function the_progress_meter( $course_id = 0, $user_id = 0 ){
1704
-
1705
-        if( empty( $course_id ) ){
1706
-            global $post;
1707
-            $course_id = $post->ID;
1708
-        }
1709
-
1710
-        if( empty( $user_id ) ){
1711
-            $user_id = get_current_user_id();
1712
-        }
1713
-
1714
-        if( 'course' != get_post_type( $course_id ) || ! get_userdata( $user_id )
1715
-            || ! Sensei_Utils::user_started_course( $course_id ,$user_id ) ){
1716
-            return;
1717
-        }
1718
-        $percentage_completed = $this->get_completion_percentage( $course_id, $user_id );
1719
-
1720
-        echo $this->get_progress_meter( $percentage_completed );
1721
-
1722
-    }// end the_progress_meter
1723
-
1724
-    /**
1725
-     * Checks how many lessons are completed
1726
-     *
1727
-     * @since 1.8.0
1728
-     *
1729
-     * @param int $course_id
1730
-     * @param int $user_id
1731
-     * @return array $completed_lesson_ids
1732
-     */
1733
-    public function get_completed_lesson_ids( $course_id, $user_id = 0 ){
1734
-
1735
-        if( !( intval( $user_id ) ) > 0 ){
1736
-            $user_id = get_current_user_id();
1737
-        }
1590
+	/**
1591
+	 * Returns a list of all courses
1592
+	 *
1593
+	 * @since 1.8.0
1594
+	 * @return array $courses{
1595
+	 *  @type $course WP_Post
1596
+	 * }
1597
+	 */
1598
+	public static function get_all_courses(){
1599
+
1600
+		$args = array(
1601
+			   'post_type' => 'course',
1602
+				'posts_per_page' 		=> -1,
1603
+				'orderby'         	=> 'title',
1604
+				'order'           	=> 'ASC',
1605
+				'post_status'      	=> 'any',
1606
+				'suppress_filters' 	=> 0,
1607
+		);
1608
+
1609
+		$wp_query_obj =  new WP_Query( $args );
1610
+
1611
+		/**
1612
+		 * sensei_get_all_courses filter
1613
+		 *
1614
+		 * This filter runs inside Sensei_Course::get_all_courses.
1615
+		 *
1616
+		 * @param array $courses{
1617
+		 *  @type WP_Post
1618
+		 * }
1619
+		 * @param array $attributes
1620
+		 */
1621
+		return apply_filters( 'sensei_get_all_courses' , $wp_query_obj->posts );
1622
+
1623
+	}// end get_all_courses
1624
+
1625
+	/**
1626
+	 * Generate the course meter component
1627
+	 *
1628
+	 * @since 1.8.0
1629
+	 * @param int $progress_percentage 0 - 100
1630
+	 * @return string $progress_bar_html
1631
+	 */
1632
+	public function get_progress_meter( $progress_percentage ){
1633
+
1634
+		if ( 50 < $progress_percentage ) {
1635
+			$class = ' green';
1636
+		} elseif ( 25 <= $progress_percentage && 50 >= $progress_percentage ) {
1637
+			$class = ' orange';
1638
+		} else {
1639
+			$class = ' red';
1640
+		}
1641
+		$progress_bar_html = '<div class="meter' . esc_attr( $class ) . '"><span style="width: ' . $progress_percentage . '%">' . round( $progress_percentage ) . '%</span></div>';
1642
+
1643
+		return $progress_bar_html;
1644
+
1645
+	}// end get_progress_meter
1646
+
1647
+	/**
1648
+	 * Generate a statement that tells users
1649
+	 * how far they are in the course.
1650
+	 *
1651
+	 * @param int $course_id
1652
+	 * @param int $user_id
1653
+	 *
1654
+	 * @return string $statement_html
1655
+	 */
1656
+	public function get_progress_statement( $course_id, $user_id ){
1657
+
1658
+		if( empty( $course_id ) || empty( $user_id )
1659
+		|| ! Sensei_Utils::user_started_course( $course_id, $user_id ) ){
1660
+			return '';
1661
+		}
1662
+
1663
+		$completed = count( $this->get_completed_lesson_ids( $course_id, $user_id ) );
1664
+		$total_lessons = count( $this->course_lessons( $course_id ) );
1665
+
1666
+		$statement = sprintf( _n('Currently completed %s lesson of %s in total', 'Currently completed %s lessons of %s in total', $completed, 'woothemes-sensei'), $completed, $total_lessons );
1667
+
1668
+		/**
1669
+		 * Filter the course completion statement.
1670
+		 * Default Currently completed $var lesson($plural) of $var in total
1671
+		 *
1672
+		 * @param string $statement
1673
+		 */
1674
+		return apply_filters( 'sensei_course_completion_statement', $statement );
1675
+
1676
+	}// end generate_progress_statement
1677
+
1678
+	/**
1679
+	 * Output the course progress statement
1680
+	 *
1681
+	 * @param $course_id
1682
+	 * @return void
1683
+	 */
1684
+	public function the_progress_statement( $course_id = 0, $user_id = 0 ){
1685
+		if( empty( $course_id ) ){
1686
+			global $post;
1687
+			$course_id = $post->ID;
1688
+		}
1689
+
1690
+		if( empty( $user_id ) ){
1691
+			$user_id = get_current_user_id();
1692
+		}
1693
+
1694
+		echo '<span class="progress statement  course-completion-rate">' . $this->get_progress_statement( $course_id, $user_id  ) . '</span>';
1695
+	}
1696
+
1697
+	/**
1698
+	 * Output the course progress bar
1699
+	 *
1700
+	 * @param $course_id
1701
+	 * @return void
1702
+	 */
1703
+	public function the_progress_meter( $course_id = 0, $user_id = 0 ){
1704
+
1705
+		if( empty( $course_id ) ){
1706
+			global $post;
1707
+			$course_id = $post->ID;
1708
+		}
1709
+
1710
+		if( empty( $user_id ) ){
1711
+			$user_id = get_current_user_id();
1712
+		}
1713
+
1714
+		if( 'course' != get_post_type( $course_id ) || ! get_userdata( $user_id )
1715
+			|| ! Sensei_Utils::user_started_course( $course_id ,$user_id ) ){
1716
+			return;
1717
+		}
1718
+		$percentage_completed = $this->get_completion_percentage( $course_id, $user_id );
1719
+
1720
+		echo $this->get_progress_meter( $percentage_completed );
1738 1721
 
1739
-        $completed_lesson_ids = array();
1722
+	}// end the_progress_meter
1740 1723
 
1741
-        $course_lessons = $this->course_lessons( $course_id );
1724
+	/**
1725
+	 * Checks how many lessons are completed
1726
+	 *
1727
+	 * @since 1.8.0
1728
+	 *
1729
+	 * @param int $course_id
1730
+	 * @param int $user_id
1731
+	 * @return array $completed_lesson_ids
1732
+	 */
1733
+	public function get_completed_lesson_ids( $course_id, $user_id = 0 ){
1734
+
1735
+		if( !( intval( $user_id ) ) > 0 ){
1736
+			$user_id = get_current_user_id();
1737
+		}
1738
+
1739
+		$completed_lesson_ids = array();
1740
+
1741
+		$course_lessons = $this->course_lessons( $course_id );
1742
+
1743
+		foreach( $course_lessons as $lesson ){
1744
+
1745
+			$is_lesson_completed = Sensei_Utils::user_completed_lesson( $lesson->ID, $user_id );
1746
+			if( $is_lesson_completed ){
1747
+				$completed_lesson_ids[] = $lesson->ID;
1748
+			}
1749
+
1750
+		}
1751
+
1752
+		return $completed_lesson_ids;
1753
+
1754
+	}// end get_completed_lesson_ids
1755
+
1756
+	/**
1757
+	 * Calculate the perceantage completed in the course
1758
+	 *
1759
+	 * @since 1.8.0
1760
+	 *
1761
+	 * @param int $course_id
1762
+	 * @param int $user_id
1763
+	 * @return int $percentage
1764
+	 */
1765
+	public function get_completion_percentage( $course_id, $user_id = 0 ){
1766
+
1767
+		if( !( intval( $user_id ) ) > 0 ){
1768
+			$user_id = get_current_user_id();
1769
+		}
1770
+
1771
+		$completed = count( $this->get_completed_lesson_ids( $course_id, $user_id ) );
1772
+
1773
+		if( ! (  $completed  > 0 ) ){
1774
+			return 0;
1775
+		}
1776
+
1777
+		$total_lessons = count( $this->course_lessons( $course_id ) );
1778
+		$percentage = $completed / $total_lessons * 100;
1779
+
1780
+		/**
1781
+		 *
1782
+		 * Filter the percentage returned for a users course.
1783
+		 *
1784
+		 * @param $percentage
1785
+		 * @param $course_id
1786
+		 * @param $user_id
1787
+		 * @since 1.8.0
1788
+		 */
1789
+		return apply_filters( 'sensei_course_completion_percentage', $percentage, $course_id, $user_id );
1790
+
1791
+	}// end get_completed_lesson_ids
1792
+
1793
+	/**
1794
+	 * Block email notifications for the specific courses
1795
+	 * that the user disabled the notifications.
1796
+	 *
1797
+	 * @since 1.8.0
1798
+	 * @param $should_send
1799
+	 * @return bool
1800
+	 */
1801
+	public function block_notification_emails( $should_send ){
1802
+		global $sensei_email_data;
1803
+		$email = $sensei_email_data;
1804
+
1805
+		$course_id = '';
1806
+
1807
+		if( isset( $email['course_id'] ) ){
1808
+
1809
+			$course_id = $email['course_id'];
1810
+
1811
+		}elseif( isset( $email['lesson_id'] ) ){
1812
+
1813
+			$course_id = Sensei()->lesson->get_course_id( $email['lesson_id'] );
1814
+
1815
+		}elseif( isset( $email['quiz_id'] ) ){
1816
+
1817
+			$lesson_id = Sensei()->quiz->get_lesson_id( $email['quiz_id'] );
1818
+			$course_id = Sensei()->lesson->get_course_id( $lesson_id );
1819
+
1820
+		}
1821
+
1822
+		if( !empty( $course_id ) && 'course'== get_post_type( $course_id ) ) {
1823
+
1824
+			$course_emails_disabled = get_post_meta($course_id, 'disable_notification', true);
1825
+
1826
+			if ($course_emails_disabled) {
1827
+
1828
+				return false;
1829
+
1830
+			}
1831
+
1832
+		}// end if
1833
+
1834
+		return $should_send;
1835
+	}// end block_notification_emails
1836
+
1837
+	/**
1838
+	 * Render the course notification setting meta box
1839
+	 *
1840
+	 * @since 1.8.0
1841
+	 * @param $course
1842
+	 */
1843
+	public function course_notification_meta_box_content( $course ){
1742 1844
 
1743
-        foreach( $course_lessons as $lesson ){
1845
+		$checked = get_post_meta( $course->ID , 'disable_notification', true );
1744 1846
 
1745
-            $is_lesson_completed = Sensei_Utils::user_completed_lesson( $lesson->ID, $user_id );
1746
-            if( $is_lesson_completed ){
1747
-                $completed_lesson_ids[] = $lesson->ID;
1748
-            }
1749
-
1750
-        }
1751
-
1752
-        return $completed_lesson_ids;
1847
+		// generate checked html
1848
+		$checked_html = '';
1849
+		if( $checked ){
1850
+			$checked_html = 'checked="checked"';
1851
+		}
1852
+		wp_nonce_field( 'update-course-notification-setting','_sensei_course_notification' );
1753 1853
 
1754
-    }// end get_completed_lesson_ids
1854
+		echo '<input id="disable_sensei_course_notification" '.$checked_html .' type="checkbox" name="disable_sensei_course_notification" >';
1855
+		echo '<label for="disable_sensei_course_notification">'.__('Disable notifications on this course ?', 'woothemes-sensei'). '</label>';
1755 1856
 
1756
-    /**
1757
-     * Calculate the perceantage completed in the course
1758
-     *
1759
-     * @since 1.8.0
1760
-     *
1761
-     * @param int $course_id
1762
-     * @param int $user_id
1763
-     * @return int $percentage
1764
-     */
1765
-    public function get_completion_percentage( $course_id, $user_id = 0 ){
1766
-
1767
-        if( !( intval( $user_id ) ) > 0 ){
1768
-            $user_id = get_current_user_id();
1769
-        }
1770
-
1771
-        $completed = count( $this->get_completed_lesson_ids( $course_id, $user_id ) );
1772
-
1773
-        if( ! (  $completed  > 0 ) ){
1774
-            return 0;
1775
-        }
1776
-
1777
-        $total_lessons = count( $this->course_lessons( $course_id ) );
1778
-        $percentage = $completed / $total_lessons * 100;
1779
-
1780
-        /**
1781
-         *
1782
-         * Filter the percentage returned for a users course.
1783
-         *
1784
-         * @param $percentage
1785
-         * @param $course_id
1786
-         * @param $user_id
1787
-         * @since 1.8.0
1788
-         */
1789
-        return apply_filters( 'sensei_course_completion_percentage', $percentage, $course_id, $user_id );
1857
+	}// end course_notification_meta_box_content
1790 1858
 
1791
-    }// end get_completed_lesson_ids
1859
+	/**
1860
+	 * Store the setting for the course notification setting.
1861
+	 *
1862
+	 * @hooked int save_post
1863
+	 * @since 1.8.0
1864
+	 *
1865
+	 * @param $course_id
1866
+	 */
1867
+	public function save_course_notification_meta_box( $course_id ){
1868
+
1869
+		if( !isset( $_POST['_sensei_course_notification']  )
1870
+			|| ! wp_verify_nonce( $_POST['_sensei_course_notification'], 'update-course-notification-setting' ) ){
1871
+			return;
1872
+		}
1792 1873
 
1793
-    /**
1794
-     * Block email notifications for the specific courses
1795
-     * that the user disabled the notifications.
1796
-     *
1797
-     * @since 1.8.0
1798
-     * @param $should_send
1799
-     * @return bool
1800
-     */
1801
-    public function block_notification_emails( $should_send ){
1802
-        global $sensei_email_data;
1803
-        $email = $sensei_email_data;
1874
+		if( isset( $_POST['disable_sensei_course_notification'] ) && 'on'== $_POST['disable_sensei_course_notification']  ) {
1875
+			$new_val = true;
1876
+		}else{
1877
+			$new_val = false;
1878
+		}
1804 1879
 
1805
-        $course_id = '';
1880
+	   update_post_meta( $course_id , 'disable_notification', $new_val );
1806 1881
 
1807
-        if( isset( $email['course_id'] ) ){
1882
+	}// end save notification meta box
1808 1883
 
1809
-            $course_id = $email['course_id'];
1810
-
1811
-        }elseif( isset( $email['lesson_id'] ) ){
1884
+	/**
1885
+	 * Backwards compatibility hooks added to ensure that
1886
+	 * plugins and other parts of sensei still works.
1887
+	 *
1888
+	 * This function hooks into `sensei_course_content_inside_before`
1889
+	 *
1890
+	 * @since 1.9
1891
+	 *
1892
+	 * @param WP_Post $post
1893
+	 */
1894
+	public function content_before_backwards_compatibility_hooks( $post ){
1812 1895
 
1813
-            $course_id = Sensei()->lesson->get_course_id( $email['lesson_id'] );
1896
+		sensei_do_deprecated_action( 'sensei_course_image','1.9.0','sensei_course_content_inside_before' );
1897
+		sensei_do_deprecated_action( 'sensei_course_archive_course_title','1.9.0','sensei_course_content_inside_before' );
1814 1898
 
1815
-        }elseif( isset( $email['quiz_id'] ) ){
1899
+	}
1816 1900
 
1817
-            $lesson_id = Sensei()->quiz->get_lesson_id( $email['quiz_id'] );
1818
-            $course_id = Sensei()->lesson->get_course_id( $lesson_id );
1901
+	/**
1902
+	 * Backwards compatibility hooks that should be hooked into sensei_loop_course_before
1903
+	 *
1904
+	 * hooked into 'sensei_loop_course_before'
1905
+	 *
1906
+	 * @since 1.9
1907
+	 *
1908
+	 * @global WP_Post $post
1909
+	 */
1910
+	public  function loop_before_backwards_compatibility_hooks( ){
1819 1911
 
1820
-        }
1912
+		global $post;
1913
+		sensei_do_deprecated_action( 'sensei_course_archive_header','1.9.0','sensei_course_content_inside_before', $post->post_type  );
1821 1914
 
1822
-        if( !empty( $course_id ) && 'course'== get_post_type( $course_id ) ) {
1823
-
1824
-            $course_emails_disabled = get_post_meta($course_id, 'disable_notification', true);
1825
-
1826
-            if ($course_emails_disabled) {
1827
-
1828
-                return false;
1829
-
1830
-            }
1831
-
1832
-        }// end if
1833
-
1834
-        return $should_send;
1835
-    }// end block_notification_emails
1836
-
1837
-    /**
1838
-     * Render the course notification setting meta box
1839
-     *
1840
-     * @since 1.8.0
1841
-     * @param $course
1842
-     */
1843
-    public function course_notification_meta_box_content( $course ){
1844
-
1845
-        $checked = get_post_meta( $course->ID , 'disable_notification', true );
1846
-
1847
-        // generate checked html
1848
-        $checked_html = '';
1849
-        if( $checked ){
1850
-            $checked_html = 'checked="checked"';
1851
-        }
1852
-        wp_nonce_field( 'update-course-notification-setting','_sensei_course_notification' );
1853
-
1854
-        echo '<input id="disable_sensei_course_notification" '.$checked_html .' type="checkbox" name="disable_sensei_course_notification" >';
1855
-        echo '<label for="disable_sensei_course_notification">'.__('Disable notifications on this course ?', 'woothemes-sensei'). '</label>';
1856
-
1857
-    }// end course_notification_meta_box_content
1858
-
1859
-    /**
1860
-     * Store the setting for the course notification setting.
1861
-     *
1862
-     * @hooked int save_post
1863
-     * @since 1.8.0
1864
-     *
1865
-     * @param $course_id
1866
-     */
1867
-    public function save_course_notification_meta_box( $course_id ){
1868
-
1869
-        if( !isset( $_POST['_sensei_course_notification']  )
1870
-            || ! wp_verify_nonce( $_POST['_sensei_course_notification'], 'update-course-notification-setting' ) ){
1871
-            return;
1872
-        }
1873
-
1874
-        if( isset( $_POST['disable_sensei_course_notification'] ) && 'on'== $_POST['disable_sensei_course_notification']  ) {
1875
-            $new_val = true;
1876
-        }else{
1877
-            $new_val = false;
1878
-        }
1879
-
1880
-       update_post_meta( $course_id , 'disable_notification', $new_val );
1881
-
1882
-    }// end save notification meta box
1883
-
1884
-    /**
1885
-     * Backwards compatibility hooks added to ensure that
1886
-     * plugins and other parts of sensei still works.
1887
-     *
1888
-     * This function hooks into `sensei_course_content_inside_before`
1889
-     *
1890
-     * @since 1.9
1891
-     *
1892
-     * @param WP_Post $post
1893
-     */
1894
-    public function content_before_backwards_compatibility_hooks( $post ){
1895
-
1896
-        sensei_do_deprecated_action( 'sensei_course_image','1.9.0','sensei_course_content_inside_before' );
1897
-        sensei_do_deprecated_action( 'sensei_course_archive_course_title','1.9.0','sensei_course_content_inside_before' );
1915
+	}
1898 1916
 
1899
-    }
1917
+	/**
1918
+	 * Output a link to view course. The button text is different depending on the amount of preview lesson available.
1919
+	 *
1920
+	 * hooked into 'sensei_course_content_inside_after'
1921
+	 *
1922
+	 * @since 1.9.0
1923
+	 *
1924
+	 * @param WP_Post $course
1925
+	 */
1926
+	public function the_course_free_lesson_preview( $course ){
1927
+		// Meta data
1928
+		$preview_lesson_count = intval( Sensei()->course->course_lesson_preview_count( $course->ID ) );
1929
+		$is_user_taking_course = Sensei_Utils::user_started_course( $course->ID, get_current_user_id() );
1900 1930
 
1901
-    /**
1902
-     * Backwards compatibility hooks that should be hooked into sensei_loop_course_before
1903
-     *
1904
-     * hooked into 'sensei_loop_course_before'
1905
-     *
1906
-     * @since 1.9
1907
-     *
1908
-     * @global WP_Post $post
1909
-     */
1910
-    public  function loop_before_backwards_compatibility_hooks( ){
1911
-
1912
-        global $post;
1913
-        sensei_do_deprecated_action( 'sensei_course_archive_header','1.9.0','sensei_course_content_inside_before', $post->post_type  );
1914
-
1915
-    }
1916
-
1917
-    /**
1918
-     * Output a link to view course. The button text is different depending on the amount of preview lesson available.
1919
-     *
1920
-     * hooked into 'sensei_course_content_inside_after'
1921
-     *
1922
-     * @since 1.9.0
1923
-     *
1924
-     * @param WP_Post $course
1925
-     */
1926
-    public function the_course_free_lesson_preview( $course ){
1927
-        // Meta data
1928
-        $preview_lesson_count = intval( Sensei()->course->course_lesson_preview_count( $course->ID ) );
1929
-        $is_user_taking_course = Sensei_Utils::user_started_course( $course->ID, get_current_user_id() );
1930
-
1931
-        if ( 0 < $preview_lesson_count && !$is_user_taking_course ) {
1932
-            ?>
1931
+		if ( 0 < $preview_lesson_count && !$is_user_taking_course ) {
1932
+			?>
1933 1933
             <p class="sensei-free-lessons">
1934 1934
                 <a href="<?php echo get_permalink(); ?>">
1935 1935
                     <?php _e( 'Preview this course', 'woothemes-sensei' ) ?>
@@ -1938,22 +1938,22 @@  discard block
 block discarded – undo
1938 1938
             </p>
1939 1939
 
1940 1940
         <?php
1941
-        }
1942
-    }
1941
+		}
1942
+	}
1943 1943
 
1944
-    /**
1945
-     * Add course mata to the course meta hook
1946
-     *
1947
-     * @since 1.9.0
1948
-     * @param WP_Post $course
1949
-     */
1950
-    public function the_course_meta( $course ){
1951
-        echo '<p class="sensei-course-meta">';
1944
+	/**
1945
+	 * Add course mata to the course meta hook
1946
+	 *
1947
+	 * @since 1.9.0
1948
+	 * @param WP_Post $course
1949
+	 */
1950
+	public function the_course_meta( $course ){
1951
+		echo '<p class="sensei-course-meta">';
1952 1952
 
1953
-        $category_output = get_the_term_list( $course->ID, 'course-category', '', ', ', '' );
1954
-        $author_display_name = get_the_author_meta( 'display_name', $course->post_author  );
1953
+		$category_output = get_the_term_list( $course->ID, 'course-category', '', ', ', '' );
1954
+		$author_display_name = get_the_author_meta( 'display_name', $course->post_author  );
1955 1955
 
1956
-        if ( isset( Sensei()->settings->settings[ 'course_author' ] ) && ( Sensei()->settings->settings[ 'course_author' ] ) ) {?>
1956
+		if ( isset( Sensei()->settings->settings[ 'course_author' ] ) && ( Sensei()->settings->settings[ 'course_author' ] ) ) {?>
1957 1957
 
1958 1958
             <span class="course-author"><?php _e( 'by ', 'woothemes-sensei' ); ?>
1959 1959
 
@@ -1971,62 +1971,62 @@  discard block
 block discarded – undo
1971 1971
 
1972 1972
         <?php } // End If Statement
1973 1973
 
1974
-        // number of completed lessons
1975
-        if( Sensei_Utils::user_started_course( $course->ID,  get_current_user_id() )
1976
-            || Sensei_Utils::user_completed_course( $course->ID,  get_current_user_id() )  ){
1974
+		// number of completed lessons
1975
+		if( Sensei_Utils::user_started_course( $course->ID,  get_current_user_id() )
1976
+			|| Sensei_Utils::user_completed_course( $course->ID,  get_current_user_id() )  ){
1977 1977
 
1978
-            $completed = count( $this->get_completed_lesson_ids( $course->ID, get_current_user_id() ) );
1979
-            $lesson_count = count( $this->course_lessons( $course->ID ) );
1980
-            echo '<span class="course-lesson-progress">' . sprintf( __( '%1$d of %2$d lessons completed', 'woothemes-sensei' ) , $completed, $lesson_count  ) . '</span>';
1978
+			$completed = count( $this->get_completed_lesson_ids( $course->ID, get_current_user_id() ) );
1979
+			$lesson_count = count( $this->course_lessons( $course->ID ) );
1980
+			echo '<span class="course-lesson-progress">' . sprintf( __( '%1$d of %2$d lessons completed', 'woothemes-sensei' ) , $completed, $lesson_count  ) . '</span>';
1981 1981
 
1982
-        }
1982
+		}
1983 1983
 
1984
-        sensei_simple_course_price( $course->ID );
1984
+		sensei_simple_course_price( $course->ID );
1985 1985
 
1986
-        echo '</p>';
1987
-    } // end the course meta
1986
+		echo '</p>';
1987
+	} // end the course meta
1988 1988
 
1989
-    /**
1990
-     * Filter the classes attached to a post types for courses
1991
-     * and add a status class for when the user is logged in.
1992
-     *
1993
-     * @param $classes
1994
-     * @param $class
1995
-     * @param $post_id
1996
-     *
1997
-     * @return array $classes
1998
-     */
1999
-    public static function add_course_user_status_class( $classes, $class, $course_id ){
1989
+	/**
1990
+	 * Filter the classes attached to a post types for courses
1991
+	 * and add a status class for when the user is logged in.
1992
+	 *
1993
+	 * @param $classes
1994
+	 * @param $class
1995
+	 * @param $post_id
1996
+	 *
1997
+	 * @return array $classes
1998
+	 */
1999
+	public static function add_course_user_status_class( $classes, $class, $course_id ){
2000 2000
 
2001
-        if( 'course' == get_post_type( $course_id )  &&  is_user_logged_in() ){
2001
+		if( 'course' == get_post_type( $course_id )  &&  is_user_logged_in() ){
2002 2002
 
2003
-            if( Sensei_Utils::user_completed_course( $course_id, get_current_user_id() ) ){
2003
+			if( Sensei_Utils::user_completed_course( $course_id, get_current_user_id() ) ){
2004 2004
 
2005
-                $classes[] = 'user-status-completed';
2005
+				$classes[] = 'user-status-completed';
2006 2006
 
2007
-            }else{
2007
+			}else{
2008 2008
 
2009
-                $classes[] = 'user-status-active';
2009
+				$classes[] = 'user-status-active';
2010 2010
 
2011
-            }
2011
+			}
2012 2012
 
2013
-        }
2013
+		}
2014 2014
 
2015
-        return $classes;
2015
+		return $classes;
2016 2016
 
2017
-    }// end add_course_user_status_class
2017
+	}// end add_course_user_status_class
2018 2018
 
2019
-    /**
2020
-     * Prints out the course action buttons links
2021
-     *
2022
-     * - complete course
2023
-     * - delete course
2024
-     *
2025
-     * @param WP_Post $course
2026
-     */
2027
-    public static function the_course_action_buttons( $course ){
2019
+	/**
2020
+	 * Prints out the course action buttons links
2021
+	 *
2022
+	 * - complete course
2023
+	 * - delete course
2024
+	 *
2025
+	 * @param WP_Post $course
2026
+	 */
2027
+	public static function the_course_action_buttons( $course ){
2028 2028
 
2029
-        if( is_user_logged_in() ) { ?>
2029
+		if( is_user_logged_in() ) { ?>
2030 2030
 
2031 2031
             <section class="entry-actions">
2032 2032
                 <form method="POST" action="<?php  echo esc_url( remove_query_arg( array( 'active_page', 'completed_page' ) ) ); ?>">
@@ -2045,32 +2045,32 @@  discard block
 block discarded – undo
2045 2045
 
2046 2046
                    <?php  } // End If Statement
2047 2047
 
2048
-                    $course_purchased = false;
2049
-                    if ( Sensei_WC::is_woocommerce_active() ) {
2050
-                        // Get the product ID
2051
-                        $wc_post_id = get_post_meta( intval( $course->ID ), '_course_woocommerce_product', true );
2052
-                        if ( 0 < $wc_post_id ) {
2048
+					$course_purchased = false;
2049
+					if ( Sensei_WC::is_woocommerce_active() ) {
2050
+						// Get the product ID
2051
+						$wc_post_id = get_post_meta( intval( $course->ID ), '_course_woocommerce_product', true );
2052
+						if ( 0 < $wc_post_id ) {
2053 2053
 
2054
-                            $user = wp_get_current_user();
2055
-                            $course_purchased = Sensei_Utils::sensei_customer_bought_product( $user->user_email, $user->ID, $wc_post_id );
2054
+							$user = wp_get_current_user();
2055
+							$course_purchased = Sensei_Utils::sensei_customer_bought_product( $user->user_email, $user->ID, $wc_post_id );
2056 2056
 
2057
-                        } // End If Statement
2058
-                    } // End If Statement
2057
+						} // End If Statement
2058
+					} // End If Statement
2059 2059
 
2060
-                    if ( ! $course_purchased && ! Sensei_Utils::user_completed_course( $course->ID, get_current_user_id() ) ) {?>
2060
+					if ( ! $course_purchased && ! Sensei_Utils::user_completed_course( $course->ID, get_current_user_id() ) ) {?>
2061 2061
 
2062 2062
                         <span><input name="course_complete" type="submit" class="course-delete" value="<?php echo __( 'Delete Course', 'woothemes-sensei' ); ?>"/></span>
2063 2063
 
2064 2064
                     <?php } // End If Statement
2065 2065
 
2066
-                    $has_quizzes = Sensei()->course->course_quizzes( $course->ID, true );
2067
-                    $results_link = '';
2068
-                    if( $has_quizzes ){
2069
-                        $results_link = '<a class="button view-results" href="' . Sensei()->course_results->get_permalink( $course->ID ) . '">' . __( 'View results', 'woothemes-sensei' ) . '</a>';
2070
-                    }
2066
+					$has_quizzes = Sensei()->course->course_quizzes( $course->ID, true );
2067
+					$results_link = '';
2068
+					if( $has_quizzes ){
2069
+						$results_link = '<a class="button view-results" href="' . Sensei()->course_results->get_permalink( $course->ID ) . '">' . __( 'View results', 'woothemes-sensei' ) . '</a>';
2070
+					}
2071 2071
 
2072
-                    // Output only if there is content to display
2073
-                    if ( has_filter( 'sensei_results_links' ) || $has_quizzes ) { ?>
2072
+					// Output only if there is content to display
2073
+					if ( has_filter( 'sensei_results_links' ) || $has_quizzes ) { ?>
2074 2074
 
2075 2075
                         <p class="sensei-results-links">
2076 2076
                             <?php echo apply_filters( 'sensei_results_links', $results_link ); ?>
@@ -2082,456 +2082,456 @@  discard block
 block discarded – undo
2082 2082
 
2083 2083
         <?php  }// end if is user logged in
2084 2084
 
2085
-    }// end the_course_action_buttons
2086
-
2087
-    /**
2088
-     * This function alter the main query on the course archive page.
2089
-     * This also gives Sensei specific filters that allows variables to be altered specifically on the course archive.
2090
-     *
2091
-     * This function targets only the course archives and the my courses page. Shortcodes can set their own
2092
-     * query parameters via the arguments.
2093
-     *
2094
-     * This function is hooked into pre_get_posts filter
2095
-     *
2096
-     * @since 1.9.0
2097
-     *
2098
-     * @param WP_Query $query
2099
-     * @return WP_Query $query
2100
-     */
2101
-    public static function course_query_filter( $query ){
2102
-
2103
-        // exit early for no course queries and admin queries
2104
-        if( is_admin( ) || 'course' != $query->get( 'post_type' ) ){
2105
-            return $query;
2106
-        }
2107
-
2108
-        global $post; // used to get the current page id for my courses
2109
-
2110
-        // for the course archive page
2111
-        if( $query->is_main_query() && is_post_type_archive('course') )
2112
-        {
2113
-            /**
2114
-             * sensei_archive_courses_per_page
2115
-             *
2116
-             * Sensei courses per page on the course
2117
-             * archive
2118
-             *
2119
-             * @since 1.9.0
2120
-             * @param integer $posts_per_page default 10
2121
-             */
2122
-            $query->set( 'posts_per_page', apply_filters( 'sensei_archive_courses_per_page', 10 ) );
2123
-
2124
-        }
2125
-        // for the my courses page
2126
-        elseif( is_page() && Sensei()->settings->get( 'my_course_page' ) == $post->ID  )
2127
-        {
2128
-            /**
2129
-             * sensei_my_courses_per_page
2130
-             *
2131
-             * Sensei courses per page on the my courses page
2132
-             * as set in the settings
2133
-             *
2134
-             * @since 1.9.0
2135
-             * @param integer $posts_per_page default 10
2136
-             */
2137
-            $query->set( 'posts_per_page', apply_filters( 'sensei_my_courses_per_page', 10 ) );
2138
-
2139
-        }
2140
-
2141
-        return $query;
2142
-
2143
-    }// end course_query_filter
2144
-
2145
-    /**
2146
-     * Determine the class of the course loop
2147
-     *
2148
-     * This will output .first or .last and .course-item-number-x
2149
-     *
2150
-     * @return array $extra_classes
2151
-     * @since 1.9.0
2152
-     */
2153
-    public static function get_course_loop_content_class ()
2154
-    {
2155
-
2156
-        global $sensei_course_loop;
2157
-
2158
-
2159
-        if( !isset( $sensei_course_loop ) ){
2160
-            $sensei_course_loop = array();
2161
-        }
2162
-
2163
-        if (!isset($sensei_course_loop['counter'])) {
2164
-            $sensei_course_loop['counter'] = 0;
2165
-        }
2166
-
2167
-        if (!isset($sensei_course_loop['columns'])) {
2168
-            $sensei_course_loop['columns'] = self::get_loop_number_of_columns();
2169
-        }
2170
-
2171
-        // increment the counter
2172
-        $sensei_course_loop['counter']++;
2173
-
2174
-        $extra_classes = array();
2175
-        if( 0 == ( $sensei_course_loop['counter'] - 1 ) % $sensei_course_loop['columns'] || 1 == $sensei_course_loop['columns']  ){
2176
-            $extra_classes[] = 'first';
2177
-        }
2178
-
2179
-        if( 0 == $sensei_course_loop['counter'] % $sensei_course_loop['columns']  ){
2180
-            $extra_classes[] = 'last';
2181
-        }
2182
-
2183
-        // add the item number to the classes as well.
2184
-        $extra_classes[] = 'loop-item-number-'. $sensei_course_loop['counter'];
2185
-
2186
-        /**
2187
-         * Filter the course loop class the fires in the  in get_course_loop_content_class function
2188
-         * which is called from the course loop content-course.php
2189
-         *
2190
-         * @since 1.9.0
2191
-         *
2192
-         * @param array $extra_classes
2193
-         * @param WP_Post $loop_current_course
2194
-         */
2195
-        return apply_filters( 'sensei_course_loop_content_class', $extra_classes ,get_post() );
2196
-
2197
-    }// end get_course_loop_class
2198
-
2199
-    /**
2200
-     * Get the number of columns set for Sensei courses
2201
-     *
2202
-     * @since 1.9.0
2203
-     * @return mixed|void
2204
-     */
2205
-    public static function get_loop_number_of_columns(){
2206
-
2207
-        /**
2208
-         * Filter the number of columns on the course archive page.
2209
-         *
2210
-         * @since 1.9.0
2211
-         * @param int $number_of_columns default 1
2212
-         */
2213
-        return apply_filters('sensei_course_loop_number_of_columns', 1);
2214
-
2215
-    }
2216
-
2217
-    /**
2218
-     * Output the course archive filter markup
2219
-     *
2220
-     * hooked into sensei_loop_course_before
2221
-     *
2222
-     * @since 1.9.0
2223
-     * @param
2224
-     */
2225
-    public static function course_archive_sorting( $query ){
2226
-
2227
-        // don't show on category pages and other pages
2228
-        if( ! is_archive(  'course ') || is_tax('course-category') ){
2229
-            return;
2230
-        }
2231
-
2232
-        /**
2233
-         * Filter the sensei archive course order by values
2234
-         *
2235
-         * @since 1.9.0
2236
-         * @param array $options {
2237
-         *  @type string $option_value
2238
-         *  @type string $option_string
2239
-         * }
2240
-         */
2241
-        $course_order_by_options = apply_filters( 'sensei_archive_course_order_by_options', array(
2242
-            "newness"     => __( "Sort by newest first", "woothemes-sensei"),
2243
-            "title"       => __( "Sort by title A-Z", "woothemes-sensei" ),
2244
-        ));
2245
-
2246
-        // setup the currently selected item
2247
-        $selected = 'newness';
2248
-        if( isset( $_GET['orderby'] ) ){
2249
-
2250
-            $selected =  $_GET[ 'orderby' ];
2251
-
2252
-        }
2253
-
2254
-        ?>
2085
+	}// end the_course_action_buttons
2086
+
2087
+	/**
2088
+	 * This function alter the main query on the course archive page.
2089
+	 * This also gives Sensei specific filters that allows variables to be altered specifically on the course archive.
2090
+	 *
2091
+	 * This function targets only the course archives and the my courses page. Shortcodes can set their own
2092
+	 * query parameters via the arguments.
2093
+	 *
2094
+	 * This function is hooked into pre_get_posts filter
2095
+	 *
2096
+	 * @since 1.9.0
2097
+	 *
2098
+	 * @param WP_Query $query
2099
+	 * @return WP_Query $query
2100
+	 */
2101
+	public static function course_query_filter( $query ){
2102
+
2103
+		// exit early for no course queries and admin queries
2104
+		if( is_admin( ) || 'course' != $query->get( 'post_type' ) ){
2105
+			return $query;
2106
+		}
2107
+
2108
+		global $post; // used to get the current page id for my courses
2109
+
2110
+		// for the course archive page
2111
+		if( $query->is_main_query() && is_post_type_archive('course') )
2112
+		{
2113
+			/**
2114
+			 * sensei_archive_courses_per_page
2115
+			 *
2116
+			 * Sensei courses per page on the course
2117
+			 * archive
2118
+			 *
2119
+			 * @since 1.9.0
2120
+			 * @param integer $posts_per_page default 10
2121
+			 */
2122
+			$query->set( 'posts_per_page', apply_filters( 'sensei_archive_courses_per_page', 10 ) );
2123
+
2124
+		}
2125
+		// for the my courses page
2126
+		elseif( is_page() && Sensei()->settings->get( 'my_course_page' ) == $post->ID  )
2127
+		{
2128
+			/**
2129
+			 * sensei_my_courses_per_page
2130
+			 *
2131
+			 * Sensei courses per page on the my courses page
2132
+			 * as set in the settings
2133
+			 *
2134
+			 * @since 1.9.0
2135
+			 * @param integer $posts_per_page default 10
2136
+			 */
2137
+			$query->set( 'posts_per_page', apply_filters( 'sensei_my_courses_per_page', 10 ) );
2138
+
2139
+		}
2140
+
2141
+		return $query;
2142
+
2143
+	}// end course_query_filter
2144
+
2145
+	/**
2146
+	 * Determine the class of the course loop
2147
+	 *
2148
+	 * This will output .first or .last and .course-item-number-x
2149
+	 *
2150
+	 * @return array $extra_classes
2151
+	 * @since 1.9.0
2152
+	 */
2153
+	public static function get_course_loop_content_class ()
2154
+	{
2155
+
2156
+		global $sensei_course_loop;
2157
+
2158
+
2159
+		if( !isset( $sensei_course_loop ) ){
2160
+			$sensei_course_loop = array();
2161
+		}
2162
+
2163
+		if (!isset($sensei_course_loop['counter'])) {
2164
+			$sensei_course_loop['counter'] = 0;
2165
+		}
2166
+
2167
+		if (!isset($sensei_course_loop['columns'])) {
2168
+			$sensei_course_loop['columns'] = self::get_loop_number_of_columns();
2169
+		}
2170
+
2171
+		// increment the counter
2172
+		$sensei_course_loop['counter']++;
2173
+
2174
+		$extra_classes = array();
2175
+		if( 0 == ( $sensei_course_loop['counter'] - 1 ) % $sensei_course_loop['columns'] || 1 == $sensei_course_loop['columns']  ){
2176
+			$extra_classes[] = 'first';
2177
+		}
2178
+
2179
+		if( 0 == $sensei_course_loop['counter'] % $sensei_course_loop['columns']  ){
2180
+			$extra_classes[] = 'last';
2181
+		}
2182
+
2183
+		// add the item number to the classes as well.
2184
+		$extra_classes[] = 'loop-item-number-'. $sensei_course_loop['counter'];
2185
+
2186
+		/**
2187
+		 * Filter the course loop class the fires in the  in get_course_loop_content_class function
2188
+		 * which is called from the course loop content-course.php
2189
+		 *
2190
+		 * @since 1.9.0
2191
+		 *
2192
+		 * @param array $extra_classes
2193
+		 * @param WP_Post $loop_current_course
2194
+		 */
2195
+		return apply_filters( 'sensei_course_loop_content_class', $extra_classes ,get_post() );
2196
+
2197
+	}// end get_course_loop_class
2198
+
2199
+	/**
2200
+	 * Get the number of columns set for Sensei courses
2201
+	 *
2202
+	 * @since 1.9.0
2203
+	 * @return mixed|void
2204
+	 */
2205
+	public static function get_loop_number_of_columns(){
2206
+
2207
+		/**
2208
+		 * Filter the number of columns on the course archive page.
2209
+		 *
2210
+		 * @since 1.9.0
2211
+		 * @param int $number_of_columns default 1
2212
+		 */
2213
+		return apply_filters('sensei_course_loop_number_of_columns', 1);
2214
+
2215
+	}
2216
+
2217
+	/**
2218
+	 * Output the course archive filter markup
2219
+	 *
2220
+	 * hooked into sensei_loop_course_before
2221
+	 *
2222
+	 * @since 1.9.0
2223
+	 * @param
2224
+	 */
2225
+	public static function course_archive_sorting( $query ){
2226
+
2227
+		// don't show on category pages and other pages
2228
+		if( ! is_archive(  'course ') || is_tax('course-category') ){
2229
+			return;
2230
+		}
2231
+
2232
+		/**
2233
+		 * Filter the sensei archive course order by values
2234
+		 *
2235
+		 * @since 1.9.0
2236
+		 * @param array $options {
2237
+		 *  @type string $option_value
2238
+		 *  @type string $option_string
2239
+		 * }
2240
+		 */
2241
+		$course_order_by_options = apply_filters( 'sensei_archive_course_order_by_options', array(
2242
+			"newness"     => __( "Sort by newest first", "woothemes-sensei"),
2243
+			"title"       => __( "Sort by title A-Z", "woothemes-sensei" ),
2244
+		));
2245
+
2246
+		// setup the currently selected item
2247
+		$selected = 'newness';
2248
+		if( isset( $_GET['orderby'] ) ){
2249
+
2250
+			$selected =  $_GET[ 'orderby' ];
2251
+
2252
+		}
2253
+
2254
+		?>
2255 2255
 
2256 2256
         <form class="sensei-ordering" name="sensei-course-order" action="<?php echo esc_attr( Sensei_Utils::get_current_url() ) ; ?>" method="POST">
2257 2257
             <select name="course-orderby" class="orderby">
2258 2258
                 <?php
2259
-                foreach( $course_order_by_options as $value => $text ){
2259
+				foreach( $course_order_by_options as $value => $text ){
2260 2260
 
2261
-                    echo '<option value="'. $value . ' "' . selected( $selected, $value, false ) . '>'. $text. '</option>';
2261
+					echo '<option value="'. $value . ' "' . selected( $selected, $value, false ) . '>'. $text. '</option>';
2262 2262
 
2263
-                }
2264
-                ?>
2263
+				}
2264
+				?>
2265 2265
             </select>
2266 2266
         </form>
2267 2267
 
2268 2268
     <?php
2269
-    }// end course archive filters
2270
-
2271
-    /**
2272
-     * Output the course archive filter markup
2273
-     *
2274
-     * hooked into sensei_loop_course_before
2275
-     *
2276
-     * @since 1.9.0
2277
-     * @param
2278
-     */
2279
-    public static function course_archive_filters( $query ){
2280
-
2281
-        // don't show on category pages
2282
-        if( is_tax('course-category') ){
2283
-            return;
2284
-        }
2285
-
2286
-        /**
2287
-         * filter the course archive filter buttons
2288
-         *
2289
-         * @since 1.9.0
2290
-         * @param array $filters{
2291
-         *   @type array ( $id, $url , $title )
2292
-         * }
2293
-         *
2294
-         */
2295
-        $filters = apply_filters( 'sensei_archive_course_filter_by_options', array(
2296
-            array( 'id' => 'all', 'url' => self::get_courses_page_url(), 'title'=> __( 'All', 'woothemes-sensei' ) ),
2297
-            array( 'id' => 'featured', 'url' => add_query_arg( array( 'course_filter'=>'featured'), self::get_courses_page_url()  ), 'title'=> __( 'Featured', 'woothemes-sensei' ) ),
2298
-        ));
2299
-
2300
-
2301
-        ?>
2269
+	}// end course archive filters
2270
+
2271
+	/**
2272
+	 * Output the course archive filter markup
2273
+	 *
2274
+	 * hooked into sensei_loop_course_before
2275
+	 *
2276
+	 * @since 1.9.0
2277
+	 * @param
2278
+	 */
2279
+	public static function course_archive_filters( $query ){
2280
+
2281
+		// don't show on category pages
2282
+		if( is_tax('course-category') ){
2283
+			return;
2284
+		}
2285
+
2286
+		/**
2287
+		 * filter the course archive filter buttons
2288
+		 *
2289
+		 * @since 1.9.0
2290
+		 * @param array $filters{
2291
+		 *   @type array ( $id, $url , $title )
2292
+		 * }
2293
+		 *
2294
+		 */
2295
+		$filters = apply_filters( 'sensei_archive_course_filter_by_options', array(
2296
+			array( 'id' => 'all', 'url' => self::get_courses_page_url(), 'title'=> __( 'All', 'woothemes-sensei' ) ),
2297
+			array( 'id' => 'featured', 'url' => add_query_arg( array( 'course_filter'=>'featured'), self::get_courses_page_url()  ), 'title'=> __( 'Featured', 'woothemes-sensei' ) ),
2298
+		));
2299
+
2300
+
2301
+		?>
2302 2302
         <ul class="sensei-course-filters clearfix" >
2303 2303
             <?php
2304 2304
 
2305
-            //determine the current active url
2306
-            $current_url = Sensei_Utils::get_current_url();
2305
+			//determine the current active url
2306
+			$current_url = Sensei_Utils::get_current_url();
2307 2307
 
2308
-            foreach( $filters as $filter ) {
2308
+			foreach( $filters as $filter ) {
2309 2309
 
2310
-                $active_class =  $current_url == $filter['url'] ? ' class="active" ' : '';
2310
+				$active_class =  $current_url == $filter['url'] ? ' class="active" ' : '';
2311 2311
 
2312
-                echo '<li><a '. $active_class .' id="'. $filter['id'] .'" href="'. esc_url( $filter['url'] ).'" >'. $filter['title']  .'</a></li>';
2312
+				echo '<li><a '. $active_class .' id="'. $filter['id'] .'" href="'. esc_url( $filter['url'] ).'" >'. $filter['title']  .'</a></li>';
2313 2313
 
2314
-            }
2315
-            ?>
2314
+			}
2315
+			?>
2316 2316
 
2317 2317
         </ul>
2318 2318
 
2319 2319
         <?php
2320 2320
 
2321
-    }
2321
+	}
2322 2322
 
2323
-    /**
2324
-     * if the featured link is clicked on the course archive page
2325
-     * filter the courses returned to only show those featured
2326
-     *
2327
-     * Hooked into pre_get_posts
2328
-     *
2329
-     * @since 1.9.0
2330
-     * @param WP_Query $query
2331
-     * @return WP_Query $query
2332
-     */
2333
-    public static function course_archive_featured_filter( $query ){
2334
-
2335
-        if( isset ( $_GET[ 'course_filter' ] ) && 'featured'== $_GET['course_filter'] && $query->is_main_query()  ){
2336
-            //setup meta query for featured courses
2337
-            $query->set( 'meta_value', 'featured'  );
2338
-            $query->set( 'meta_key', '_course_featured'  );
2339
-            $query->set( 'meta_compare', '='  );
2340
-        }
2341
-
2342
-        return $query;
2343
-    }
2344
-
2345
-    /**
2346
-     * if the course order drop down is changed
2347
-     *
2348
-     * Hooked into pre_get_posts
2349
-     *
2350
-     * @since 1.9.0
2351
-     * @param WP_Query $query
2352
-     * @return WP_Query $query
2353
-     */
2354
-    public static function course_archive_order_by_title( $query ){
2355
-
2356
-        if( isset ( $_POST[ 'course-orderby' ] ) && 'title '== $_POST['course-orderby']
2357
-            && 'course'== $query->get('post_type') && $query->is_main_query()  ){
2358
-            // setup the order by title for this query
2359
-            $query->set( 'orderby', 'title'  );
2360
-            $query->set( 'order', 'ASC'  );
2361
-        }
2362
-
2363
-        return $query;
2364
-    }
2365
-
2366
-
2367
-    /**
2368
-     * Get the link to the courses page. This will be the course post type archive
2369
-     * page link or the page the user set in their settings
2370
-     *
2371
-     * @since 1.9.0
2372
-     * @return string $course_page_url
2373
-     */
2374
-    public static function get_courses_page_url(){
2375
-
2376
-        $course_page_id = intval( Sensei()->settings->settings[ 'course_page' ] );
2377
-        $course_page_url = empty( $course_page_id ) ? get_post_type_archive_link('course') : get_permalink( $course_page_id );
2323
+	/**
2324
+	 * if the featured link is clicked on the course archive page
2325
+	 * filter the courses returned to only show those featured
2326
+	 *
2327
+	 * Hooked into pre_get_posts
2328
+	 *
2329
+	 * @since 1.9.0
2330
+	 * @param WP_Query $query
2331
+	 * @return WP_Query $query
2332
+	 */
2333
+	public static function course_archive_featured_filter( $query ){
2378 2334
 
2379
-        return $course_page_url;
2380
-
2381
-    }// get_course_url
2335
+		if( isset ( $_GET[ 'course_filter' ] ) && 'featured'== $_GET['course_filter'] && $query->is_main_query()  ){
2336
+			//setup meta query for featured courses
2337
+			$query->set( 'meta_value', 'featured'  );
2338
+			$query->set( 'meta_key', '_course_featured'  );
2339
+			$query->set( 'meta_compare', '='  );
2340
+		}
2382 2341
 
2383
-    /**
2384
-     * Output the headers on the course archive page
2385
-     *
2386
-     * Hooked into the sensei_archive_title
2387
-     *
2388
-     * @since 1.9.0
2389
-     * @param string $query_type
2390
-     * @param string $before_html
2391
-     * @param string $after_html
2392
-     * @return void
2393
-     */
2394
-    public static function archive_header( $query_type ='' , $before_html='', $after_html =''  ){
2342
+		return $query;
2343
+	}
2395 2344
 
2396
-        if( ! is_post_type_archive('course') ){
2397
-            return;
2398
-        }
2345
+	/**
2346
+	 * if the course order drop down is changed
2347
+	 *
2348
+	 * Hooked into pre_get_posts
2349
+	 *
2350
+	 * @since 1.9.0
2351
+	 * @param WP_Query $query
2352
+	 * @return WP_Query $query
2353
+	 */
2354
+	public static function course_archive_order_by_title( $query ){
2399 2355
 
2400
-        // deprecated since 1.9.0
2401
-        sensei_do_deprecated_action('sensei_archive_title','1.9.0','sensei_archive_before_course_loop');
2356
+		if( isset ( $_POST[ 'course-orderby' ] ) && 'title '== $_POST['course-orderby']
2357
+			&& 'course'== $query->get('post_type') && $query->is_main_query()  ){
2358
+			// setup the order by title for this query
2359
+			$query->set( 'orderby', 'title'  );
2360
+			$query->set( 'order', 'ASC'  );
2361
+		}
2402 2362
 
2403
-        $html = '';
2363
+		return $query;
2364
+	}
2404 2365
 
2405
-        if( empty( $before_html ) ){
2406 2366
 
2407
-            $before_html = '<header class="archive-header"><h1>';
2367
+	/**
2368
+	 * Get the link to the courses page. This will be the course post type archive
2369
+	 * page link or the page the user set in their settings
2370
+	 *
2371
+	 * @since 1.9.0
2372
+	 * @return string $course_page_url
2373
+	 */
2374
+	public static function get_courses_page_url(){
2408 2375
 
2409
-        }
2376
+		$course_page_id = intval( Sensei()->settings->settings[ 'course_page' ] );
2377
+		$course_page_url = empty( $course_page_id ) ? get_post_type_archive_link('course') : get_permalink( $course_page_id );
2410 2378
 
2411
-        if( empty( $after_html ) ){
2379
+		return $course_page_url;
2412 2380
 
2413
-            $after_html = '</h1></header>';
2381
+	}// get_course_url
2414 2382
 
2415
-        }
2383
+	/**
2384
+	 * Output the headers on the course archive page
2385
+	 *
2386
+	 * Hooked into the sensei_archive_title
2387
+	 *
2388
+	 * @since 1.9.0
2389
+	 * @param string $query_type
2390
+	 * @param string $before_html
2391
+	 * @param string $after_html
2392
+	 * @return void
2393
+	 */
2394
+	public static function archive_header( $query_type ='' , $before_html='', $after_html =''  ){
2416 2395
 
2417
-        if ( is_tax( 'course-category' ) ) {
2396
+		if( ! is_post_type_archive('course') ){
2397
+			return;
2398
+		}
2418 2399
 
2419
-            global $wp_query;
2400
+		// deprecated since 1.9.0
2401
+		sensei_do_deprecated_action('sensei_archive_title','1.9.0','sensei_archive_before_course_loop');
2420 2402
 
2421
-            $taxonomy_obj = $wp_query->get_queried_object();
2422
-            $taxonomy_short_name = $taxonomy_obj->taxonomy;
2423
-            $taxonomy_raw_obj = get_taxonomy( $taxonomy_short_name );
2424
-            $title = sprintf( __( '%1$s Archives: %2$s', 'woothemes-sensei' ), $taxonomy_raw_obj->labels->name, $taxonomy_obj->name );
2425
-            echo apply_filters( 'course_category_archive_title', $before_html . $title . $after_html );
2426
-            return;
2403
+		$html = '';
2427 2404
 
2428
-        } // End If Statement
2405
+		if( empty( $before_html ) ){
2429 2406
 
2430
-        switch ( $query_type ) {
2431
-            case 'newcourses':
2432
-                $html .= $before_html . __( 'New Courses', 'woothemes-sensei' ) . $after_html;
2433
-                break;
2434
-            case 'featuredcourses':
2435
-                $html .= $before_html .  __( 'Featured Courses', 'woothemes-sensei' ) . $after_html;
2436
-                break;
2437
-            case 'freecourses':
2438
-                $html .= $before_html .  __( 'Free Courses', 'woothemes-sensei' ) . $after_html;
2439
-                break;
2440
-            case 'paidcourses':
2441
-                $html .= $before_html .  __( 'Paid Courses', 'woothemes-sensei' ) . $after_html;
2442
-                break;
2443
-            default:
2444
-                $html .= $before_html . __( 'Courses', 'woothemes-sensei' ) . $after_html;
2445
-                break;
2446
-        } // End Switch Statement
2407
+			$before_html = '<header class="archive-header"><h1>';
2447 2408
 
2448
-        echo apply_filters( 'course_archive_title', $html );
2409
+		}
2449 2410
 
2450
-    }//course_archive_header
2411
+		if( empty( $after_html ) ){
2451 2412
 
2413
+			$after_html = '</h1></header>';
2452 2414
 
2453
-    /**
2454
-     * Filter the single course content
2455
-     * taking into account if the user has access.
2456
-     *
2457
-     * @1.9.0
2458
-     *
2459
-     * @param string $content
2460
-     * @return string $content or $excerpt
2461
-     */
2462
-    public static function single_course_content( $content ){
2415
+		}
2463 2416
 
2464
-        if( ! is_singular('course') ){
2417
+		if ( is_tax( 'course-category' ) ) {
2465 2418
 
2466
-            return $content;
2419
+			global $wp_query;
2467 2420
 
2468
-        }
2421
+			$taxonomy_obj = $wp_query->get_queried_object();
2422
+			$taxonomy_short_name = $taxonomy_obj->taxonomy;
2423
+			$taxonomy_raw_obj = get_taxonomy( $taxonomy_short_name );
2424
+			$title = sprintf( __( '%1$s Archives: %2$s', 'woothemes-sensei' ), $taxonomy_raw_obj->labels->name, $taxonomy_obj->name );
2425
+			echo apply_filters( 'course_category_archive_title', $before_html . $title . $after_html );
2426
+			return;
2469 2427
 
2470
-        // Content Access Permissions
2471
-        $access_permission = false;
2428
+		} // End If Statement
2472 2429
 
2473
-        if ( ! Sensei()->settings->get('access_permission')  || sensei_all_access() ) {
2430
+		switch ( $query_type ) {
2431
+			case 'newcourses':
2432
+				$html .= $before_html . __( 'New Courses', 'woothemes-sensei' ) . $after_html;
2433
+				break;
2434
+			case 'featuredcourses':
2435
+				$html .= $before_html .  __( 'Featured Courses', 'woothemes-sensei' ) . $after_html;
2436
+				break;
2437
+			case 'freecourses':
2438
+				$html .= $before_html .  __( 'Free Courses', 'woothemes-sensei' ) . $after_html;
2439
+				break;
2440
+			case 'paidcourses':
2441
+				$html .= $before_html .  __( 'Paid Courses', 'woothemes-sensei' ) . $after_html;
2442
+				break;
2443
+			default:
2444
+				$html .= $before_html . __( 'Courses', 'woothemes-sensei' ) . $after_html;
2445
+				break;
2446
+		} // End Switch Statement
2474 2447
 
2475
-            $access_permission = true;
2448
+		echo apply_filters( 'course_archive_title', $html );
2476 2449
 
2477
-        } // End If Statement
2450
+	}//course_archive_header
2478 2451
 
2479
-        // Check if the user is taking the course
2480
-        $is_user_taking_course = Sensei_Utils::user_started_course( get_the_ID(), get_current_user_id() );
2481 2452
 
2482
-        if(Sensei_WC::is_woocommerce_active()) {
2453
+	/**
2454
+	 * Filter the single course content
2455
+	 * taking into account if the user has access.
2456
+	 *
2457
+	 * @1.9.0
2458
+	 *
2459
+	 * @param string $content
2460
+	 * @return string $content or $excerpt
2461
+	 */
2462
+	public static function single_course_content( $content ){
2483 2463
 
2484
-            $wc_post_id = get_post_meta( get_the_ID(), '_course_woocommerce_product', true );
2485
-            $product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id );
2464
+		if( ! is_singular('course') ){
2486 2465
 
2487
-            $has_product_attached = isset ( $product ) && is_object ( $product );
2466
+			return $content;
2488 2467
 
2489
-        } else {
2468
+		}
2490 2469
 
2491
-            $has_product_attached = false;
2470
+		// Content Access Permissions
2471
+		$access_permission = false;
2492 2472
 
2493
-        }
2473
+		if ( ! Sensei()->settings->get('access_permission')  || sensei_all_access() ) {
2494 2474
 
2495
-        if ( ( is_user_logged_in() && $is_user_taking_course )
2496
-            || ( $access_permission && !$has_product_attached)
2497
-            || 'full' == Sensei()->settings->get( 'course_single_content_display' ) ) {
2475
+			$access_permission = true;
2498 2476
 
2499
-            return $content;
2477
+		} // End If Statement
2500 2478
 
2501
-        } else {
2479
+		// Check if the user is taking the course
2480
+		$is_user_taking_course = Sensei_Utils::user_started_course( get_the_ID(), get_current_user_id() );
2502 2481
 
2503
-            return '<p class="course-excerpt">' . get_post(  get_the_ID() )->post_excerpt . '</p>';
2482
+		if(Sensei_WC::is_woocommerce_active()) {
2504 2483
 
2505
-        }
2484
+			$wc_post_id = get_post_meta( get_the_ID(), '_course_woocommerce_product', true );
2485
+			$product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id );
2506 2486
 
2507
-    }// end single_course_content
2487
+			$has_product_attached = isset ( $product ) && is_object ( $product );
2508 2488
 
2509
-    /**
2510
-     * Output the the single course lessons title with markup.
2511
-     *
2512
-     * @since 1.9.0
2513
-     */
2514
-    public static function the_course_lessons_title(){
2515
-        global $post;
2516
-        $none_module_lessons = Sensei()->modules->get_none_module_lessons( $post->ID  );
2517
-        $course_lessons = Sensei()->course->course_lessons( $post->ID );
2489
+		} else {
2518 2490
 
2519
-        // title should be Other Lessons if there are lessons belonging to models.
2520
-        $title = __('Other Lessons', 'woothemes-sensei');
2521
-        if( count( $course_lessons ) == count( $none_module_lessons )  ){
2491
+			$has_product_attached = false;
2522 2492
 
2523
-            $title = __('Lessons', 'woothemes-sensei');
2493
+		}
2494
+
2495
+		if ( ( is_user_logged_in() && $is_user_taking_course )
2496
+			|| ( $access_permission && !$has_product_attached)
2497
+			|| 'full' == Sensei()->settings->get( 'course_single_content_display' ) ) {
2498
+
2499
+			return $content;
2524 2500
 
2525
-        }
2501
+		} else {
2526 2502
 
2527
-        /**
2528
-         * hook document in class-woothemes-sensei-message.php
2529
-         */
2530
-        $title = apply_filters( 'sensei_single_title', $title, $post->post_type );
2503
+			return '<p class="course-excerpt">' . get_post(  get_the_ID() )->post_excerpt . '</p>';
2531 2504
 
2532
-        ob_start(); // start capturing the following output.
2505
+		}
2533 2506
 
2534
-        ?>
2507
+	}// end single_course_content
2508
+
2509
+	/**
2510
+	 * Output the the single course lessons title with markup.
2511
+	 *
2512
+	 * @since 1.9.0
2513
+	 */
2514
+	public static function the_course_lessons_title(){
2515
+		global $post;
2516
+		$none_module_lessons = Sensei()->modules->get_none_module_lessons( $post->ID  );
2517
+		$course_lessons = Sensei()->course->course_lessons( $post->ID );
2518
+
2519
+		// title should be Other Lessons if there are lessons belonging to models.
2520
+		$title = __('Other Lessons', 'woothemes-sensei');
2521
+		if( count( $course_lessons ) == count( $none_module_lessons )  ){
2522
+
2523
+			$title = __('Lessons', 'woothemes-sensei');
2524
+
2525
+		}
2526
+
2527
+		/**
2528
+		 * hook document in class-woothemes-sensei-message.php
2529
+		 */
2530
+		$title = apply_filters( 'sensei_single_title', $title, $post->post_type );
2531
+
2532
+		ob_start(); // start capturing the following output.
2533
+
2534
+		?>
2535 2535
 
2536 2536
             <header>
2537 2537
                 <h2> <?php echo $title; ?> </h2>
@@ -2539,277 +2539,277 @@  discard block
 block discarded – undo
2539 2539
 
2540 2540
         <?php
2541 2541
 
2542
-        /**
2543
-         * Filter the title and markup that appears above the lessons on a single course
2544
-         * page.
2545
-         *
2546
-         * @since 1.9.0
2547
-         * @param string $lessons_title_html
2548
-         */
2549
-        echo apply_filters('the_course_lessons_title', ob_get_clean() ); // output and filter the captured output and stop capturing.
2550
-
2551
-    }// end the_course_lessons_title
2552
-
2553
-    /**
2554
-     * This function loads the global wp_query object with with lessons
2555
-     * of the current course. It is designed to be used on the single-course template
2556
-     * and expects the global post to be a singular course.
2557
-     *
2558
-     * This function excludes lessons belonging to modules as they are
2559
-     * queried separately.
2560
-     *
2561
-     * @since 1.9.0
2562
-     * @global $wp_query
2563
-     */
2564
-    public static function load_single_course_lessons_query(){
2565
-
2566
-        global $post, $wp_query;
2542
+		/**
2543
+		 * Filter the title and markup that appears above the lessons on a single course
2544
+		 * page.
2545
+		 *
2546
+		 * @since 1.9.0
2547
+		 * @param string $lessons_title_html
2548
+		 */
2549
+		echo apply_filters('the_course_lessons_title', ob_get_clean() ); // output and filter the captured output and stop capturing.
2567 2550
 
2568
-        $course_id = $post->ID;
2551
+	}// end the_course_lessons_title
2569 2552
 
2570
-        if( 'course' != get_post_type( $course_id ) ){
2571
-            return;
2572
-        }
2553
+	/**
2554
+	 * This function loads the global wp_query object with with lessons
2555
+	 * of the current course. It is designed to be used on the single-course template
2556
+	 * and expects the global post to be a singular course.
2557
+	 *
2558
+	 * This function excludes lessons belonging to modules as they are
2559
+	 * queried separately.
2560
+	 *
2561
+	 * @since 1.9.0
2562
+	 * @global $wp_query
2563
+	 */
2564
+	public static function load_single_course_lessons_query(){
2573 2565
 
2574
-        $course_lesson_query_args = array(
2575
-            'post_type'         => 'lesson',
2576
-            'posts_per_page'    => 500,
2577
-            'orderby'           => 'date',
2578
-            'order'             => 'ASC',
2579
-            'meta_query'        => array(
2580
-                array(
2581
-                    'key' => '_lesson_course',
2582
-                    'value' => intval( $course_id ),
2583
-                ),
2584
-            ),
2585
-            'post_status'       => 'public',
2586
-            'suppress_filters'  => 0,
2587
-        );
2566
+		global $post, $wp_query;
2588 2567
 
2589
-        // Exclude lessons belonging to modules as they are queried along with the modules.
2590
-        $modules = Sensei()->modules->get_course_modules( $course_id );
2591
-        if( !is_wp_error( $modules ) && ! empty( $modules ) && is_array( $modules ) ){
2568
+		$course_id = $post->ID;
2592 2569
 
2593
-            $terms_ids = array();
2594
-            foreach( $modules as $term ){
2570
+		if( 'course' != get_post_type( $course_id ) ){
2571
+			return;
2572
+		}
2595 2573
 
2596
-                $terms_ids[] = $term->term_id;
2574
+		$course_lesson_query_args = array(
2575
+			'post_type'         => 'lesson',
2576
+			'posts_per_page'    => 500,
2577
+			'orderby'           => 'date',
2578
+			'order'             => 'ASC',
2579
+			'meta_query'        => array(
2580
+				array(
2581
+					'key' => '_lesson_course',
2582
+					'value' => intval( $course_id ),
2583
+				),
2584
+			),
2585
+			'post_status'       => 'public',
2586
+			'suppress_filters'  => 0,
2587
+		);
2588
+
2589
+		// Exclude lessons belonging to modules as they are queried along with the modules.
2590
+		$modules = Sensei()->modules->get_course_modules( $course_id );
2591
+		if( !is_wp_error( $modules ) && ! empty( $modules ) && is_array( $modules ) ){
2592
+
2593
+			$terms_ids = array();
2594
+			foreach( $modules as $term ){
2595
+
2596
+				$terms_ids[] = $term->term_id;
2597 2597
 
2598
-            }
2598
+			}
2599 2599
 
2600
-            $course_lesson_query_args[ 'tax_query'] = array(
2601
-                array(
2602
-                    'taxonomy' => 'module',
2603
-                    'field'    => 'id',
2604
-                    'terms'    => $terms_ids,
2605
-                    'operator' => 'NOT IN',
2606
-                ),
2607
-            );
2608
-        }
2600
+			$course_lesson_query_args[ 'tax_query'] = array(
2601
+				array(
2602
+					'taxonomy' => 'module',
2603
+					'field'    => 'id',
2604
+					'terms'    => $terms_ids,
2605
+					'operator' => 'NOT IN',
2606
+				),
2607
+			);
2608
+		}
2609 2609
 
2610
-        $wp_query = new WP_Query( $course_lesson_query_args );
2610
+		$wp_query = new WP_Query( $course_lesson_query_args );
2611 2611
 
2612
-    }// load_single_course_lessons
2612
+	}// load_single_course_lessons
2613 2613
 
2614
-    /**
2615
-     * Flush the rewrite rules for a course post type
2616
-     *
2617
-     * @since 1.9.0
2618
-     *
2619
-     * @param $post_id
2620
-     */
2621
-    public static function flush_rewrite_rules( $post_id ){
2614
+	/**
2615
+	 * Flush the rewrite rules for a course post type
2616
+	 *
2617
+	 * @since 1.9.0
2618
+	 *
2619
+	 * @param $post_id
2620
+	 */
2621
+	public static function flush_rewrite_rules( $post_id ){
2622 2622
 
2623
-        if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){
2623
+		if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){
2624 2624
 
2625
-            return;
2625
+			return;
2626 2626
 
2627
-        }
2627
+		}
2628 2628
 
2629 2629
 
2630
-        if( 'course' == get_post_type( $post_id )  ){
2630
+		if( 'course' == get_post_type( $post_id )  ){
2631 2631
 
2632
-            Sensei()->initiate_rewrite_rules_flush();
2632
+			Sensei()->initiate_rewrite_rules_flush();
2633 2633
 
2634
-        }
2634
+		}
2635 2635
 
2636
-    }
2636
+	}
2637 2637
 
2638
-    /**
2639
-     * Optionally return the full content on the single course pages
2640
-     * depending on the users course_single_content_display setting
2641
-     *
2642
-     * @since 1.9.0
2643
-     * @param $excerpt
2644
-     * @return string
2645
-     */
2646
-    public static function full_content_excerpt_override( $excerpt ){
2638
+	/**
2639
+	 * Optionally return the full content on the single course pages
2640
+	 * depending on the users course_single_content_display setting
2641
+	 *
2642
+	 * @since 1.9.0
2643
+	 * @param $excerpt
2644
+	 * @return string
2645
+	 */
2646
+	public static function full_content_excerpt_override( $excerpt ){
2647 2647
 
2648
-        if (   is_singular('course')  &&
2649
-                'full' == Sensei()->settings->get( 'course_single_content_display' ) ){
2648
+		if (   is_singular('course')  &&
2649
+				'full' == Sensei()->settings->get( 'course_single_content_display' ) ){
2650 2650
 
2651
-            return get_the_content();
2651
+			return get_the_content();
2652 2652
 
2653
-        } else {
2653
+		} else {
2654 2654
 
2655
-            return $excerpt;
2655
+			return $excerpt;
2656 2656
 
2657
-        }
2657
+		}
2658 2658
 
2659
-    }
2659
+	}
2660 2660
 
2661
-    /**
2662
-     * Output the course actions like start taking course, register, add to cart etc.
2663
-     *
2664
-     * @since 1.9.0
2665
-     */
2666
-    public static function the_course_enrolment_actions(){
2667
-        ?>
2661
+	/**
2662
+	 * Output the course actions like start taking course, register, add to cart etc.
2663
+	 *
2664
+	 * @since 1.9.0
2665
+	 */
2666
+	public static function the_course_enrolment_actions(){
2667
+		?>
2668 2668
         <section class="course-meta course-enrolment">
2669 2669
         <?php
2670
-        global  $post, $current_user;
2671
-        $is_user_taking_course = Sensei_Utils::user_started_course( $post->ID, $current_user->ID );
2672
-        if ( is_user_logged_in() && ! $is_user_taking_course ) {
2673
-
2674
-            // Get the product ID
2675
-            $wc_post_id = absint( get_post_meta( $post->ID, '_course_woocommerce_product', true ) );
2676
-
2677
-            // Check for woocommerce
2678
-            if ( Sensei_WC::is_woocommerce_active() && ( 0 < intval( $wc_post_id ) ) ) {
2679
-                sensei_wc_add_to_cart($post->ID);
2680
-            } else {
2681
-                sensei_start_course_form($post->ID);
2682
-            } // End If Statement
2683
-
2684
-        } elseif ( is_user_logged_in() ) {
2685
-
2686
-            // Check if course is completed
2687
-            $user_course_status = Sensei_Utils::user_course_status( $post->ID, $current_user->ID );
2688
-            $completed_course = Sensei_Utils::user_completed_course( $user_course_status );
2689
-            // Success message
2690
-            if ( $completed_course ) { ?>
2670
+		global  $post, $current_user;
2671
+		$is_user_taking_course = Sensei_Utils::user_started_course( $post->ID, $current_user->ID );
2672
+		if ( is_user_logged_in() && ! $is_user_taking_course ) {
2673
+
2674
+			// Get the product ID
2675
+			$wc_post_id = absint( get_post_meta( $post->ID, '_course_woocommerce_product', true ) );
2676
+
2677
+			// Check for woocommerce
2678
+			if ( Sensei_WC::is_woocommerce_active() && ( 0 < intval( $wc_post_id ) ) ) {
2679
+				sensei_wc_add_to_cart($post->ID);
2680
+			} else {
2681
+				sensei_start_course_form($post->ID);
2682
+			} // End If Statement
2683
+
2684
+		} elseif ( is_user_logged_in() ) {
2685
+
2686
+			// Check if course is completed
2687
+			$user_course_status = Sensei_Utils::user_course_status( $post->ID, $current_user->ID );
2688
+			$completed_course = Sensei_Utils::user_completed_course( $user_course_status );
2689
+			// Success message
2690
+			if ( $completed_course ) { ?>
2691 2691
                 <div class="status completed"><?php  _e( 'Completed', 'woothemes-sensei' ); ?></div>
2692 2692
                 <?php
2693
-                $has_quizzes = Sensei()->course->course_quizzes( $post->ID, true );
2694
-                if( has_filter( 'sensei_results_links' ) || $has_quizzes ) { ?>
2693
+				$has_quizzes = Sensei()->course->course_quizzes( $post->ID, true );
2694
+				if( has_filter( 'sensei_results_links' ) || $has_quizzes ) { ?>
2695 2695
                     <p class="sensei-results-links">
2696 2696
                         <?php
2697
-                        $results_link = '';
2698
-                        if( $has_quizzes ) {
2699
-                            $results_link = '<a class="view-results" href="' . Sensei()->course_results->get_permalink( $post->ID ) . '">' .  __( 'View results', 'woothemes-sensei' ) . '</a>';
2700
-                        }
2701
-                        $results_link = apply_filters( 'sensei_results_links', $results_link );
2702
-                        echo $results_link;
2703
-                        ?></p>
2697
+						$results_link = '';
2698
+						if( $has_quizzes ) {
2699
+							$results_link = '<a class="view-results" href="' . Sensei()->course_results->get_permalink( $post->ID ) . '">' .  __( 'View results', 'woothemes-sensei' ) . '</a>';
2700
+						}
2701
+						$results_link = apply_filters( 'sensei_results_links', $results_link );
2702
+						echo $results_link;
2703
+						?></p>
2704 2704
                 <?php } ?>
2705 2705
             <?php } else { ?>
2706 2706
                 <div class="status in-progress"><?php echo __( 'In Progress', 'woothemes-sensei' ); ?></div>
2707 2707
             <?php }
2708 2708
 
2709
-        } else {
2710
-            // Get the product ID
2711
-            $wc_post_id = absint( get_post_meta( $post->ID, '_course_woocommerce_product', true ) );
2712
-            // Check for woocommerce
2713
-            if ( Sensei_WC::is_woocommerce_active() && ( 0 < intval( $wc_post_id ) ) ) {
2709
+		} else {
2710
+			// Get the product ID
2711
+			$wc_post_id = absint( get_post_meta( $post->ID, '_course_woocommerce_product', true ) );
2712
+			// Check for woocommerce
2713
+			if ( Sensei_WC::is_woocommerce_active() && ( 0 < intval( $wc_post_id ) ) ) {
2714 2714
 
2715
-                sensei_wc_add_to_cart($post->ID);
2715
+				sensei_wc_add_to_cart($post->ID);
2716 2716
 
2717
-            } else {
2717
+			} else {
2718 2718
 
2719
-                if( get_option( 'users_can_register') ) {
2719
+				if( get_option( 'users_can_register') ) {
2720 2720
 
2721 2721
 
2722
-                    $my_courses_page_id = '';
2722
+					$my_courses_page_id = '';
2723 2723
 
2724
-                    /**
2725
-                     * Filter to force Sensei to output the default WordPress user
2726
-                     * registration link.
2727
-                     *
2728
-                     * @since 1.9.0
2729
-                     * @param bool $wp_register_link default false
2730
-                     */
2724
+					/**
2725
+					 * Filter to force Sensei to output the default WordPress user
2726
+					 * registration link.
2727
+					 *
2728
+					 * @since 1.9.0
2729
+					 * @param bool $wp_register_link default false
2730
+					 */
2731 2731
 
2732
-                    $wp_register_link = apply_filters('sensei_use_wp_register_link', false);
2732
+					$wp_register_link = apply_filters('sensei_use_wp_register_link', false);
2733 2733
 
2734
-                    $settings = Sensei()->settings->get_settings();
2735
-                    if( isset( $settings[ 'my_course_page' ] )
2736
-                        && 0 < intval( $settings[ 'my_course_page' ] ) ){
2734
+					$settings = Sensei()->settings->get_settings();
2735
+					if( isset( $settings[ 'my_course_page' ] )
2736
+						&& 0 < intval( $settings[ 'my_course_page' ] ) ){
2737 2737
 
2738
-                        $my_courses_page_id = $settings[ 'my_course_page' ];
2738
+						$my_courses_page_id = $settings[ 'my_course_page' ];
2739 2739
 
2740
-                    }
2740
+					}
2741 2741
 
2742
-                    // If a My Courses page was set in Settings, and 'sensei_use_wp_register_link'
2743
-                    // is false, link to My Courses. If not, link to default WordPress registration page.
2744
-                    if( !empty( $my_courses_page_id ) && $my_courses_page_id && !$wp_register_link){
2742
+					// If a My Courses page was set in Settings, and 'sensei_use_wp_register_link'
2743
+					// is false, link to My Courses. If not, link to default WordPress registration page.
2744
+					if( !empty( $my_courses_page_id ) && $my_courses_page_id && !$wp_register_link){
2745 2745
 
2746
-                        $my_courses_url = get_permalink( $my_courses_page_id  );
2747
-                        $register_link = '<a href="'.$my_courses_url. '">' . __('Register', 'woothemes-sensei') .'</a>';
2748
-                        echo '<div class="status register">' . $register_link . '</div>' ;
2746
+						$my_courses_url = get_permalink( $my_courses_page_id  );
2747
+						$register_link = '<a href="'.$my_courses_url. '">' . __('Register', 'woothemes-sensei') .'</a>';
2748
+						echo '<div class="status register">' . $register_link . '</div>' ;
2749 2749
 
2750
-                    } else{
2750
+					} else{
2751 2751
 
2752
-                        wp_register( '<div class="status register">', '</div>' );
2752
+						wp_register( '<div class="status register">', '</div>' );
2753 2753
 
2754
-                    }
2754
+					}
2755 2755
 
2756
-                } // end if user can register
2756
+				} // end if user can register
2757 2757
 
2758
-            } // End If Statement
2758
+			} // End If Statement
2759 2759
 
2760
-        } // End If Statement ?>
2760
+		} // End If Statement ?>
2761 2761
 
2762 2762
         </section><?php
2763 2763
 
2764
-    }// end the_course_enrolment_actions
2764
+	}// end the_course_enrolment_actions
2765 2765
 
2766
-    /**
2767
-     * Output the course video inside the loop.
2768
-     *
2769
-     * @since 1.9.0
2770
-     */
2771
-    public static function the_course_video(){
2766
+	/**
2767
+	 * Output the course video inside the loop.
2768
+	 *
2769
+	 * @since 1.9.0
2770
+	 */
2771
+	public static function the_course_video(){
2772 2772
 
2773
-        global $post;
2774
-        // Get the meta info
2775
-        $course_video_embed = get_post_meta( $post->ID, '_course_video_embed', true );
2773
+		global $post;
2774
+		// Get the meta info
2775
+		$course_video_embed = get_post_meta( $post->ID, '_course_video_embed', true );
2776 2776
 
2777
-        if ( 'http' == substr( $course_video_embed, 0, 4) ) {
2777
+		if ( 'http' == substr( $course_video_embed, 0, 4) ) {
2778 2778
 
2779
-            $course_video_embed = wp_oembed_get( esc_url( $course_video_embed ) );
2779
+			$course_video_embed = wp_oembed_get( esc_url( $course_video_embed ) );
2780 2780
 
2781
-        } // End If Statement
2781
+		} // End If Statement
2782 2782
 
2783
-        if ( '' != $course_video_embed ) { ?>
2783
+		if ( '' != $course_video_embed ) { ?>
2784 2784
 
2785 2785
             <div class="course-video">
2786 2786
                 <?php echo html_entity_decode($course_video_embed); ?>
2787 2787
             </div>
2788 2788
 
2789 2789
         <?php } // End If Statement
2790
-    }
2790
+	}
2791 2791
 
2792
-    /**
2793
-     * Output the title for the single lesson page
2794
-     *
2795
-     * @global $post
2796
-     * @since 1.9.0
2797
-     */
2798
-    public static function the_title(){
2792
+	/**
2793
+	 * Output the title for the single lesson page
2794
+	 *
2795
+	 * @global $post
2796
+	 * @since 1.9.0
2797
+	 */
2798
+	public static function the_title(){
2799 2799
 
2800
-        global $post;
2800
+		global $post;
2801 2801
 
2802
-        ?>
2802
+		?>
2803 2803
         <header>
2804 2804
 
2805 2805
             <h1>
2806 2806
 
2807 2807
                 <?php
2808
-                /**
2809
-                 * Filter documented in class-sensei-messages.php the_title
2810
-                 */
2811
-                echo apply_filters( 'sensei_single_title', get_the_title( $post ), $post->post_type );
2812
-                ?>
2808
+				/**
2809
+				 * Filter documented in class-sensei-messages.php the_title
2810
+				 */
2811
+				echo apply_filters( 'sensei_single_title', get_the_title( $post ), $post->post_type );
2812
+				?>
2813 2813
 
2814 2814
             </h1>
2815 2815
 
@@ -2817,111 +2817,111 @@  discard block
 block discarded – undo
2817 2817
 
2818 2818
         <?php
2819 2819
 
2820
-    }//the_title
2821
-
2822
-    /**
2823
-     * Show the title on the course category pages
2824
-     *
2825
-     * @since 1.9.0
2826
-     */
2827
-    public static function course_category_title(){
2828
-
2829
-        if( ! is_tax( 'course-category' ) ){
2830
-            return;
2831
-        }
2832
-
2833
-        $category_slug = get_query_var('course-category');
2834
-        $term  = get_term_by('slug',$category_slug,'course-category');
2835
-
2836
-        if( ! empty($term) ){
2837
-
2838
-            $title = $term->name;
2839
-
2840
-        }else{
2841
-
2842
-            $title = 'Course Category';
2843
-
2844
-        }
2845
-
2846
-        $html = '<h2 class="sensei-category-title">';
2847
-        $html .= __('Category') . ' ' . $title;
2848
-        $html .= '</h2>';
2849
-
2850
-        echo apply_filters( 'course_category_title', $html , $term->term_id );
2851
-
2852
-    }// course_category_title
2853
-
2854
-    /**
2855
-     * Alter the course query to respect the order set for courses and apply
2856
-     * this on the course-category pages.
2857
-     *
2858
-     * @since 1.9.0
2859
-     *
2860
-     * @param WP_Query $query
2861
-     * @return WP_Query
2862
-     */
2863
-    public static function alter_course_category_order( $query ){
2864
-
2865
-        if( ! is_tax( 'course-category' ) || ! $query->is_main_query() ){
2866
-            return $query;
2867
-        }
2868
-
2869
-        $order = get_option( 'sensei_course_order', '' );
2870
-        if( !empty( $order )  ){
2871
-            $query->set('orderby', 'menu_order' );
2872
-            $query->set('order', 'ASC' );
2873
-        }
2874
-
2875
-        return $query;
2876
-
2877
-    }
2878
-
2879
-    /**
2880
-     * The very basic course query arguments
2881
-     * so we don't have to repeat this througout
2882
-     * the code base.
2883
-     *
2884
-     * Usage:
2885
-     * $args = Sensei_Course::get_default_query_args();
2886
-     * $args['custom_arg'] ='custom value';
2887
-     * $courses = get_posts( $args )
2888
-     *
2889
-     * @since 1.9.0
2890
-     *
2891
-     * @return array
2892
-     */
2893
-    public static function get_default_query_args(){
2894
-        return array(
2895
-            'post_type' 		=> 'course',
2896
-            'posts_per_page' 		=> 1000,
2897
-            'orderby'         	=> 'date',
2898
-            'order'           	=> 'DESC',
2899
-            'suppress_filters' 	=> 0
2900
-        );
2901
-    }
2902
-
2903
-    /**
2904
-     * Check if the prerequisite course is completed
2905
-     * Courses with no pre-requisite should always return true
2906
-     *
2907
-     * @since 1.9.0
2908
-     * @param $course_id
2909
-     * @return bool
2910
-     */
2911
-    public static function is_prerequisite_complete( $course_id ){
2912
-
2913
-        $course_prerequisite_id = get_post_meta( $course_id, '_course_prerequisite', true );
2914
-
2915
-        // if it has a pre requisite course check it
2916
-        if( ! empty(  $course_prerequisite_id ) ){
2917
-
2918
-            return Sensei_Utils::user_completed_course( $course_prerequisite_id, get_current_user_id() );
2919
-
2920
-        }
2921
-
2922
-        return true;
2923
-
2924
-    }// end is_prerequisite_complete
2820
+	}//the_title
2821
+
2822
+	/**
2823
+	 * Show the title on the course category pages
2824
+	 *
2825
+	 * @since 1.9.0
2826
+	 */
2827
+	public static function course_category_title(){
2828
+
2829
+		if( ! is_tax( 'course-category' ) ){
2830
+			return;
2831
+		}
2832
+
2833
+		$category_slug = get_query_var('course-category');
2834
+		$term  = get_term_by('slug',$category_slug,'course-category');
2835
+
2836
+		if( ! empty($term) ){
2837
+
2838
+			$title = $term->name;
2839
+
2840
+		}else{
2841
+
2842
+			$title = 'Course Category';
2843
+
2844
+		}
2845
+
2846
+		$html = '<h2 class="sensei-category-title">';
2847
+		$html .= __('Category') . ' ' . $title;
2848
+		$html .= '</h2>';
2849
+
2850
+		echo apply_filters( 'course_category_title', $html , $term->term_id );
2851
+
2852
+	}// course_category_title
2853
+
2854
+	/**
2855
+	 * Alter the course query to respect the order set for courses and apply
2856
+	 * this on the course-category pages.
2857
+	 *
2858
+	 * @since 1.9.0
2859
+	 *
2860
+	 * @param WP_Query $query
2861
+	 * @return WP_Query
2862
+	 */
2863
+	public static function alter_course_category_order( $query ){
2864
+
2865
+		if( ! is_tax( 'course-category' ) || ! $query->is_main_query() ){
2866
+			return $query;
2867
+		}
2868
+
2869
+		$order = get_option( 'sensei_course_order', '' );
2870
+		if( !empty( $order )  ){
2871
+			$query->set('orderby', 'menu_order' );
2872
+			$query->set('order', 'ASC' );
2873
+		}
2874
+
2875
+		return $query;
2876
+
2877
+	}
2878
+
2879
+	/**
2880
+	 * The very basic course query arguments
2881
+	 * so we don't have to repeat this througout
2882
+	 * the code base.
2883
+	 *
2884
+	 * Usage:
2885
+	 * $args = Sensei_Course::get_default_query_args();
2886
+	 * $args['custom_arg'] ='custom value';
2887
+	 * $courses = get_posts( $args )
2888
+	 *
2889
+	 * @since 1.9.0
2890
+	 *
2891
+	 * @return array
2892
+	 */
2893
+	public static function get_default_query_args(){
2894
+		return array(
2895
+			'post_type' 		=> 'course',
2896
+			'posts_per_page' 		=> 1000,
2897
+			'orderby'         	=> 'date',
2898
+			'order'           	=> 'DESC',
2899
+			'suppress_filters' 	=> 0
2900
+		);
2901
+	}
2902
+
2903
+	/**
2904
+	 * Check if the prerequisite course is completed
2905
+	 * Courses with no pre-requisite should always return true
2906
+	 *
2907
+	 * @since 1.9.0
2908
+	 * @param $course_id
2909
+	 * @return bool
2910
+	 */
2911
+	public static function is_prerequisite_complete( $course_id ){
2912
+
2913
+		$course_prerequisite_id = get_post_meta( $course_id, '_course_prerequisite', true );
2914
+
2915
+		// if it has a pre requisite course check it
2916
+		if( ! empty(  $course_prerequisite_id ) ){
2917
+
2918
+			return Sensei_Utils::user_completed_course( $course_prerequisite_id, get_current_user_id() );
2919
+
2920
+		}
2921
+
2922
+		return true;
2923
+
2924
+	}// end is_prerequisite_complete
2925 2925
 
2926 2926
 
2927 2927
 }// End Class
Please login to merge, or discard this patch.
Spacing   +639 added lines, -639 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined('ABSPATH')) exit; // Exit if accessed directly
3 3
 
4 4
 /**
5 5
  * Sensei Course Class
@@ -33,72 +33,72 @@  discard block
 block discarded – undo
33 33
 	 * Constructor.
34 34
 	 * @since  1.0.0
35 35
 	 */
36
-	public function __construct () {
36
+	public function __construct() {
37 37
 
38 38
         $this->token = 'course';
39 39
 
40 40
 		// Setup meta fields for this post type
41
-		$this->meta_fields = array( 'course_prerequisite', 'course_featured', 'course_video_embed', 'course_woocommerce_product' );
41
+		$this->meta_fields = array('course_prerequisite', 'course_featured', 'course_video_embed', 'course_woocommerce_product');
42 42
 		// Admin actions
43
-		if ( is_admin() ) {
43
+		if (is_admin()) {
44 44
 			// Metabox functions
45
-            add_action( 'add_meta_boxes', array( $this, 'meta_box_setup' ), 20 );
46
-			add_action( 'save_post', array( $this, 'meta_box_save' ) );
45
+            add_action('add_meta_boxes', array($this, 'meta_box_setup'), 20);
46
+			add_action('save_post', array($this, 'meta_box_save'));
47 47
 			// Custom Write Panel Columns
48
-			add_filter( 'manage_edit-course_columns', array( $this, 'add_column_headings' ), 10, 1 );
49
-			add_action( 'manage_posts_custom_column', array( $this, 'add_column_data' ), 10, 2 );
48
+			add_filter('manage_edit-course_columns', array($this, 'add_column_headings'), 10, 1);
49
+			add_action('manage_posts_custom_column', array($this, 'add_column_data'), 10, 2);
50 50
 		} else {
51 51
 			$this->my_courses_page = false;
52 52
 		} // End If Statement
53 53
 
54 54
 		// Update course completion upon completion of a lesson
55
-		add_action( 'sensei_user_lesson_end', array( $this, 'update_status_after_lesson_change' ), 10, 2 );
55
+		add_action('sensei_user_lesson_end', array($this, 'update_status_after_lesson_change'), 10, 2);
56 56
 		// Update course completion upon reset of a lesson
57
-		add_action( 'sensei_user_lesson_reset', array( $this, 'update_status_after_lesson_change' ), 10, 2 );
57
+		add_action('sensei_user_lesson_reset', array($this, 'update_status_after_lesson_change'), 10, 2);
58 58
 		// Update course completion upon grading of a quiz
59
-		add_action( 'sensei_user_quiz_grade', array( $this, 'update_status_after_quiz_submission' ), 10, 2 );
59
+		add_action('sensei_user_quiz_grade', array($this, 'update_status_after_quiz_submission'), 10, 2);
60 60
 
61 61
         // show the progress bar ont he single course page
62
-        add_action( 'sensei_single_course_content_inside_before' , array( $this, 'the_progress_statement' ), 15 );
63
-        add_action( 'sensei_single_course_content_inside_before' , array( $this, 'the_progress_meter' ), 16 );
62
+        add_action('sensei_single_course_content_inside_before', array($this, 'the_progress_statement'), 15);
63
+        add_action('sensei_single_course_content_inside_before', array($this, 'the_progress_meter'), 16);
64 64
 
65 65
         // provide an option to block all emails related to a selected course
66
-        add_filter( 'sensei_send_emails', array( $this, 'block_notification_emails' ) );
67
-        add_action( 'save_post', array( $this, 'save_course_notification_meta_box' ) );
66
+        add_filter('sensei_send_emails', array($this, 'block_notification_emails'));
67
+        add_action('save_post', array($this, 'save_course_notification_meta_box'));
68 68
 
69 69
         // preview lessons on the course content
70
-        add_action( 'sensei_course_content_inside_after',array( $this, 'the_course_free_lesson_preview' ) );
70
+        add_action('sensei_course_content_inside_after', array($this, 'the_course_free_lesson_preview'));
71 71
 
72 72
         // the course meta
73
-        add_action('sensei_course_content_inside_before', array( $this, 'the_course_meta' ) );
73
+        add_action('sensei_course_content_inside_before', array($this, 'the_course_meta'));
74 74
 
75 75
         // backwards compatible template hooks
76
-        add_action('sensei_course_content_inside_before', array( $this, 'content_before_backwards_compatibility_hooks' ));
77
-        add_action('sensei_loop_course_before', array( $this,'loop_before_backwards_compatibility_hooks' ) );
76
+        add_action('sensei_course_content_inside_before', array($this, 'content_before_backwards_compatibility_hooks'));
77
+        add_action('sensei_loop_course_before', array($this, 'loop_before_backwards_compatibility_hooks'));
78 78
 
79 79
         // add the user status on the course to the markup as a class
80
-        add_filter('post_class', array( __CLASS__ , 'add_course_user_status_class' ), 20, 3 );
80
+        add_filter('post_class', array(__CLASS__, 'add_course_user_status_class'), 20, 3);
81 81
 
82 82
         //filter the course query in Sensei specific instances
83
-        add_filter( 'pre_get_posts', array( __CLASS__, 'course_query_filter' ) );
83
+        add_filter('pre_get_posts', array(__CLASS__, 'course_query_filter'));
84 84
 
85 85
         //attache the sorting to the course archive
86
-        add_action ( 'sensei_archive_before_course_loop' , array( 'Sensei_Course', 'course_archive_sorting' ) );
86
+        add_action('sensei_archive_before_course_loop', array('Sensei_Course', 'course_archive_sorting'));
87 87
 
88 88
         //attach the filter links to the course archive
89
-        add_action ( 'sensei_archive_before_course_loop' , array( 'Sensei_Course', 'course_archive_filters' ) );
89
+        add_action('sensei_archive_before_course_loop', array('Sensei_Course', 'course_archive_filters'));
90 90
 
91 91
         //filter the course query when featured filter is applied
92
-        add_filter( 'pre_get_posts',  array( __CLASS__, 'course_archive_featured_filter'));
92
+        add_filter('pre_get_posts', array(__CLASS__, 'course_archive_featured_filter'));
93 93
 
94 94
         // handle the order by title post submission
95
-        add_filter( 'pre_get_posts',  array( __CLASS__, 'course_archive_order_by_title'));
95
+        add_filter('pre_get_posts', array(__CLASS__, 'course_archive_order_by_title'));
96 96
 
97 97
         // ensure the course category page respects the manual order set for courses
98
-        add_filter( 'pre_get_posts',  array( __CLASS__, 'alter_course_category_order'));
98
+        add_filter('pre_get_posts', array(__CLASS__, 'alter_course_category_order'));
99 99
 
100 100
         // flush rewrite rules when saving a course
101
-        add_action('save_post', array( 'Sensei_Course', 'flush_rewrite_rules' ) );
101
+        add_action('save_post', array('Sensei_Course', 'flush_rewrite_rules'));
102 102
 
103 103
 	} // End __construct()
104 104
 
@@ -108,10 +108,10 @@  discard block
 block discarded – undo
108 108
 	 * @param type $user_id
109 109
 	 * @param type $quiz_id
110 110
 	 */
111
-	public function update_status_after_quiz_submission( $user_id, $quiz_id ) {
112
-		if ( intval( $user_id ) > 0 && intval( $quiz_id ) > 0 ) {
113
-			$lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true );
114
-			$this->update_status_after_lesson_change( $user_id, $lesson_id );
111
+	public function update_status_after_quiz_submission($user_id, $quiz_id) {
112
+		if (intval($user_id) > 0 && intval($quiz_id) > 0) {
113
+			$lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true);
114
+			$this->update_status_after_lesson_change($user_id, $lesson_id);
115 115
 		}
116 116
 	}
117 117
 
@@ -121,12 +121,12 @@  discard block
 block discarded – undo
121 121
 	 * @param int $user_id
122 122
 	 * @param int $lesson_id
123 123
 	 */
124
-	public function update_status_after_lesson_change( $user_id, $lesson_id ) {
125
-		if ( intval( $user_id ) > 0 && intval( $lesson_id ) > 0 ) {
126
-			$course_id = get_post_meta( $lesson_id, '_lesson_course', true );
127
-			if ( intval( $course_id ) > 0 ) {
124
+	public function update_status_after_lesson_change($user_id, $lesson_id) {
125
+		if (intval($user_id) > 0 && intval($lesson_id) > 0) {
126
+			$course_id = get_post_meta($lesson_id, '_lesson_course', true);
127
+			if (intval($course_id) > 0) {
128 128
 				// Updates the Course status and it's meta data
129
-				Sensei_Utils::user_complete_course( $course_id, $user_id );
129
+				Sensei_Utils::user_complete_course($course_id, $user_id);
130 130
 			}
131 131
 		}
132 132
 	}
@@ -137,27 +137,27 @@  discard block
 block discarded – undo
137 137
 	 * @access public
138 138
 	 * @return void
139 139
 	 */
140
-	public function meta_box_setup () {
140
+	public function meta_box_setup() {
141 141
 
142
-		if ( Sensei_WC::is_woocommerce_active() ) {
142
+		if (Sensei_WC::is_woocommerce_active()) {
143 143
 			// Add Meta Box for WooCommerce Course
144
-			add_meta_box( 'course-wc-product', __( 'WooCommerce Product', 'woothemes-sensei' ), array( $this, 'course_woocommerce_product_meta_box_content' ), $this->token, 'side', 'default' );
144
+			add_meta_box('course-wc-product', __('WooCommerce Product', 'woothemes-sensei'), array($this, 'course_woocommerce_product_meta_box_content'), $this->token, 'side', 'default');
145 145
 		} // End If Statement
146 146
 		// Add Meta Box for Prerequisite Course
147
-		add_meta_box( 'course-prerequisite', __( 'Course Prerequisite', 'woothemes-sensei' ), array( $this, 'course_prerequisite_meta_box_content' ), $this->token, 'side', 'default' );
147
+		add_meta_box('course-prerequisite', __('Course Prerequisite', 'woothemes-sensei'), array($this, 'course_prerequisite_meta_box_content'), $this->token, 'side', 'default');
148 148
 		// Add Meta Box for Featured Course
149
-		add_meta_box( 'course-featured', __( 'Featured Course', 'woothemes-sensei' ), array( $this, 'course_featured_meta_box_content' ), $this->token, 'side', 'default' );
149
+		add_meta_box('course-featured', __('Featured Course', 'woothemes-sensei'), array($this, 'course_featured_meta_box_content'), $this->token, 'side', 'default');
150 150
 		// Add Meta Box for Course Meta
151
-		add_meta_box( 'course-video', __( 'Course Video', 'woothemes-sensei' ), array( $this, 'course_video_meta_box_content' ), $this->token, 'normal', 'default' );
151
+		add_meta_box('course-video', __('Course Video', 'woothemes-sensei'), array($this, 'course_video_meta_box_content'), $this->token, 'normal', 'default');
152 152
 		// Add Meta Box for Course Lessons
153
-		add_meta_box( 'course-lessons', __( 'Course Lessons', 'woothemes-sensei' ), array( $this, 'course_lessons_meta_box_content' ), $this->token, 'normal', 'default' );
153
+		add_meta_box('course-lessons', __('Course Lessons', 'woothemes-sensei'), array($this, 'course_lessons_meta_box_content'), $this->token, 'normal', 'default');
154 154
         // Add Meta Box to link to Manage Learners
155
-        add_meta_box( 'course-manage', __( 'Course Management', 'woothemes-sensei' ), array( $this, 'course_manage_meta_box_content' ), $this->token, 'side', 'default' );
155
+        add_meta_box('course-manage', __('Course Management', 'woothemes-sensei'), array($this, 'course_manage_meta_box_content'), $this->token, 'side', 'default');
156 156
         // Remove "Custom Settings" meta box.
157
-		remove_meta_box( 'woothemes-settings', $this->token, 'normal' );
157
+		remove_meta_box('woothemes-settings', $this->token, 'normal');
158 158
 
159 159
         // add Disable email notification box
160
-        add_meta_box( 'course-notifications', __( 'Course Notifications', 'woothemes-sensei' ), array( $this, 'course_notification_meta_box_content' ), 'course', 'normal', 'default' );
160
+        add_meta_box('course-notifications', __('Course Notifications', 'woothemes-sensei'), array($this, 'course_notification_meta_box_content'), 'course', 'normal', 'default');
161 161
 
162 162
 	} // End meta_box_setup()
163 163
 
@@ -167,58 +167,58 @@  discard block
 block discarded – undo
167 167
 	 * @access public
168 168
 	 * @return void
169 169
 	 */
170
-	public function course_woocommerce_product_meta_box_content () {
170
+	public function course_woocommerce_product_meta_box_content() {
171 171
 		global $post;
172 172
 
173
-		$select_course_woocommerce_product = get_post_meta( $post->ID, '_course_woocommerce_product', true );
173
+		$select_course_woocommerce_product = get_post_meta($post->ID, '_course_woocommerce_product', true);
174 174
 
175
-		$post_args = array(	'post_type' 		=> array( 'product', 'product_variation' ),
175
+		$post_args = array('post_type' 		=> array('product', 'product_variation'),
176 176
 							'posts_per_page' 		=> -1,
177 177
 							'orderby'         	=> 'title',
178 178
     						'order'           	=> 'DESC',
179 179
     						'exclude' 			=> $post->ID,
180
-    						'post_status'		=> array( 'publish', 'private', 'draft' ),
180
+    						'post_status'		=> array('publish', 'private', 'draft'),
181 181
     						'tax_query'			=> array(
182 182
 								array(
183 183
 									'taxonomy'	=> 'product_type',
184 184
 									'field'		=> 'slug',
185
-									'terms'		=> array( 'variable', 'grouped' ),
185
+									'terms'		=> array('variable', 'grouped'),
186 186
 									'operator'	=> 'NOT IN'
187 187
 								)
188 188
 							),
189 189
 							'suppress_filters' 	=> 0
190 190
 							);
191
-		$posts_array = get_posts( $post_args );
191
+		$posts_array = get_posts($post_args);
192 192
 
193 193
 		$html = '';
194 194
 
195
-		$html .= '<input type="hidden" name="' . esc_attr( 'woo_' . $this->token . '_noonce' ) . '" id="' . esc_attr( 'woo_' . $this->token . '_noonce' ) . '" value="' . esc_attr( wp_create_nonce( plugin_basename(__FILE__) ) ) . '" />';
195
+		$html .= '<input type="hidden" name="'.esc_attr('woo_'.$this->token.'_noonce').'" id="'.esc_attr('woo_'.$this->token.'_noonce').'" value="'.esc_attr(wp_create_nonce(plugin_basename(__FILE__))).'" />';
196 196
 
197
-		if ( count( $posts_array ) > 0 ) {
197
+		if (count($posts_array) > 0) {
198 198
 
199
-			$html .= '<select id="course-woocommerce-product-options" name="course_woocommerce_product" class="chosen_select widefat">' . "\n";
200
-			$html .= '<option value="-">' . __( 'None', 'woothemes-sensei' ) . '</option>';
199
+			$html .= '<select id="course-woocommerce-product-options" name="course_woocommerce_product" class="chosen_select widefat">'."\n";
200
+			$html .= '<option value="-">'.__('None', 'woothemes-sensei').'</option>';
201 201
 				$prev_parent_id = 0;
202
-				foreach ( $posts_array as $post_item ) {
202
+				foreach ($posts_array as $post_item) {
203 203
 
204
-					if ( 'product_variation' == $post_item->post_type ) {
204
+					if ('product_variation' == $post_item->post_type) {
205 205
 
206
-						$product_object = get_product( $post_item->ID );
207
-						$parent_id = wp_get_post_parent_id( $post_item->ID );
206
+						$product_object = get_product($post_item->ID);
207
+						$parent_id = wp_get_post_parent_id($post_item->ID);
208 208
 
209
-                        if( sensei_check_woocommerce_version( '2.1' ) ) {
210
-							$formatted_variation = wc_get_formatted_variation( $product_object->variation_data, true );
209
+                        if (sensei_check_woocommerce_version('2.1')) {
210
+							$formatted_variation = wc_get_formatted_variation($product_object->variation_data, true);
211 211
 
212 212
 						} else {
213 213
                             // fall back to pre wc 2.1
214
-							$formatted_variation = woocommerce_get_formatted_variation( $product_object->variation_data, true );
214
+							$formatted_variation = woocommerce_get_formatted_variation($product_object->variation_data, true);
215 215
 
216 216
 						}
217 217
 
218
-                        $product_name = ucwords( $formatted_variation );
219
-                        if( empty( $product_name ) ){
218
+                        $product_name = ucwords($formatted_variation);
219
+                        if (empty($product_name)) {
220 220
 
221
-                            $product_name = __( 'Variation #', 'woothemes-sensei' ) . $product_object->variation_id;
221
+                            $product_name = __('Variation #', 'woothemes-sensei').$product_object->variation_id;
222 222
 
223 223
                         }
224 224
 
@@ -231,47 +231,47 @@  discard block
 block discarded – undo
231 231
 					}
232 232
 
233 233
 					// Show variations in groups
234
-					if( $parent_id && $parent_id != $prev_parent_id ) {
234
+					if ($parent_id && $parent_id != $prev_parent_id) {
235 235
 
236
-						if( 0 != $prev_parent_id ) {
236
+						if (0 != $prev_parent_id) {
237 237
 
238 238
 							$html .= '</optgroup>';
239 239
 
240 240
 						}
241
-						$html .= '<optgroup label="' . get_the_title( $parent_id ) . '">';
241
+						$html .= '<optgroup label="'.get_the_title($parent_id).'">';
242 242
 						$prev_parent_id = $parent_id;
243 243
 
244
-					} elseif( ! $parent_id && 0 == $prev_parent_id ) {
244
+					} elseif ( ! $parent_id && 0 == $prev_parent_id) {
245 245
 
246 246
 						$html .= '</optgroup>';
247 247
 
248 248
 					}
249 249
 
250
-					$html .= '<option value="' . esc_attr( absint( $post_item->ID ) ) . '"' . selected( $post_item->ID, $select_course_woocommerce_product, false ) . '>' . esc_html( $product_name ) . '</option>' . "\n";
250
+					$html .= '<option value="'.esc_attr(absint($post_item->ID)).'"'.selected($post_item->ID, $select_course_woocommerce_product, false).'>'.esc_html($product_name).'</option>'."\n";
251 251
 
252 252
 				} // End For Loop
253 253
 
254
-			$html .= '</select>' . "\n";
255
-			if ( current_user_can( 'publish_product' )) {
254
+			$html .= '</select>'."\n";
255
+			if (current_user_can('publish_product')) {
256 256
 
257
-				$html .= '<p>' . "\n";
258
-					$html .= '<a href="' . admin_url( 'post-new.php?post_type=product' ) . '" title="' . esc_attr( __( 'Add a Product', 'woothemes-sensei' ) ) . '">' . __( 'Add a Product', 'woothemes-sensei' ) . '</a>' . "\n";
257
+				$html .= '<p>'."\n";
258
+					$html .= '<a href="'.admin_url('post-new.php?post_type=product').'" title="'.esc_attr(__('Add a Product', 'woothemes-sensei')).'">'.__('Add a Product', 'woothemes-sensei').'</a>'."\n";
259 259
 				$html .= '</p>'."\n";
260 260
 
261 261
 			} // End If Statement
262 262
 
263 263
 		} else {
264 264
 
265
-			if ( current_user_can( 'publish_product' )) {
265
+			if (current_user_can('publish_product')) {
266 266
 
267
-				$html .= '<p>' . "\n";
268
-					$html .= esc_html( __( 'No products exist yet.', 'woothemes-sensei' ) ) . '&nbsp;<a href="' . admin_url( 'post-new.php?post_type=product' ) . '" title="' . esc_attr( __( 'Add a Product', 'woothemes-sensei' ) ) . '">' . __( 'Please add some first', 'woothemes-sensei' ) . '</a>' . "\n";
267
+				$html .= '<p>'."\n";
268
+					$html .= esc_html(__('No products exist yet.', 'woothemes-sensei')).'&nbsp;<a href="'.admin_url('post-new.php?post_type=product').'" title="'.esc_attr(__('Add a Product', 'woothemes-sensei')).'">'.__('Please add some first', 'woothemes-sensei').'</a>'."\n";
269 269
 				$html .= '</p>'."\n";
270 270
 
271 271
 			} else {
272 272
 
273
-                $html .= '<p>' . "\n";
274
-					$html .= esc_html( __( 'No products exist yet.', 'woothemes-sensei' ) ) . "\n";
273
+                $html .= '<p>'."\n";
274
+					$html .= esc_html(__('No products exist yet.', 'woothemes-sensei'))."\n";
275 275
 				$html .= '</p>'."\n";
276 276
 
277 277
 			} // End If Statement
@@ -288,33 +288,33 @@  discard block
 block discarded – undo
288 288
 	 * @access public
289 289
 	 * @return void
290 290
 	 */
291
-	public function course_prerequisite_meta_box_content () {
291
+	public function course_prerequisite_meta_box_content() {
292 292
 		global $post;
293 293
 
294
-		$select_course_prerequisite = get_post_meta( $post->ID, '_course_prerequisite', true );
294
+		$select_course_prerequisite = get_post_meta($post->ID, '_course_prerequisite', true);
295 295
 
296
-		$post_args = array(	'post_type' 		=> 'course',
296
+		$post_args = array('post_type' 		=> 'course',
297 297
 							'posts_per_page' 		=> -1,
298 298
 							'orderby'         	=> 'title',
299 299
     						'order'           	=> 'DESC',
300 300
     						'exclude' 			=> $post->ID,
301 301
 							'suppress_filters' 	=> 0
302 302
 							);
303
-		$posts_array = get_posts( $post_args );
303
+		$posts_array = get_posts($post_args);
304 304
 
305 305
 		$html = '';
306 306
 
307
-		$html .= '<input type="hidden" name="' . esc_attr( 'woo_' . $this->token . '_noonce' ) . '" id="' . esc_attr( 'woo_' . $this->token . '_noonce' ) . '" value="' . esc_attr( wp_create_nonce( plugin_basename(__FILE__) ) ) . '" />';
307
+		$html .= '<input type="hidden" name="'.esc_attr('woo_'.$this->token.'_noonce').'" id="'.esc_attr('woo_'.$this->token.'_noonce').'" value="'.esc_attr(wp_create_nonce(plugin_basename(__FILE__))).'" />';
308 308
 
309
-		if ( count( $posts_array ) > 0 ) {
310
-			$html .= '<select id="course-prerequisite-options" name="course_prerequisite" class="chosen_select widefat">' . "\n";
311
-			$html .= '<option value="">' . __( 'None', 'woothemes-sensei' ) . '</option>';
312
-				foreach ($posts_array as $post_item){
313
-					$html .= '<option value="' . esc_attr( absint( $post_item->ID ) ) . '"' . selected( $post_item->ID, $select_course_prerequisite, false ) . '>' . esc_html( $post_item->post_title ) . '</option>' . "\n";
309
+		if (count($posts_array) > 0) {
310
+			$html .= '<select id="course-prerequisite-options" name="course_prerequisite" class="chosen_select widefat">'."\n";
311
+			$html .= '<option value="">'.__('None', 'woothemes-sensei').'</option>';
312
+				foreach ($posts_array as $post_item) {
313
+					$html .= '<option value="'.esc_attr(absint($post_item->ID)).'"'.selected($post_item->ID, $select_course_prerequisite, false).'>'.esc_html($post_item->post_title).'</option>'."\n";
314 314
 				} // End For Loop
315
-			$html .= '</select>' . "\n";
315
+			$html .= '</select>'."\n";
316 316
 		} else {
317
-			$html .= '<p>' . esc_html( __( 'No courses exist yet. Please add some first.', 'woothemes-sensei' ) ) . '</p>';
317
+			$html .= '<p>'.esc_html(__('No courses exist yet. Please add some first.', 'woothemes-sensei')).'</p>';
318 318
 		} // End If Statement
319 319
 
320 320
 		echo $html;
@@ -327,21 +327,21 @@  discard block
 block discarded – undo
327 327
 	 * @access public
328 328
 	 * @return void
329 329
 	 */
330
-	public function course_featured_meta_box_content () {
330
+	public function course_featured_meta_box_content() {
331 331
 		global $post;
332 332
 
333
-		$course_featured = get_post_meta( $post->ID, '_course_featured', true );
333
+		$course_featured = get_post_meta($post->ID, '_course_featured', true);
334 334
 
335 335
 		$html = '';
336 336
 
337
-		$html .= '<input type="hidden" name="' . esc_attr( 'woo_' . $this->token . '_noonce' ) . '" id="' . esc_attr( 'woo_' . $this->token . '_noonce' ) . '" value="' . esc_attr( wp_create_nonce( plugin_basename(__FILE__) ) ) . '" />';
337
+		$html .= '<input type="hidden" name="'.esc_attr('woo_'.$this->token.'_noonce').'" id="'.esc_attr('woo_'.$this->token.'_noonce').'" value="'.esc_attr(wp_create_nonce(plugin_basename(__FILE__))).'" />';
338 338
 
339 339
 		$checked = '';
340
-		if ( isset( $course_featured ) && ( '' != $course_featured ) ) {
341
-	 	    $checked = checked( 'featured', $course_featured, false );
340
+		if (isset($course_featured) && ('' != $course_featured)) {
341
+	 	    $checked = checked('featured', $course_featured, false);
342 342
 	 	} // End If Statement
343 343
 
344
-	 	$html .= '<input type="checkbox" name="course_featured" value="featured" ' . $checked . '>&nbsp;' . __( 'Feature this course', 'woothemes-sensei' ) . '<br>';
344
+	 	$html .= '<input type="checkbox" name="course_featured" value="featured" '.$checked.'>&nbsp;'.__('Feature this course', 'woothemes-sensei').'<br>';
345 345
 
346 346
 		echo $html;
347 347
 
@@ -353,16 +353,16 @@  discard block
 block discarded – undo
353 353
 	 * @access public
354 354
 	 * @return void
355 355
 	 */
356
-	public function course_video_meta_box_content () {
356
+	public function course_video_meta_box_content() {
357 357
 		global $post;
358 358
 
359
-		$course_video_embed = get_post_meta( $post->ID, '_course_video_embed', true );
359
+		$course_video_embed = get_post_meta($post->ID, '_course_video_embed', true);
360 360
 
361 361
 		$html = '';
362 362
 
363
-		$html .= '<label class="screen-reader-text" for="course_video_embed">' . __( 'Video Embed Code', 'woothemes-sensei' ) . '</label>';
364
-		$html .= '<textarea rows="5" cols="50" name="course_video_embed" tabindex="6" id="course-video-embed">' . $course_video_embed . '</textarea>';
365
-		$html .= '<p>' .  __( 'Paste the embed code for your video (e.g. YouTube, Vimeo etc.) in the box above.', 'woothemes-sensei' ) . '</p>';
363
+		$html .= '<label class="screen-reader-text" for="course_video_embed">'.__('Video Embed Code', 'woothemes-sensei').'</label>';
364
+		$html .= '<textarea rows="5" cols="50" name="course_video_embed" tabindex="6" id="course-video-embed">'.$course_video_embed.'</textarea>';
365
+		$html .= '<p>'.__('Paste the embed code for your video (e.g. YouTube, Vimeo etc.) in the box above.', 'woothemes-sensei').'</p>';
366 366
 
367 367
 		echo $html;
368 368
 
@@ -377,36 +377,36 @@  discard block
 block discarded – undo
377 377
 	 * @param int $post_id
378 378
 	 * @return int
379 379
 	 */
380
-	public function meta_box_save ( $post_id ) {
380
+	public function meta_box_save($post_id) {
381 381
 		global $post;
382 382
 
383 383
 		/* Verify the nonce before proceeding. */
384
-		if ( ( get_post_type() != $this->token ) || ! wp_verify_nonce( $_POST['woo_' . $this->token . '_noonce'], plugin_basename(__FILE__) ) ) {
384
+		if ((get_post_type() != $this->token) || ! wp_verify_nonce($_POST['woo_'.$this->token.'_noonce'], plugin_basename(__FILE__))) {
385 385
 			return $post_id;
386 386
 		}
387 387
 
388 388
 		/* Get the post type object. */
389
-		$post_type = get_post_type_object( $post->post_type );
389
+		$post_type = get_post_type_object($post->post_type);
390 390
 
391 391
 		/* Check if the current user has permission to edit the post. */
392
-		if ( !current_user_can( $post_type->cap->edit_post, $post_id ) ) {
392
+		if ( ! current_user_can($post_type->cap->edit_post, $post_id)) {
393 393
 			return $post_id;
394 394
 		} // End If Statement
395 395
 
396
-		if ( 'page' == $_POST['post_type'] ) {
397
-			if ( ! current_user_can( 'edit_page', $post_id ) ) {
396
+		if ('page' == $_POST['post_type']) {
397
+			if ( ! current_user_can('edit_page', $post_id)) {
398 398
 				return $post_id;
399 399
 			} // End If Statement
400 400
 		} else {
401
-			if ( ! current_user_can( 'edit_post', $post_id ) ) {
401
+			if ( ! current_user_can('edit_post', $post_id)) {
402 402
 				return $post_id;
403 403
 			} // End If Statement
404 404
 		} // End If Statement
405 405
 
406 406
 		// Save the post meta data fields
407
-		if ( isset($this->meta_fields) && is_array($this->meta_fields) ) {
408
-			foreach ( $this->meta_fields as $meta_key ) {
409
-				$this->save_post_meta( $meta_key, $post_id );
407
+		if (isset($this->meta_fields) && is_array($this->meta_fields)) {
408
+			foreach ($this->meta_fields as $meta_key) {
409
+				$this->save_post_meta($meta_key, $post_id);
410 410
 			} // End For Loop
411 411
 		} // End If Statement
412 412
 
@@ -423,18 +423,18 @@  discard block
 block discarded – undo
423 423
 	 * @param int $post_id (default: 0)
424 424
 	 * @return int new meta id | bool meta value saved status
425 425
 	 */
426
-	private function save_post_meta( $post_key = '', $post_id = 0 ) {
426
+	private function save_post_meta($post_key = '', $post_id = 0) {
427 427
 		// Get the meta key.
428
-		$meta_key = '_' . $post_key;
428
+		$meta_key = '_'.$post_key;
429 429
 		// Get the posted data and sanitize it for use as an HTML class.
430
-		if ( 'course_video_embed' == $post_key) {
431
-			$new_meta_value = esc_html( $_POST[$post_key] );
430
+		if ('course_video_embed' == $post_key) {
431
+			$new_meta_value = esc_html($_POST[$post_key]);
432 432
 		} else {
433
-			$new_meta_value = ( isset( $_POST[$post_key] ) ? sanitize_html_class( $_POST[$post_key] ) : '' );
433
+			$new_meta_value = (isset($_POST[$post_key]) ? sanitize_html_class($_POST[$post_key]) : '');
434 434
 		} // End If Statement
435 435
 
436 436
         // update field with the new value
437
-        return update_post_meta( $post_id, $meta_key, $new_meta_value );
437
+        return update_post_meta($post_id, $meta_key, $new_meta_value);
438 438
 
439 439
 	} // End save_post_meta()
440 440
 
@@ -444,31 +444,31 @@  discard block
 block discarded – undo
444 444
 	 * @access public
445 445
 	 * @return void
446 446
 	 */
447
-	public function course_lessons_meta_box_content () {
447
+	public function course_lessons_meta_box_content() {
448 448
 
449 449
 		global $post;
450 450
 
451 451
 		// Setup Lesson Query
452 452
 		$posts_array = array();
453
-		if ( 0 < $post->ID ) {
453
+		if (0 < $post->ID) {
454 454
 
455
-			$posts_array = $this->course_lessons( $post->ID, 'any' );
455
+			$posts_array = $this->course_lessons($post->ID, 'any');
456 456
 
457 457
 		} // End If Statement
458 458
 
459 459
 		$html = '';
460
-		$html .= '<input type="hidden" name="' . esc_attr( 'woo_' . $this->token . '_noonce' ) . '" id="'
461
-                 . esc_attr( 'woo_' . $this->token . '_noonce' )
462
-                 . '" value="' . esc_attr( wp_create_nonce( plugin_basename(__FILE__) ) ) . '" />';
460
+		$html .= '<input type="hidden" name="'.esc_attr('woo_'.$this->token.'_noonce').'" id="'
461
+                 . esc_attr('woo_'.$this->token.'_noonce')
462
+                 . '" value="'.esc_attr(wp_create_nonce(plugin_basename(__FILE__))).'" />';
463 463
 
464
-		if ( count( $posts_array ) > 0 ) {
464
+		if (count($posts_array) > 0) {
465 465
 
466
-			foreach ($posts_array as $post_item){
466
+			foreach ($posts_array as $post_item) {
467 467
 
468 468
 				$html .= '<p>'."\n";
469 469
 
470 470
 					$html .= $post_item->post_title."\n";
471
-					$html .= '<a href="' . esc_url( get_edit_post_link( $post_item->ID ) ) . '" title="' . esc_attr( sprintf( __( 'Edit %s', 'woothemes-sensei' ), $post_item->post_title ) ) . '" class="edit-lesson-action">' . __( 'Edit this lesson', 'woothemes-sensei' ) . '</a>';
471
+					$html .= '<a href="'.esc_url(get_edit_post_link($post_item->ID)).'" title="'.esc_attr(sprintf(__('Edit %s', 'woothemes-sensei'), $post_item->post_title)).'" class="edit-lesson-action">'.__('Edit this lesson', 'woothemes-sensei').'</a>';
472 472
 
473 473
 				$html .= '</p>'."\n";
474 474
 
@@ -476,12 +476,12 @@  discard block
 block discarded – undo
476 476
 
477 477
 		} else {
478 478
 			$course_id = '';
479
-			if ( 0 < $post->ID ) { $course_id = '&course_id=' . $post->ID; }
480
-			$html .= '<p>' . esc_html( __( 'No lessons exist yet for this course.', 'woothemes-sensei' ) ) . "\n";
479
+			if (0 < $post->ID) { $course_id = '&course_id='.$post->ID; }
480
+			$html .= '<p>'.esc_html(__('No lessons exist yet for this course.', 'woothemes-sensei'))."\n";
481 481
 
482
-				$html .= '<a href="' . admin_url( 'post-new.php?post_type=lesson' . $course_id )
483
-                         . '" title="' . esc_attr( __( 'Add a Lesson', 'woothemes-sensei' ) ) . '">'
484
-                         . __( 'Please add some.', 'woothemes-sensei' ) . '</a>' . "\n";
482
+				$html .= '<a href="'.admin_url('post-new.php?post_type=lesson'.$course_id)
483
+                         . '" title="'.esc_attr(__('Add a Lesson', 'woothemes-sensei')).'">'
484
+                         . __('Please add some.', 'woothemes-sensei').'</a>'."\n";
485 485
 
486 486
 			$html .= '</p>'."\n";
487 487
 		} // End If Statement
@@ -498,12 +498,12 @@  discard block
 block discarded – undo
498 498
      * @return void
499 499
      */
500 500
 
501
-    public function course_manage_meta_box_content () {
501
+    public function course_manage_meta_box_content() {
502 502
         global $post;
503 503
         
504
-        $manage_url = esc_url( add_query_arg( array( 'page' => 'sensei_learners', 'course_id' => $post->ID, 'view' => 'learners' ), admin_url( 'admin.php') ) );
504
+        $manage_url = esc_url(add_query_arg(array('page' => 'sensei_learners', 'course_id' => $post->ID, 'view' => 'learners'), admin_url('admin.php')));
505 505
 
506
-        $grading_url = esc_url( add_query_arg( array( 'page' => 'sensei_grading', 'course_id' => $post->ID, 'view' => 'learners' ), admin_url( 'admin.php') ) );
506
+        $grading_url = esc_url(add_query_arg(array('page' => 'sensei_grading', 'course_id' => $post->ID, 'view' => 'learners'), admin_url('admin.php')));
507 507
 
508 508
 
509 509
         echo "<ul><li><a href='$manage_url'>".__("Manage Learners", 'woothemes-sensei')."</a></li>";
@@ -521,16 +521,16 @@  discard block
 block discarded – undo
521 521
 	 * @param  array $defaults
522 522
 	 * @return array $new_columns
523 523
 	 */
524
-	public function add_column_headings ( $defaults ) {
524
+	public function add_column_headings($defaults) {
525 525
 		$new_columns['cb'] = '<input type="checkbox" />';
526 526
 		// $new_columns['id'] = __( 'ID' );
527
-		$new_columns['title'] = _x( 'Course Title', 'column name', 'woothemes-sensei' );
528
-		$new_columns['course-prerequisite'] = _x( 'Pre-requisite Course', 'column name', 'woothemes-sensei' );
529
-		if ( Sensei_WC::is_woocommerce_active() ) {
530
-			$new_columns['course-woocommerce-product'] = _x( 'WooCommerce Product', 'column name', 'woothemes-sensei' );
527
+		$new_columns['title'] = _x('Course Title', 'column name', 'woothemes-sensei');
528
+		$new_columns['course-prerequisite'] = _x('Pre-requisite Course', 'column name', 'woothemes-sensei');
529
+		if (Sensei_WC::is_woocommerce_active()) {
530
+			$new_columns['course-woocommerce-product'] = _x('WooCommerce Product', 'column name', 'woothemes-sensei');
531 531
 		} // End If Statement
532
-		$new_columns['course-category'] = _x( 'Category', 'column name', 'woothemes-sensei' );
533
-		if ( isset( $defaults['date'] ) ) {
532
+		$new_columns['course-category'] = _x('Category', 'column name', 'woothemes-sensei');
533
+		if (isset($defaults['date'])) {
534 534
 			$new_columns['date'] = $defaults['date'];
535 535
 		}
536 536
 
@@ -545,45 +545,45 @@  discard block
 block discarded – undo
545 545
 	 * @param  int $id
546 546
 	 * @return void
547 547
 	 */
548
-	public function add_column_data ( $column_name, $id ) {
548
+	public function add_column_data($column_name, $id) {
549 549
 		global $wpdb, $post;
550 550
 
551
-		switch ( $column_name ) {
551
+		switch ($column_name) {
552 552
 			case 'id':
553 553
 				echo $id;
554 554
 			break;
555 555
 
556 556
 			case 'course-prerequisite':
557
-				$course_prerequisite_id = get_post_meta( $id, '_course_prerequisite', true);
558
-				if ( 0 < absint( $course_prerequisite_id ) ) { echo '<a href="' . esc_url( get_edit_post_link( absint( $course_prerequisite_id ) ) ) . '" title="' . esc_attr( sprintf( __( 'Edit %s', 'woothemes-sensei' ), get_the_title( absint( $course_prerequisite_id ) ) ) ) . '">' . get_the_title( absint( $course_prerequisite_id ) ) . '</a>'; }
557
+				$course_prerequisite_id = get_post_meta($id, '_course_prerequisite', true);
558
+				if (0 < absint($course_prerequisite_id)) { echo '<a href="'.esc_url(get_edit_post_link(absint($course_prerequisite_id))).'" title="'.esc_attr(sprintf(__('Edit %s', 'woothemes-sensei'), get_the_title(absint($course_prerequisite_id)))).'">'.get_the_title(absint($course_prerequisite_id)).'</a>'; }
559 559
 
560 560
 			break;
561 561
 
562 562
 			case 'course-woocommerce-product':
563
-				if ( Sensei_WC::is_woocommerce_active() ) {
564
-					$course_woocommerce_product_id = get_post_meta( $id, '_course_woocommerce_product', true);
565
-					if ( 0 < absint( $course_woocommerce_product_id ) ) {
566
-						if ( 'product_variation' == get_post_type( $course_woocommerce_product_id ) ) {
567
-							$product_object = get_product( $course_woocommerce_product_id );
568
-							if( sensei_check_woocommerce_version( '2.1' ) ) {
569
-								$formatted_variation = wc_get_formatted_variation( $product_object->variation_data, true );
563
+				if (Sensei_WC::is_woocommerce_active()) {
564
+					$course_woocommerce_product_id = get_post_meta($id, '_course_woocommerce_product', true);
565
+					if (0 < absint($course_woocommerce_product_id)) {
566
+						if ('product_variation' == get_post_type($course_woocommerce_product_id)) {
567
+							$product_object = get_product($course_woocommerce_product_id);
568
+							if (sensei_check_woocommerce_version('2.1')) {
569
+								$formatted_variation = wc_get_formatted_variation($product_object->variation_data, true);
570 570
 							} else {
571
-								$formatted_variation = woocommerce_get_formatted_variation( $product_object->variation_data, true );
571
+								$formatted_variation = woocommerce_get_formatted_variation($product_object->variation_data, true);
572 572
 							}
573 573
 							$course_woocommerce_product_id = $product_object->parent->post->ID;
574
-							$product_name = $product_object->parent->post->post_title . '<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . ucwords( $formatted_variation );
574
+							$product_name = $product_object->parent->post->post_title.'<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.ucwords($formatted_variation);
575 575
 						} else {
576
-							$product_name = get_the_title( absint( $course_woocommerce_product_id ) );
576
+							$product_name = get_the_title(absint($course_woocommerce_product_id));
577 577
 						} // End If Statement
578
-						echo '<a href="' . esc_url( get_edit_post_link( absint( $course_woocommerce_product_id ) ) ) . '" title="' . esc_attr( sprintf( __( 'Edit %s', 'woothemes-sensei' ), $product_name ) ) . '">' . $product_name . '</a>';
578
+						echo '<a href="'.esc_url(get_edit_post_link(absint($course_woocommerce_product_id))).'" title="'.esc_attr(sprintf(__('Edit %s', 'woothemes-sensei'), $product_name)).'">'.$product_name.'</a>';
579 579
 					} // End If Statement
580 580
 				} // End If Statement
581 581
 			break;
582 582
 
583 583
 			case 'course-category':
584
-				$output = get_the_term_list( $id, 'course-category', '', ', ', '' );
585
-				if ( '' == $output ) {
586
-					$output = __( 'None', 'woothemes-sensei' );
584
+				$output = get_the_term_list($id, 'course-category', '', ', ', '');
585
+				if ('' == $output) {
586
+					$output = __('None', 'woothemes-sensei');
587 587
 				} // End If Statement
588 588
 				echo $output;
589 589
 			break;
@@ -603,29 +603,29 @@  discard block
 block discarded – undo
603 603
 	 * @param array $includes (default: array())
604 604
 	 * @return array
605 605
 	 */
606
-	public function course_query( $amount = 0, $type = 'default', $includes = array(), $excludes = array() ) {
607
-		global $my_courses_page ;
606
+	public function course_query($amount = 0, $type = 'default', $includes = array(), $excludes = array()) {
607
+		global $my_courses_page;
608 608
 
609 609
 		$results_array = array();
610 610
 
611
-		if( $my_courses_page ) { add_action( 'pre_get_posts', array( $this, 'filter_my_courses' ) ); }
611
+		if ($my_courses_page) { add_action('pre_get_posts', array($this, 'filter_my_courses')); }
612 612
 
613
-		$post_args = $this->get_archive_query_args( $type, $amount, $includes, $excludes );
613
+		$post_args = $this->get_archive_query_args($type, $amount, $includes, $excludes);
614 614
 
615 615
 		// get the posts
616
-		if( empty( $post_args ) ) {
616
+		if (empty($post_args)) {
617 617
 
618 618
 			return $results_array;
619 619
 
620
-		}else{
620
+		} else {
621 621
 
622 622
 			//reset the pagination as this widgets do not need it
623 623
 			$post_args['paged'] = 1;
624
-			$results_array = get_posts( $post_args );
624
+			$results_array = get_posts($post_args);
625 625
 
626 626
 		}
627 627
 
628
-		if( $my_courses_page ) { remove_action( 'pre_get_posts', array( $this, 'filter_my_courses' ) ); }
628
+		if ($my_courses_page) { remove_action('pre_get_posts', array($this, 'filter_my_courses')); }
629 629
 
630 630
 		return $results_array;
631 631
 
@@ -641,22 +641,22 @@  discard block
 block discarded – undo
641 641
 	 * @param array $includes (default: array())
642 642
 	 * @return array
643 643
 	 */
644
-	public function get_archive_query_args( $type = '', $amount = 0 , $includes = array(), $excludes = array() ) {
644
+	public function get_archive_query_args($type = '', $amount = 0, $includes = array(), $excludes = array()) {
645 645
 
646 646
 		global $wp_query;
647 647
 
648
-		if ( 0 == $amount && ( isset( Sensei()->settings->settings[ 'course_archive_amount' ] ) && 'usercourses' != $type && ( 0 < absint( Sensei()->settings->settings[ 'course_archive_amount' ] ) ) ) ) {
649
-			$amount = absint( Sensei()->settings->settings[ 'course_archive_amount' ] );
648
+		if (0 == $amount && (isset(Sensei()->settings->settings['course_archive_amount']) && 'usercourses' != $type && (0 < absint(Sensei()->settings->settings['course_archive_amount'])))) {
649
+			$amount = absint(Sensei()->settings->settings['course_archive_amount']);
650 650
 		} else {
651
-			if ( 0 == $amount) {
652
-				$amount = $wp_query->get( 'posts_per_page' );
651
+			if (0 == $amount) {
652
+				$amount = $wp_query->get('posts_per_page');
653 653
 			} // End If Statement
654 654
 		} // End If Statement
655 655
 
656
-        $stored_order = get_option( 'sensei_course_order', '' );
656
+        $stored_order = get_option('sensei_course_order', '');
657 657
         $order = 'ASC';
658 658
         $orderby = 'menu_order';
659
-        if( empty( $stored_order ) ){
659
+        if (empty($stored_order)) {
660 660
 
661 661
             $order = 'DESC';
662 662
             $orderby = 'date';
@@ -666,7 +666,7 @@  discard block
 block discarded – undo
666 666
 		switch ($type) {
667 667
 
668 668
 			case 'usercourses':
669
-				$post_args = array(	'post_type' 		=> 'course',
669
+				$post_args = array('post_type' 		=> 'course',
670 670
 									'orderby'         	=> $orderby,
671 671
     								'order'           	=> $order,
672 672
     								'post_status'      	=> 'publish',
@@ -707,7 +707,7 @@  discard block
 block discarded – undo
707 707
 				break;
708 708
 
709 709
 			case 'featuredcourses':
710
-                $post_args = array(	'post_type' 		=> 'course',
710
+                $post_args = array('post_type' 		=> 'course',
711 711
                                     'orderby'         	=> $orderby,
712 712
                                     'order'           	=> $order,
713 713
     								'post_status'      	=> 'publish',
@@ -719,7 +719,7 @@  discard block
 block discarded – undo
719 719
 									);
720 720
 				break;
721 721
 			default:
722
-				$post_args = array(	'post_type' 		=> 'course',
722
+				$post_args = array('post_type' 		=> 'course',
723 723
                                     'orderby'         	=> $orderby,
724 724
                                     'order'           	=> $order,
725 725
     								'post_status'      	=> 'publish',
@@ -731,13 +731,13 @@  discard block
 block discarded – undo
731 731
 		}
732 732
 
733 733
         $post_args['posts_per_page'] = $amount;
734
-        $paged = $wp_query->get( 'paged' );
735
-        $post_args['paged'] = empty( $paged) ? 1 : $paged;
734
+        $paged = $wp_query->get('paged');
735
+        $post_args['paged'] = empty($paged) ? 1 : $paged;
736 736
 
737
-        if( 'newcourses' == $type ){
737
+        if ('newcourses' == $type) {
738 738
 
739
-            $post_args[ 'orderby' ] = 'date';
740
-            $post_args[ 'order' ] = 'DESC';
739
+            $post_args['orderby'] = 'date';
740
+            $post_args['order'] = 'DESC';
741 741
         }
742 742
 
743 743
 		return $post_args;
@@ -759,35 +759,35 @@  discard block
 block discarded – undo
759 759
      *
760 760
 	 * @return string | void
761 761
 	 */
762
-	public function course_image( $course_id = 0, $width = '100', $height = '100', $return = false ) {
762
+	public function course_image($course_id = 0, $width = '100', $height = '100', $return = false) {
763 763
 
764
-        if( is_a( $course_id, 'WP_Post' ) ){
764
+        if (is_a($course_id, 'WP_Post')) {
765 765
             $course_id = $course_id->ID;
766 766
         }
767 767
 
768 768
 		$html = '';
769 769
 
770 770
 		// Get Width and Height settings
771
-		if ( ( $width == '100' ) && ( $height == '100' ) ) {
771
+		if (($width == '100') && ($height == '100')) {
772 772
 
773
-			if ( is_singular( 'course' ) ) {
773
+			if (is_singular('course')) {
774 774
 
775
-				if ( !Sensei()->settings->settings[ 'course_single_image_enable' ] ) {
775
+				if ( ! Sensei()->settings->settings['course_single_image_enable']) {
776 776
 					return '';
777 777
 				} // End If Statement
778 778
 				$image_thumb_size = 'course_single_image';
779
-				$dimensions = Sensei()->get_image_size( $image_thumb_size );
779
+				$dimensions = Sensei()->get_image_size($image_thumb_size);
780 780
 				$width = $dimensions['width'];
781 781
 				$height = $dimensions['height'];
782 782
 
783 783
 			} else {
784 784
 
785
-				if ( !Sensei()->settings->settings[ 'course_archive_image_enable' ] ) {
785
+				if ( ! Sensei()->settings->settings['course_archive_image_enable']) {
786 786
 					return '';
787 787
 				} // End If Statement
788 788
 
789 789
 				$image_thumb_size = 'course_archive_image';
790
-				$dimensions = Sensei()->get_image_size( $image_thumb_size );
790
+				$dimensions = Sensei()->get_image_size($image_thumb_size);
791 791
 				$width = $dimensions['width'];
792 792
 				$height = $dimensions['height'];
793 793
 
@@ -796,31 +796,31 @@  discard block
 block discarded – undo
796 796
 		} // End If Statement
797 797
 
798 798
 		$img_url = '';
799
-		if ( has_post_thumbnail( $course_id ) ) {
799
+		if (has_post_thumbnail($course_id)) {
800 800
    			// Get Featured Image
801
-   			$img_url = get_the_post_thumbnail( $course_id, array( $width, $height ), array( 'class' => 'woo-image thumbnail alignleft') );
801
+   			$img_url = get_the_post_thumbnail($course_id, array($width, $height), array('class' => 'woo-image thumbnail alignleft'));
802 802
  		} else {
803 803
 
804 804
 			// Check for a Lesson Image
805
-			$course_lessons = $this->course_lessons( $course_id );
805
+			$course_lessons = $this->course_lessons($course_id);
806 806
 
807
-			foreach ($course_lessons as $lesson_item){
808
-				if ( has_post_thumbnail( $lesson_item->ID ) ) {
807
+			foreach ($course_lessons as $lesson_item) {
808
+				if (has_post_thumbnail($lesson_item->ID)) {
809 809
 					// Get Featured Image
810
-					$img_url = get_the_post_thumbnail( $lesson_item->ID, array( $width, $height ), array( 'class' => 'woo-image thumbnail alignleft') );
811
-					if ( '' != $img_url ) {
810
+					$img_url = get_the_post_thumbnail($lesson_item->ID, array($width, $height), array('class' => 'woo-image thumbnail alignleft'));
811
+					if ('' != $img_url) {
812 812
 						break;
813 813
 					} // End If Statement
814 814
 
815 815
 				} // End If Statement
816 816
 			} // End For Loop
817 817
 
818
- 			if ( '' == $img_url ) {
818
+ 			if ('' == $img_url) {
819 819
 
820 820
  				// Display Image Placeholder if none
821
-				if ( Sensei()->settings->get( 'placeholder_images_enable' ) ) {
821
+				if (Sensei()->settings->get('placeholder_images_enable')) {
822 822
 
823
-                    $img_url = apply_filters( 'sensei_course_placeholder_image_url', '<img src="http://placehold.it/' . $width . 'x' . $height . '" class="woo-image thumbnail alignleft" />' );
823
+                    $img_url = apply_filters('sensei_course_placeholder_image_url', '<img src="http://placehold.it/'.$width.'x'.$height.'" class="woo-image thumbnail alignleft" />');
824 824
 
825 825
 				} // End If Statement
826 826
 
@@ -828,17 +828,17 @@  discard block
 block discarded – undo
828 828
 
829 829
 		} // End If Statement
830 830
 
831
-		if ( '' != $img_url ) {
831
+		if ('' != $img_url) {
832 832
 
833
-			$html .= '<a href="' . get_permalink( $course_id ) . '" title="' . esc_attr( get_post_field( 'post_title', $course_id ) ) . '">' . $img_url  .'</a>';
833
+			$html .= '<a href="'.get_permalink($course_id).'" title="'.esc_attr(get_post_field('post_title', $course_id)).'">'.$img_url.'</a>';
834 834
 
835 835
 		} // End If Statement
836 836
 
837
-        if( $return ){
837
+        if ($return) {
838 838
 
839 839
             return $html;
840 840
 
841
-        }else{
841
+        } else {
842 842
 
843 843
             echo $html;
844 844
 
@@ -855,9 +855,9 @@  discard block
 block discarded – undo
855 855
 	 * @param string $post_status (default: 'publish')
856 856
 	 * @return int
857 857
 	 */
858
-	public function course_count( $post_status = 'publish' ) {
858
+	public function course_count($post_status = 'publish') {
859 859
 
860
-		$post_args = array(	'post_type'         => 'course',
860
+		$post_args = array('post_type'         => 'course',
861 861
 							'posts_per_page'    => -1,
862 862
 //							'orderby'           => 'menu_order date',
863 863
 //							'order'             => 'ASC',
@@ -868,10 +868,10 @@  discard block
 block discarded – undo
868 868
 
869 869
 		// Allow WP to generate the complex final query, just shortcut to only do an overall count
870 870
 //		add_filter( 'posts_clauses', array( 'WooThemes_Sensei_Utils', 'get_posts_count_only_filter' ) );
871
-		$courses_query = new WP_Query( apply_filters( 'sensei_course_count', $post_args ) );
871
+		$courses_query = new WP_Query(apply_filters('sensei_course_count', $post_args));
872 872
 //		remove_filter( 'posts_clauses', array( 'WooThemes_Sensei_Utils', 'get_posts_count_only_filter' ) );
873 873
 
874
-		return count( $courses_query->posts );
874
+		return count($courses_query->posts);
875 875
 	} // End course_count()
876 876
 
877 877
 
@@ -884,42 +884,42 @@  discard block
 block discarded – undo
884 884
 	 * @param string $fields (default: 'all'). WP only allows 3 types, but we will limit it to only 'ids' or 'all'
885 885
 	 * @return array{ type WP_Post }  $posts_array
886 886
 	 */
887
-	public function course_lessons( $course_id = 0, $post_status = 'publish', $fields = 'all' ) {
887
+	public function course_lessons($course_id = 0, $post_status = 'publish', $fields = 'all') {
888 888
 
889
-        if( is_a( $course_id, 'WP_Post' ) ){
889
+        if (is_a($course_id, 'WP_Post')) {
890 890
             $course_id = $course_id->ID;
891 891
         }
892 892
 
893
-		$post_args = array(	'post_type'         => 'lesson',
893
+		$post_args = array('post_type'         => 'lesson',
894 894
 							'posts_per_page'       => -1,
895 895
 							'orderby'           => 'date',
896 896
 							'order'             => 'ASC',
897 897
 							'meta_query'        => array(
898 898
 								array(
899 899
 									'key' => '_lesson_course',
900
-									'value' => intval( $course_id ),
900
+									'value' => intval($course_id),
901 901
 								),
902 902
 							),
903 903
 							'post_status'       => $post_status,
904 904
 							'suppress_filters'  => 0,
905 905
 							);
906
-		$query_results = new WP_Query( $post_args );
906
+		$query_results = new WP_Query($post_args);
907 907
         $lessons = $query_results->posts;
908 908
 
909 909
         // re order the lessons. This could not be done via the OR meta query as there may be lessons
910 910
         // with the course order for a different course and this should not be included. It could also not
911 911
         // be done via the AND meta query as it excludes lesson that does not have the _order_$course_id but
912 912
         // that have been added to the course.
913
-        if( count( $lessons) > 1  ){
913
+        if (count($lessons) > 1) {
914 914
 
915
-            foreach( $lessons as $lesson ){
915
+            foreach ($lessons as $lesson) {
916 916
 
917
-                $order = intval( get_post_meta( $lesson->ID, '_order_'. $course_id, true ) );
917
+                $order = intval(get_post_meta($lesson->ID, '_order_'.$course_id, true));
918 918
                 // for lessons with no order set it to be 10000 so that it show up at the end
919 919
                 $lesson->course_order = $order ? $order : 100000;
920 920
             }
921 921
 
922
-            uasort( $lessons, array( $this, '_short_course_lessons_callback' )   );
922
+            uasort($lessons, array($this, '_short_course_lessons_callback'));
923 923
         }
924 924
 
925 925
         /**
@@ -930,12 +930,12 @@  discard block
 block discarded – undo
930 930
          * @param array $lessons
931 931
          * @param int $course_id
932 932
          */
933
-        $lessons = apply_filters( 'sensei_course_get_lessons', $lessons, $course_id  );
933
+        $lessons = apply_filters('sensei_course_get_lessons', $lessons, $course_id);
934 934
 
935 935
         //return the requested fields
936 936
         // runs after the sensei_course_get_lessons filter so the filter always give an array of lesson
937 937
         // objects
938
-        if( 'ids' == $fields ) {
938
+        if ('ids' == $fields) {
939 939
             $lesson_objects = $lessons;
940 940
             $lessons = array();
941 941
 
@@ -957,9 +957,9 @@  discard block
 block discarded – undo
957 957
      * @param array $lesson_2
958 958
      * @return int
959 959
      */
960
-    protected function _short_course_lessons_callback( $lesson_1, $lesson_2 ){
960
+    protected function _short_course_lessons_callback($lesson_1, $lesson_2) {
961 961
 
962
-        if ( $lesson_1->course_order == $lesson_2->course_order ) {
962
+        if ($lesson_1->course_order == $lesson_2->course_order) {
963 963
             return 0;
964 964
         }
965 965
 
@@ -973,21 +973,21 @@  discard block
 block discarded – undo
973 973
 	 * @param  boolean $boolean_check True if a simple yes/no is required
974 974
 	 * @return array              Array of quiz post objects
975 975
 	 */
976
-	public function course_quizzes( $course_id = 0, $boolean_check = false ) {
976
+	public function course_quizzes($course_id = 0, $boolean_check = false) {
977 977
 
978 978
 
979 979
 		$course_quizzes = array();
980 980
 
981
-		if( $course_id ) {
982
-			$lesson_ids = Sensei()->course->course_lessons( $course_id, 'any', 'ids' );
981
+		if ($course_id) {
982
+			$lesson_ids = Sensei()->course->course_lessons($course_id, 'any', 'ids');
983 983
 
984
-			foreach( $lesson_ids as $lesson_id ) {
985
-				$has_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true );
986
-				if ( $has_questions && $boolean_check ) {
984
+			foreach ($lesson_ids as $lesson_id) {
985
+				$has_questions = get_post_meta($lesson_id, '_quiz_has_questions', true);
986
+				if ($has_questions && $boolean_check) {
987 987
 					return true;
988 988
 				}
989
-				elseif ( $has_questions ) {
990
-					$quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
989
+				elseif ($has_questions) {
990
+					$quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id);
991 991
 //					$questions = Sensei()->lesson->lesson_quiz_questions( $quiz_id );
992 992
 //					if( count( $questions ) > 0 ) {
993 993
 						$course_quizzes[] = $quiz_id;
@@ -995,7 +995,7 @@  discard block
 block discarded – undo
995 995
 				}
996 996
 			}
997 997
 		}
998
-		if ( $boolean_check && empty($course_quizzes) ) {
998
+		if ($boolean_check && empty($course_quizzes)) {
999 999
 			$course_quizzes = false;
1000 1000
 		}
1001 1001
 		return $course_quizzes;
@@ -1010,9 +1010,9 @@  discard block
 block discarded – undo
1010 1010
 	 * @param  string $post_status (default: 'publish')
1011 1011
 	 * @return array
1012 1012
 	 */
1013
-	public function course_lessons_completed( $course_id = 0, $post_status = 'publish' ) {
1013
+	public function course_lessons_completed($course_id = 0, $post_status = 'publish') {
1014 1014
 
1015
-		return $this->course_lessons( $course_id, $post_status );
1015
+		return $this->course_lessons($course_id, $post_status);
1016 1016
 
1017 1017
 	} // End course_lessons_completed()
1018 1018
 
@@ -1025,9 +1025,9 @@  discard block
 block discarded – undo
1025 1025
 	 * @param  int $course_id (default: 0)
1026 1026
 	 * @return int
1027 1027
 	 */
1028
-	public function course_author_lesson_count( $author_id = 0, $course_id = 0 ) {
1028
+	public function course_author_lesson_count($author_id = 0, $course_id = 0) {
1029 1029
 
1030
-        $lesson_args = array(	'post_type' 		=> 'lesson',
1030
+        $lesson_args = array('post_type' 		=> 'lesson',
1031 1031
 								'posts_per_page' 		=> -1,
1032 1032
 		    					'author'         	=> $author_id,
1033 1033
 		    					'meta_key'        	=> '_lesson_course',
@@ -1036,8 +1036,8 @@  discard block
 block discarded – undo
1036 1036
     	    					'suppress_filters' 	=> 0,
1037 1037
 								'fields'            => 'ids', // less data to retrieve
1038 1038
 		    				);
1039
-		$lessons_array = get_posts( $lesson_args );
1040
-		$count = count( $lessons_array );
1039
+		$lessons_array = get_posts($lesson_args);
1040
+		$count = count($lessons_array);
1041 1041
 		return $count;
1042 1042
 
1043 1043
 	} // End course_author_lesson_count()
@@ -1049,9 +1049,9 @@  discard block
 block discarded – undo
1049 1049
 	 * @param  int $course_id (default: 0)
1050 1050
 	 * @return int
1051 1051
 	 */
1052
-	public function course_lesson_count( $course_id = 0 ) {
1052
+	public function course_lesson_count($course_id = 0) {
1053 1053
 
1054
-		$lesson_args = array(	'post_type' 		=> 'lesson',
1054
+		$lesson_args = array('post_type' 		=> 'lesson',
1055 1055
 								'posts_per_page' 		=> -1,
1056 1056
 		    					'meta_key'        	=> '_lesson_course',
1057 1057
     							'meta_value'      	=> $course_id,
@@ -1059,9 +1059,9 @@  discard block
 block discarded – undo
1059 1059
     	    					'suppress_filters' 	=> 0,
1060 1060
 								'fields'            => 'ids', // less data to retrieve
1061 1061
 		    				);
1062
-		$lessons_array = get_posts( $lesson_args );
1062
+		$lessons_array = get_posts($lesson_args);
1063 1063
 
1064
-        $count = count( $lessons_array );
1064
+        $count = count($lessons_array);
1065 1065
 
1066 1066
         return $count;
1067 1067
 
@@ -1074,9 +1074,9 @@  discard block
 block discarded – undo
1074 1074
 	 * @param  int $course_id (default: 0)
1075 1075
 	 * @return int
1076 1076
 	 */
1077
-	public function course_lesson_preview_count( $course_id = 0 ) {
1077
+	public function course_lesson_preview_count($course_id = 0) {
1078 1078
 
1079
-		$lesson_args = array(	'post_type' 		=> 'lesson',
1079
+		$lesson_args = array('post_type' 		=> 'lesson',
1080 1080
 								'posts_per_page' 		=> -1,
1081 1081
     	    					'post_status'      	=> 'publish',
1082 1082
     	    					'suppress_filters' 	=> 0,
@@ -1092,9 +1092,9 @@  discard block
 block discarded – undo
1092 1092
 								),
1093 1093
 								'fields'            => 'ids', // less data to retrieve
1094 1094
 		    				);
1095
-		$lessons_array = get_posts( $lesson_args );
1095
+		$lessons_array = get_posts($lesson_args);
1096 1096
 
1097
-		$count = count( $lessons_array );
1097
+		$count = count($lessons_array);
1098 1098
 
1099 1099
         return $count;
1100 1100
 
@@ -1107,12 +1107,12 @@  discard block
 block discarded – undo
1107 1107
 	 * @param  int $product_id (default: 0)
1108 1108
 	 * @return array
1109 1109
 	 */
1110
-	public function get_product_courses( $product_id = 0 ) {
1110
+	public function get_product_courses($product_id = 0) {
1111 1111
 
1112 1112
 		$posts_array = array();
1113 1113
 		// Check for WooCommerce
1114
-		if ( Sensei_WC::is_woocommerce_active() && 0 < $product_id ) {
1115
-			$post_args = array(	'post_type' 		=> 'course',
1114
+		if (Sensei_WC::is_woocommerce_active() && 0 < $product_id) {
1115
+			$post_args = array('post_type' 		=> 'course',
1116 1116
 								'posts_per_page' 		=> -1,
1117 1117
 								'meta_key'        	=> '_course_woocommerce_product',
1118 1118
 	    						'meta_value'      	=> $product_id,
@@ -1121,7 +1121,7 @@  discard block
 block discarded – undo
1121 1121
 								'orderby' 			=> 'menu_order date',
1122 1122
 								'order' 			=> 'ASC',
1123 1123
 								);
1124
-			$posts_array = get_posts( $post_args );
1124
+			$posts_array = get_posts($post_args);
1125 1125
 		} // End If Statement
1126 1126
 		return $posts_array;
1127 1127
 
@@ -1141,17 +1141,17 @@  discard block
 block discarded – undo
1141 1141
 	 * @param  WP_Query $query
1142 1142
 	 * @return void
1143 1143
 	 */
1144
-	public function filter_my_courses( $query ) {
1144
+	public function filter_my_courses($query) {
1145 1145
 		global  $my_courses_section;
1146 1146
 
1147
-		if ( isset( Sensei()->settings->settings[ 'my_course_amount' ] ) && ( 0 < absint( Sensei()->settings->settings[ 'my_course_amount' ] ) ) ) {
1148
-			$amount = absint( Sensei()->settings->settings[ 'my_course_amount' ] );
1149
-			$query->set( 'posts_per_page', $amount );
1147
+		if (isset(Sensei()->settings->settings['my_course_amount']) && (0 < absint(Sensei()->settings->settings['my_course_amount']))) {
1148
+			$amount = absint(Sensei()->settings->settings['my_course_amount']);
1149
+			$query->set('posts_per_page', $amount);
1150 1150
 		}
1151 1151
 
1152
-		if( isset( $_GET[ $my_courses_section . '_page' ] ) && 0 < intval( $_GET[ $my_courses_section . '_page' ] ) ) {
1153
-			$page = intval( $_GET[ $my_courses_section . '_page' ] );
1154
-			$query->set( 'paged', $page );
1152
+		if (isset($_GET[$my_courses_section.'_page']) && 0 < intval($_GET[$my_courses_section.'_page'])) {
1153
+			$page = intval($_GET[$my_courses_section.'_page']);
1154
+			$query->set('paged', $page);
1155 1155
 		}
1156 1156
 	}
1157 1157
 
@@ -1165,48 +1165,48 @@  discard block
 block discarded – undo
1165 1165
 	 * @param  boolean $manage Whether the user has permission to manage the courses
1166 1166
 	 * @return string          HTML displayng course data
1167 1167
 	 */
1168
-	public function load_user_courses_content( $user = false ) {
1168
+	public function load_user_courses_content($user = false) {
1169 1169
 		global $course, $my_courses_page, $my_courses_section;
1170 1170
 
1171
-        if( ! isset( Sensei()->settings->settings[ 'learner_profile_show_courses' ] )
1172
-            || ! Sensei()->settings->settings[ 'learner_profile_show_courses' ] ) {
1171
+        if ( ! isset(Sensei()->settings->settings['learner_profile_show_courses'])
1172
+            || ! Sensei()->settings->settings['learner_profile_show_courses']) {
1173 1173
 
1174 1174
             // do not show the content if the settings doesn't allow for it
1175 1175
             return;
1176 1176
 
1177 1177
         }
1178 1178
 
1179
-        $manage = ( $user->ID == get_current_user_id() ) ? true : false;
1179
+        $manage = ($user->ID == get_current_user_id()) ? true : false;
1180 1180
 
1181
-        do_action( 'sensei_before_learner_course_content', $user );
1181
+        do_action('sensei_before_learner_course_content', $user);
1182 1182
 
1183 1183
 		// Build Output HTML
1184 1184
 		$complete_html = $active_html = '';
1185 1185
 
1186
-		if( is_a( $user, 'WP_User' ) ) {
1186
+		if (is_a($user, 'WP_User')) {
1187 1187
 
1188 1188
 			$my_courses_page = true;
1189 1189
 
1190 1190
 			// Allow action to be run before My Courses content has loaded
1191
-			do_action( 'sensei_before_my_courses', $user->ID );
1191
+			do_action('sensei_before_my_courses', $user->ID);
1192 1192
 
1193 1193
 			// Logic for Active and Completed Courses
1194 1194
 			$per_page = 20;
1195
-			if ( isset( Sensei()->settings->settings[ 'my_course_amount' ] )
1196
-                && ( 0 < absint( Sensei()->settings->settings[ 'my_course_amount' ] ) ) ) {
1195
+			if (isset(Sensei()->settings->settings['my_course_amount'])
1196
+                && (0 < absint(Sensei()->settings->settings['my_course_amount']))) {
1197 1197
 
1198
-				$per_page = absint( Sensei()->settings->settings[ 'my_course_amount' ] );
1198
+				$per_page = absint(Sensei()->settings->settings['my_course_amount']);
1199 1199
 
1200 1200
 			}
1201 1201
 
1202
-			$course_statuses = Sensei_Utils::sensei_check_for_activity( array( 'user_id' => $user->ID, 'type' => 'sensei_course_status' ), true );
1202
+			$course_statuses = Sensei_Utils::sensei_check_for_activity(array('user_id' => $user->ID, 'type' => 'sensei_course_status'), true);
1203 1203
 			// User may only be on 1 Course
1204
-			if ( !is_array($course_statuses) ) {
1205
-				$course_statuses = array( $course_statuses );
1204
+			if ( ! is_array($course_statuses)) {
1205
+				$course_statuses = array($course_statuses);
1206 1206
 			}
1207 1207
 			$completed_ids = $active_ids = array();
1208
-			foreach( $course_statuses as $course_status ) {
1209
-				if ( Sensei_Utils::user_completed_course( $course_status, $user->ID ) ) {
1208
+			foreach ($course_statuses as $course_status) {
1209
+				if (Sensei_Utils::user_completed_course($course_status, $user->ID)) {
1210 1210
 					$completed_ids[] = $course_status->comment_post_ID;
1211 1211
 				} else {
1212 1212
 					$active_ids[] = $course_status->comment_post_ID;
@@ -1216,41 +1216,41 @@  discard block
 block discarded – undo
1216 1216
 			$active_count = $completed_count = 0;
1217 1217
 
1218 1218
 			$active_courses = array();
1219
-			if ( 0 < intval( count( $active_ids ) ) ) {
1219
+			if (0 < intval(count($active_ids))) {
1220 1220
 				$my_courses_section = 'active';
1221
-				$active_courses = Sensei()->course->course_query( $per_page, 'usercourses', $active_ids );
1222
-				$active_count = count( $active_ids );
1221
+				$active_courses = Sensei()->course->course_query($per_page, 'usercourses', $active_ids);
1222
+				$active_count = count($active_ids);
1223 1223
 			} // End If Statement
1224 1224
 
1225 1225
 			$completed_courses = array();
1226
-			if ( 0 < intval( count( $completed_ids ) ) ) {
1226
+			if (0 < intval(count($completed_ids))) {
1227 1227
 				$my_courses_section = 'completed';
1228
-				$completed_courses = Sensei()->course->course_query( $per_page, 'usercourses', $completed_ids );
1229
-				$completed_count = count( $completed_ids );
1228
+				$completed_courses = Sensei()->course->course_query($per_page, 'usercourses', $completed_ids);
1229
+				$completed_count = count($completed_ids);
1230 1230
 			} // End If Statement
1231 1231
 
1232
-			foreach ( $active_courses as $course_item ) {
1232
+			foreach ($active_courses as $course_item) {
1233 1233
 
1234
-				$course_lessons =  Sensei()->course->course_lessons( $course_item->ID );
1234
+				$course_lessons = Sensei()->course->course_lessons($course_item->ID);
1235 1235
 				$lessons_completed = 0;
1236
-				foreach ( $course_lessons as $lesson ) {
1237
-					if ( Sensei_Utils::user_completed_lesson( $lesson->ID, $user->ID ) ) {
1236
+				foreach ($course_lessons as $lesson) {
1237
+					if (Sensei_Utils::user_completed_lesson($lesson->ID, $user->ID)) {
1238 1238
 						++$lessons_completed;
1239 1239
 					}
1240 1240
 				}
1241 1241
 
1242 1242
 			    // Get Course Categories
1243
-			    $category_output = get_the_term_list( $course_item->ID, 'course-category', '', ', ', '' );
1243
+			    $category_output = get_the_term_list($course_item->ID, 'course-category', '', ', ', '');
1244 1244
 
1245
-                $active_html .= '<article class="' . esc_attr( join( ' ', get_post_class( array( 'course', 'post' ), $course_item->ID ) ) ) . '">';
1245
+                $active_html .= '<article class="'.esc_attr(join(' ', get_post_class(array('course', 'post'), $course_item->ID))).'">';
1246 1246
 
1247 1247
                 // Image
1248
-                $active_html .= Sensei()->course->course_image( absint( $course_item->ID ), '100','100', true );
1248
+                $active_html .= Sensei()->course->course_image(absint($course_item->ID), '100', '100', true);
1249 1249
 
1250 1250
                 // Title
1251 1251
                 $active_html .= '<header>';
1252 1252
 
1253
-                $active_html .= '<h2><a href="' . esc_url( get_permalink( absint( $course_item->ID ) ) ) . '" title="' . esc_attr( $course_item->post_title ) . '">' . esc_html( $course_item->post_title ) . '</a></h2>';
1253
+                $active_html .= '<h2><a href="'.esc_url(get_permalink(absint($course_item->ID))).'" title="'.esc_attr($course_item->post_title).'">'.esc_html($course_item->post_title).'</a></h2>';
1254 1254
 
1255 1255
                 $active_html .= '</header>';
1256 1256
 
@@ -1259,82 +1259,82 @@  discard block
 block discarded – undo
1259 1259
                 $active_html .= '<p class="sensei-course-meta">';
1260 1260
 
1261 1261
                 // Author
1262
-                $user_info = get_userdata( absint( $course_item->post_author ) );
1263
-                if ( isset( Sensei()->settings->settings[ 'course_author' ] )
1264
-                    && ( Sensei()->settings->settings[ 'course_author' ] ) ) {
1262
+                $user_info = get_userdata(absint($course_item->post_author));
1263
+                if (isset(Sensei()->settings->settings['course_author'])
1264
+                    && (Sensei()->settings->settings['course_author'])) {
1265 1265
 
1266 1266
                     $active_html .= '<span class="course-author">'
1267
-                        . __( 'by ', 'woothemes-sensei' )
1268
-                        . '<a href="' . esc_url( get_author_posts_url( absint( $course_item->post_author ) ) )
1269
-                        . '" title="' . esc_attr( $user_info->display_name ) . '">'
1270
-                        . esc_html( $user_info->display_name )
1267
+                        . __('by ', 'woothemes-sensei')
1268
+                        . '<a href="'.esc_url(get_author_posts_url(absint($course_item->post_author)))
1269
+                        . '" title="'.esc_attr($user_info->display_name).'">'
1270
+                        . esc_html($user_info->display_name)
1271 1271
                         . '</a></span>';
1272 1272
 
1273 1273
                 } // End If Statement
1274 1274
 
1275 1275
                 // Lesson count for this author
1276
-                $lesson_count = Sensei()->course->course_lesson_count( absint( $course_item->ID ) );
1276
+                $lesson_count = Sensei()->course->course_lesson_count(absint($course_item->ID));
1277 1277
                 // Handle Division by Zero
1278
-                if ( 0 == $lesson_count ) {
1278
+                if (0 == $lesson_count) {
1279 1279
 
1280 1280
                     $lesson_count = 1;
1281 1281
 
1282 1282
                 } // End If Statement
1283
-                $active_html .= '<span class="course-lesson-count">' . $lesson_count . '&nbsp;' .  __( 'Lessons', 'woothemes-sensei' ) . '</span>';
1283
+                $active_html .= '<span class="course-lesson-count">'.$lesson_count.'&nbsp;'.__('Lessons', 'woothemes-sensei').'</span>';
1284 1284
                 // Course Categories
1285
-                if ( '' != $category_output ) {
1285
+                if ('' != $category_output) {
1286 1286
 
1287
-                    $active_html .= '<span class="course-category">' . sprintf( __( 'in %s', 'woothemes-sensei' ), $category_output ) . '</span>';
1287
+                    $active_html .= '<span class="course-category">'.sprintf(__('in %s', 'woothemes-sensei'), $category_output).'</span>';
1288 1288
 
1289 1289
                 } // End If Statement
1290
-                $active_html .= '<span class="course-lesson-progress">' . sprintf( __( '%1$d of %2$d lessons completed', 'woothemes-sensei' ) , $lessons_completed, $lesson_count  ) . '</span>';
1290
+                $active_html .= '<span class="course-lesson-progress">'.sprintf(__('%1$d of %2$d lessons completed', 'woothemes-sensei'), $lessons_completed, $lesson_count).'</span>';
1291 1291
 
1292 1292
                 $active_html .= '</p>';
1293 1293
 
1294
-                $active_html .= '<p class="course-excerpt">' . $course_item->post_excerpt . '</p>';
1294
+                $active_html .= '<p class="course-excerpt">'.$course_item->post_excerpt.'</p>';
1295 1295
 
1296 1296
 
1297 1297
 
1298
-                $progress_percentage = abs( round( ( doubleval( $lessons_completed ) * 100 ) / ( $lesson_count ), 0 ) );
1298
+                $progress_percentage = abs(round((doubleval($lessons_completed) * 100) / ($lesson_count), 0));
1299 1299
 
1300
-                $active_html .= $this->get_progress_meter( $progress_percentage );
1300
+                $active_html .= $this->get_progress_meter($progress_percentage);
1301 1301
 
1302 1302
                 $active_html .= '</section>';
1303 1303
 
1304
-                if( is_user_logged_in() ) {
1304
+                if (is_user_logged_in()) {
1305 1305
 
1306 1306
                     $active_html .= '<section class="entry-actions">';
1307 1307
 
1308
-                    $active_html .= '<form method="POST" action="' . esc_url( remove_query_arg( array( 'active_page', 'completed_page' ) ) ) . '">';
1308
+                    $active_html .= '<form method="POST" action="'.esc_url(remove_query_arg(array('active_page', 'completed_page'))).'">';
1309 1309
 
1310
-                    $active_html .= '<input type="hidden" name="' . esc_attr( 'woothemes_sensei_complete_course_noonce' ) . '" id="' . esc_attr( 'woothemes_sensei_complete_course_noonce' ) . '" value="' . esc_attr( wp_create_nonce( 'woothemes_sensei_complete_course_noonce' ) ) . '" />';
1310
+                    $active_html .= '<input type="hidden" name="'.esc_attr('woothemes_sensei_complete_course_noonce').'" id="'.esc_attr('woothemes_sensei_complete_course_noonce').'" value="'.esc_attr(wp_create_nonce('woothemes_sensei_complete_course_noonce')).'" />';
1311 1311
 
1312
-                    $active_html .= '<input type="hidden" name="course_complete_id" id="course-complete-id" value="' . esc_attr( absint( $course_item->ID ) ) . '" />';
1312
+                    $active_html .= '<input type="hidden" name="course_complete_id" id="course-complete-id" value="'.esc_attr(absint($course_item->ID)).'" />';
1313 1313
 
1314
-                    if ( 0 < absint( count( $course_lessons ) ) && Sensei()->settings->settings['course_completion'] == 'complete' ) {
1314
+                    if (0 < absint(count($course_lessons)) && Sensei()->settings->settings['course_completion'] == 'complete') {
1315 1315
 
1316 1316
                         $active_html .= '<span><input name="course_complete" type="submit" class="course-complete" value="'
1317
-                            .  __( 'Mark as Complete', 'woothemes-sensei' ) . '"/> </span>';
1317
+                            .  __('Mark as Complete', 'woothemes-sensei').'"/> </span>';
1318 1318
 
1319 1319
                     } // End If Statement
1320 1320
 
1321 1321
                     $course_purchased = false;
1322
-                    if ( Sensei_WC::is_woocommerce_active() ) {
1322
+                    if (Sensei_WC::is_woocommerce_active()) {
1323 1323
 
1324 1324
                         // Get the product ID
1325
-                        $wc_post_id = get_post_meta( absint( $course_item->ID ), '_course_woocommerce_product', true );
1326
-                        if ( 0 < $wc_post_id ) {
1325
+                        $wc_post_id = get_post_meta(absint($course_item->ID), '_course_woocommerce_product', true);
1326
+                        if (0 < $wc_post_id) {
1327 1327
 
1328
-                            $course_purchased = Sensei_WC::has_customer_bought_product(  $user->ID, $wc_post_id );
1328
+                            $course_purchased = Sensei_WC::has_customer_bought_product($user->ID, $wc_post_id);
1329 1329
 
1330 1330
                         } // End If Statement
1331 1331
 
1332 1332
                     } // End If Statement
1333 1333
 
1334
-                    if ( false == $course_purchased ) {
1334
+                    if (false == $course_purchased) {
1335 1335
 
1336 1336
                         $active_html .= '<span><input name="course_complete" type="submit" class="course-delete" value="'
1337
-                            .  __( 'Delete Course', 'woothemes-sensei' ) . '"/></span>';
1337
+                            .  __('Delete Course', 'woothemes-sensei').'"/></span>';
1338 1338
 
1339 1339
                     } // End If Statement
1340 1340
 
@@ -1347,54 +1347,54 @@  discard block
 block discarded – undo
1347 1347
 			}
1348 1348
 
1349 1349
 			// Active pagination
1350
-			if( $active_count > $per_page ) {
1350
+			if ($active_count > $per_page) {
1351 1351
 
1352 1352
 				$current_page = 1;
1353
-				if( isset( $_GET['active_page'] ) && 0 < intval( $_GET['active_page'] ) ) {
1353
+				if (isset($_GET['active_page']) && 0 < intval($_GET['active_page'])) {
1354 1354
 					$current_page = $_GET['active_page'];
1355 1355
 				}
1356 1356
 
1357 1357
 				$active_html .= '<nav class="pagination woo-pagination">';
1358
-				$total_pages = ceil( $active_count / $per_page );
1358
+				$total_pages = ceil($active_count / $per_page);
1359 1359
 
1360
-				if( $current_page > 1 ) {
1361
-					$prev_link = add_query_arg( 'active_page', $current_page - 1 );
1362
-					$active_html .= '<a class="prev page-numbers" href="' . esc_url( $prev_link ) . '">' . __( 'Previous' , 'woothemes-sensei' ) . '</a> ';
1360
+				if ($current_page > 1) {
1361
+					$prev_link = add_query_arg('active_page', $current_page - 1);
1362
+					$active_html .= '<a class="prev page-numbers" href="'.esc_url($prev_link).'">'.__('Previous', 'woothemes-sensei').'</a> ';
1363 1363
 				}
1364 1364
 
1365
-				for ( $i = 1; $i <= $total_pages; $i++ ) {
1366
-					$link = add_query_arg( 'active_page', $i );
1365
+				for ($i = 1; $i <= $total_pages; $i++) {
1366
+					$link = add_query_arg('active_page', $i);
1367 1367
 
1368
-					if( $i == $current_page ) {
1369
-						$active_html .= '<span class="page-numbers current">' . $i . '</span> ';
1368
+					if ($i == $current_page) {
1369
+						$active_html .= '<span class="page-numbers current">'.$i.'</span> ';
1370 1370
 					} else {
1371
-						$active_html .= '<a class="page-numbers" href="' . esc_url( $link ). '">' . $i . '</a> ';
1371
+						$active_html .= '<a class="page-numbers" href="'.esc_url($link).'">'.$i.'</a> ';
1372 1372
 					}
1373 1373
 				}
1374 1374
 
1375
-				if( $current_page < $total_pages ) {
1376
-					$next_link = add_query_arg( 'active_page', $current_page + 1 );
1377
-					$active_html .= '<a class="next page-numbers" href="' . esc_url( $next_link ) . '">' . __( 'Next' , 'woothemes-sensei' ) . '</a> ';
1375
+				if ($current_page < $total_pages) {
1376
+					$next_link = add_query_arg('active_page', $current_page + 1);
1377
+					$active_html .= '<a class="next page-numbers" href="'.esc_url($next_link).'">'.__('Next', 'woothemes-sensei').'</a> ';
1378 1378
 				}
1379 1379
 
1380 1380
 				$active_html .= '</nav>';
1381 1381
 			}
1382 1382
 
1383
-			foreach ( $completed_courses as $course_item ) {
1383
+			foreach ($completed_courses as $course_item) {
1384 1384
 				$course = $course_item;
1385 1385
 
1386 1386
 			    // Get Course Categories
1387
-			    $category_output = get_the_term_list( $course_item->ID, 'course-category', '', ', ', '' );
1387
+			    $category_output = get_the_term_list($course_item->ID, 'course-category', '', ', ', '');
1388 1388
 
1389
-		    	$complete_html .= '<article class="' . join( ' ', get_post_class( array( 'course', 'post' ), $course_item->ID ) ) . '">';
1389
+		    	$complete_html .= '<article class="'.join(' ', get_post_class(array('course', 'post'), $course_item->ID)).'">';
1390 1390
 
1391 1391
 		    	    // Image
1392
-		    		$complete_html .= Sensei()->course->course_image( absint( $course_item->ID ),100, 100, true );
1392
+		    		$complete_html .= Sensei()->course->course_image(absint($course_item->ID), 100, 100, true);
1393 1393
 
1394 1394
 		    		// Title
1395 1395
 		    		$complete_html .= '<header>';
1396 1396
 
1397
-		    		    $complete_html .= '<h2><a href="' . esc_url( get_permalink( absint( $course_item->ID ) ) ) . '" title="' . esc_attr( $course_item->post_title ) . '">' . esc_html( $course_item->post_title ) . '</a></h2>';
1397
+		    		    $complete_html .= '<h2><a href="'.esc_url(get_permalink(absint($course_item->ID))).'" title="'.esc_attr($course_item->post_title).'">'.esc_html($course_item->post_title).'</a></h2>';
1398 1398
 
1399 1399
 		    		$complete_html .= '</header>';
1400 1400
 
@@ -1403,46 +1403,46 @@  discard block
 block discarded – undo
1403 1403
 		    			$complete_html .= '<p class="sensei-course-meta">';
1404 1404
 
1405 1405
 		    		    	// Author
1406
-		    		    	$user_info = get_userdata( absint( $course_item->post_author ) );
1407
-		    		    	if ( isset( Sensei()->settings->settings[ 'course_author' ] ) && ( Sensei()->settings->settings[ 'course_author' ] ) ) {
1408
-		    		    		$complete_html .= '<span class="course-author">' . __( 'by ', 'woothemes-sensei' ) . '<a href="' . esc_url( get_author_posts_url( absint( $course_item->post_author ) ) ) . '" title="' . esc_attr( $user_info->display_name ) . '">' . esc_html( $user_info->display_name ) . '</a></span>';
1406
+		    		    	$user_info = get_userdata(absint($course_item->post_author));
1407
+		    		    	if (isset(Sensei()->settings->settings['course_author']) && (Sensei()->settings->settings['course_author'])) {
1408
+		    		    		$complete_html .= '<span class="course-author">'.__('by ', 'woothemes-sensei').'<a href="'.esc_url(get_author_posts_url(absint($course_item->post_author))).'" title="'.esc_attr($user_info->display_name).'">'.esc_html($user_info->display_name).'</a></span>';
1409 1409
 		    		    	} // End If Statement
1410 1410
 
1411 1411
 		    		    	// Lesson count for this author
1412 1412
 		    		    	$complete_html .= '<span class="course-lesson-count">'
1413
-                                . Sensei()->course->course_lesson_count( absint( $course_item->ID ) )
1414
-                                . '&nbsp;' .  __( 'Lessons', 'woothemes-sensei' )
1413
+                                . Sensei()->course->course_lesson_count(absint($course_item->ID))
1414
+                                . '&nbsp;'.__('Lessons', 'woothemes-sensei')
1415 1415
                                 . '</span>';
1416 1416
 
1417 1417
 		    		    	// Course Categories
1418
-		    		    	if ( '' != $category_output ) {
1418
+		    		    	if ('' != $category_output) {
1419 1419
 
1420
-		    		    		$complete_html .= '<span class="course-category">' . sprintf( __( 'in %s', 'woothemes-sensei' ), $category_output ) . '</span>';
1420
+		    		    		$complete_html .= '<span class="course-category">'.sprintf(__('in %s', 'woothemes-sensei'), $category_output).'</span>';
1421 1421
 
1422 1422
 		    		    	} // End If Statement
1423 1423
 
1424 1424
 						$complete_html .= '</p>';
1425 1425
 
1426
-						$complete_html .= '<p class="course-excerpt">' . $course_item->post_excerpt . '</p>';
1426
+						$complete_html .= '<p class="course-excerpt">'.$course_item->post_excerpt.'</p>';
1427 1427
 
1428
-                        $complete_html .= $this->get_progress_meter( 100 );
1428
+                        $complete_html .= $this->get_progress_meter(100);
1429 1429
 
1430
-						if( $manage ) {
1431
-							$has_quizzes = Sensei()->course->course_quizzes( $course_item->ID, true );
1430
+						if ($manage) {
1431
+							$has_quizzes = Sensei()->course->course_quizzes($course_item->ID, true);
1432 1432
 							// Output only if there is content to display
1433
-							if ( has_filter( 'sensei_results_links' ) || $has_quizzes ) {
1433
+							if (has_filter('sensei_results_links') || $has_quizzes) {
1434 1434
 
1435 1435
 
1436 1436
 								$complete_html .= '<p class="sensei-results-links">';
1437 1437
 								$results_link = '';
1438
-								if( $has_quizzes ) {
1438
+								if ($has_quizzes) {
1439 1439
 
1440 1440
 									$results_link = '<a class="button view-results" href="'
1441
-                                        . Sensei()->course_results->get_permalink( $course_item->ID )
1442
-                                        . '">' . __( 'View results', 'woothemes-sensei' )
1441
+                                        . Sensei()->course_results->get_permalink($course_item->ID)
1442
+                                        . '">'.__('View results', 'woothemes-sensei')
1443 1443
                                         . '</a>';
1444 1444
 								}
1445
-								$complete_html .= apply_filters( 'sensei_results_links', $results_link );
1445
+								$complete_html .= apply_filters('sensei_results_links', $results_link);
1446 1446
 								$complete_html .= '</p>';
1447 1447
 
1448 1448
 							}
@@ -1454,35 +1454,35 @@  discard block
 block discarded – undo
1454 1454
 			}
1455 1455
 
1456 1456
 			// Active pagination
1457
-			if( $completed_count > $per_page ) {
1457
+			if ($completed_count > $per_page) {
1458 1458
 
1459 1459
 				$current_page = 1;
1460
-				if( isset( $_GET['completed_page'] ) && 0 < intval( $_GET['completed_page'] ) ) {
1460
+				if (isset($_GET['completed_page']) && 0 < intval($_GET['completed_page'])) {
1461 1461
 					$current_page = $_GET['completed_page'];
1462 1462
 				}
1463 1463
 
1464 1464
 				$complete_html .= '<nav class="pagination woo-pagination">';
1465
-				$total_pages = ceil( $completed_count / $per_page );
1465
+				$total_pages = ceil($completed_count / $per_page);
1466 1466
 
1467 1467
 
1468
-				if( $current_page > 1 ) {
1469
-					$prev_link = add_query_arg( 'completed_page', $current_page - 1 );
1470
-					$complete_html .= '<a class="prev page-numbers" href="' . esc_url( $prev_link ) . '">' . __( 'Previous' , 'woothemes-sensei' ) . '</a> ';
1468
+				if ($current_page > 1) {
1469
+					$prev_link = add_query_arg('completed_page', $current_page - 1);
1470
+					$complete_html .= '<a class="prev page-numbers" href="'.esc_url($prev_link).'">'.__('Previous', 'woothemes-sensei').'</a> ';
1471 1471
 				}
1472 1472
 
1473
-				for ( $i = 1; $i <= $total_pages; $i++ ) {
1474
-					$link = add_query_arg( 'completed_page', $i );
1473
+				for ($i = 1; $i <= $total_pages; $i++) {
1474
+					$link = add_query_arg('completed_page', $i);
1475 1475
 
1476
-					if( $i == $current_page ) {
1477
-						$complete_html .= '<span class="page-numbers current">' . $i . '</span> ';
1476
+					if ($i == $current_page) {
1477
+						$complete_html .= '<span class="page-numbers current">'.$i.'</span> ';
1478 1478
 					} else {
1479
-						$complete_html .= '<a class="page-numbers" href="' . esc_url( $link ) . '">' . $i . '</a> ';
1479
+						$complete_html .= '<a class="page-numbers" href="'.esc_url($link).'">'.$i.'</a> ';
1480 1480
 					}
1481 1481
 				}
1482 1482
 
1483
-				if( $current_page < $total_pages ) {
1484
-					$next_link = add_query_arg( 'completed_page', $current_page + 1 );
1485
-					$complete_html .= '<a class="next page-numbers" href="' . esc_url( $next_link ) . '">' . __( 'Next' , 'woothemes-sensei' ) . '</a> ';
1483
+				if ($current_page < $total_pages) {
1484
+					$next_link = add_query_arg('completed_page', $current_page + 1);
1485
+					$complete_html .= '<a class="next page-numbers" href="'.esc_url($next_link).'">'.__('Next', 'woothemes-sensei').'</a> ';
1486 1486
 				}
1487 1487
 
1488 1488
 				$complete_html .= '</nav>';
@@ -1490,26 +1490,26 @@  discard block
 block discarded – undo
1490 1490
 
1491 1491
 		} // End If Statement
1492 1492
 
1493
-		if( $manage ) {
1494
-			$no_active_message = __( 'You have no active courses.', 'woothemes-sensei' );
1495
-			$no_complete_message = __( 'You have not completed any courses yet.', 'woothemes-sensei' );
1493
+		if ($manage) {
1494
+			$no_active_message = __('You have no active courses.', 'woothemes-sensei');
1495
+			$no_complete_message = __('You have not completed any courses yet.', 'woothemes-sensei');
1496 1496
 		} else {
1497
-			$no_active_message =  __( 'This learner has no active courses.', 'woothemes-sensei' );
1498
-			$no_complete_message =  __( 'This learner has not completed any courses yet.', 'woothemes-sensei' );
1497
+			$no_active_message = __('This learner has no active courses.', 'woothemes-sensei');
1498
+			$no_complete_message = __('This learner has not completed any courses yet.', 'woothemes-sensei');
1499 1499
 		}
1500 1500
 
1501 1501
 		ob_start();
1502 1502
 		?>
1503 1503
 
1504
-		<?php do_action( 'sensei_before_user_courses' ); ?>
1504
+		<?php do_action('sensei_before_user_courses'); ?>
1505 1505
 
1506 1506
 		<?php
1507
-		if( $manage && ( ! isset( Sensei()->settings->settings['messages_disable'] ) || ! Sensei()->settings->settings['messages_disable'] ) ) {
1507
+		if ($manage && ( ! isset(Sensei()->settings->settings['messages_disable']) || ! Sensei()->settings->settings['messages_disable'])) {
1508 1508
 			?>
1509 1509
 			<p class="my-messages-link-container">
1510
-                <a class="my-messages-link" href="<?php echo get_post_type_archive_link( 'sensei_message' ); ?>"
1511
-                   title="<?php _e( 'View & reply to private messages sent to your course & lesson teachers.', 'woothemes-sensei' ); ?>">
1512
-                    <?php _e( 'My Messages', 'woothemes-sensei' ); ?>
1510
+                <a class="my-messages-link" href="<?php echo get_post_type_archive_link('sensei_message'); ?>"
1511
+                   title="<?php _e('View & reply to private messages sent to your course & lesson teachers.', 'woothemes-sensei'); ?>">
1512
+                    <?php _e('My Messages', 'woothemes-sensei'); ?>
1513 1513
                 </a>
1514 1514
             </p>
1515 1515
 			<?php
@@ -1518,11 +1518,11 @@  discard block
 block discarded – undo
1518 1518
 		<div id="my-courses">
1519 1519
 
1520 1520
 		    <ul>
1521
-		    	<li><a href="#active-courses"><?php  _e( 'Active Courses', 'woothemes-sensei' ); ?></a></li>
1522
-		    	<li><a href="#completed-courses"><?php  _e( 'Completed Courses', 'woothemes-sensei' ); ?></a></li>
1521
+		    	<li><a href="#active-courses"><?php  _e('Active Courses', 'woothemes-sensei'); ?></a></li>
1522
+		    	<li><a href="#completed-courses"><?php  _e('Completed Courses', 'woothemes-sensei'); ?></a></li>
1523 1523
 		    </ul>
1524 1524
 
1525
-		    <?php do_action( 'sensei_before_active_user_courses' ); ?>
1525
+		    <?php do_action('sensei_before_active_user_courses'); ?>
1526 1526
 
1527 1527
 		    <?php
1528 1528
             $course_page_url = Sensei_Course::get_courses_page_url();
@@ -1530,7 +1530,7 @@  discard block
 block discarded – undo
1530 1530
 
1531 1531
 		    <div id="active-courses">
1532 1532
 
1533
-		    	<?php if ( '' != $active_html ) {
1533
+		    	<?php if ('' != $active_html) {
1534 1534
 
1535 1535
 		    		echo $active_html;
1536 1536
 
@@ -1542,7 +1542,7 @@  discard block
 block discarded – undo
1542 1542
 
1543 1543
                         <a href="<?php echo $course_page_url; ?>">
1544 1544
 
1545
-                            <?php  _e( 'Start a Course!', 'woothemes-sensei' ); ?>
1545
+                            <?php  _e('Start a Course!', 'woothemes-sensei'); ?>
1546 1546
 
1547 1547
                         </a>
1548 1548
 
@@ -1552,13 +1552,13 @@  discard block
 block discarded – undo
1552 1552
 
1553 1553
 		    </div>
1554 1554
 
1555
-		    <?php do_action( 'sensei_after_active_user_courses' ); ?>
1555
+		    <?php do_action('sensei_after_active_user_courses'); ?>
1556 1556
 
1557
-		    <?php do_action( 'sensei_before_completed_user_courses' ); ?>
1557
+		    <?php do_action('sensei_before_completed_user_courses'); ?>
1558 1558
 
1559 1559
 		    <div id="completed-courses">
1560 1560
 
1561
-		    	<?php if ( '' != $complete_html ) {
1561
+		    	<?php if ('' != $complete_html) {
1562 1562
 
1563 1563
 		    		echo $complete_html;
1564 1564
 
@@ -1574,16 +1574,16 @@  discard block
 block discarded – undo
1574 1574
 
1575 1575
 		    </div>
1576 1576
 
1577
-		    <?php do_action( 'sensei_after_completed_user_courses' ); ?>
1577
+		    <?php do_action('sensei_after_completed_user_courses'); ?>
1578 1578
 
1579 1579
 		</div>
1580 1580
 
1581
-		<?php do_action( 'sensei_after_user_courses' ); ?>
1581
+		<?php do_action('sensei_after_user_courses'); ?>
1582 1582
 
1583 1583
 		<?php
1584 1584
         echo ob_get_clean();
1585 1585
 
1586
-        do_action( 'sensei_after_learner_course_content', $user );
1586
+        do_action('sensei_after_learner_course_content', $user);
1587 1587
 
1588 1588
 	} // end load_user_courses_content
1589 1589
 
@@ -1595,7 +1595,7 @@  discard block
 block discarded – undo
1595 1595
      *  @type $course WP_Post
1596 1596
      * }
1597 1597
      */
1598
-    public static function get_all_courses(){
1598
+    public static function get_all_courses() {
1599 1599
 
1600 1600
         $args = array(
1601 1601
                'post_type' => 'course',
@@ -1606,7 +1606,7 @@  discard block
 block discarded – undo
1606 1606
                 'suppress_filters' 	=> 0,
1607 1607
         );
1608 1608
 
1609
-        $wp_query_obj =  new WP_Query( $args );
1609
+        $wp_query_obj = new WP_Query($args);
1610 1610
 
1611 1611
         /**
1612 1612
          * sensei_get_all_courses filter
@@ -1618,7 +1618,7 @@  discard block
 block discarded – undo
1618 1618
          * }
1619 1619
          * @param array $attributes
1620 1620
          */
1621
-        return apply_filters( 'sensei_get_all_courses' , $wp_query_obj->posts );
1621
+        return apply_filters('sensei_get_all_courses', $wp_query_obj->posts);
1622 1622
 
1623 1623
     }// end get_all_courses
1624 1624
 
@@ -1629,16 +1629,16 @@  discard block
 block discarded – undo
1629 1629
      * @param int $progress_percentage 0 - 100
1630 1630
      * @return string $progress_bar_html
1631 1631
      */
1632
-    public function get_progress_meter( $progress_percentage ){
1632
+    public function get_progress_meter($progress_percentage) {
1633 1633
 
1634
-        if ( 50 < $progress_percentage ) {
1634
+        if (50 < $progress_percentage) {
1635 1635
             $class = ' green';
1636
-        } elseif ( 25 <= $progress_percentage && 50 >= $progress_percentage ) {
1636
+        } elseif (25 <= $progress_percentage && 50 >= $progress_percentage) {
1637 1637
             $class = ' orange';
1638 1638
         } else {
1639 1639
             $class = ' red';
1640 1640
         }
1641
-        $progress_bar_html = '<div class="meter' . esc_attr( $class ) . '"><span style="width: ' . $progress_percentage . '%">' . round( $progress_percentage ) . '%</span></div>';
1641
+        $progress_bar_html = '<div class="meter'.esc_attr($class).'"><span style="width: '.$progress_percentage.'%">'.round($progress_percentage).'%</span></div>';
1642 1642
 
1643 1643
         return $progress_bar_html;
1644 1644
 
@@ -1653,17 +1653,17 @@  discard block
 block discarded – undo
1653 1653
      *
1654 1654
      * @return string $statement_html
1655 1655
      */
1656
-    public function get_progress_statement( $course_id, $user_id ){
1656
+    public function get_progress_statement($course_id, $user_id) {
1657 1657
 
1658
-        if( empty( $course_id ) || empty( $user_id )
1659
-        || ! Sensei_Utils::user_started_course( $course_id, $user_id ) ){
1658
+        if (empty($course_id) || empty($user_id)
1659
+        || ! Sensei_Utils::user_started_course($course_id, $user_id)) {
1660 1660
             return '';
1661 1661
         }
1662 1662
 
1663
-        $completed = count( $this->get_completed_lesson_ids( $course_id, $user_id ) );
1664
-        $total_lessons = count( $this->course_lessons( $course_id ) );
1663
+        $completed = count($this->get_completed_lesson_ids($course_id, $user_id));
1664
+        $total_lessons = count($this->course_lessons($course_id));
1665 1665
 
1666
-        $statement = sprintf( _n('Currently completed %s lesson of %s in total', 'Currently completed %s lessons of %s in total', $completed, 'woothemes-sensei'), $completed, $total_lessons );
1666
+        $statement = sprintf(_n('Currently completed %s lesson of %s in total', 'Currently completed %s lessons of %s in total', $completed, 'woothemes-sensei'), $completed, $total_lessons);
1667 1667
 
1668 1668
         /**
1669 1669
          * Filter the course completion statement.
@@ -1671,7 +1671,7 @@  discard block
 block discarded – undo
1671 1671
          *
1672 1672
          * @param string $statement
1673 1673
          */
1674
-        return apply_filters( 'sensei_course_completion_statement', $statement );
1674
+        return apply_filters('sensei_course_completion_statement', $statement);
1675 1675
 
1676 1676
     }// end generate_progress_statement
1677 1677
 
@@ -1681,17 +1681,17 @@  discard block
 block discarded – undo
1681 1681
      * @param $course_id
1682 1682
      * @return void
1683 1683
      */
1684
-    public function the_progress_statement( $course_id = 0, $user_id = 0 ){
1685
-        if( empty( $course_id ) ){
1684
+    public function the_progress_statement($course_id = 0, $user_id = 0) {
1685
+        if (empty($course_id)) {
1686 1686
             global $post;
1687 1687
             $course_id = $post->ID;
1688 1688
         }
1689 1689
 
1690
-        if( empty( $user_id ) ){
1690
+        if (empty($user_id)) {
1691 1691
             $user_id = get_current_user_id();
1692 1692
         }
1693 1693
 
1694
-        echo '<span class="progress statement  course-completion-rate">' . $this->get_progress_statement( $course_id, $user_id  ) . '</span>';
1694
+        echo '<span class="progress statement  course-completion-rate">'.$this->get_progress_statement($course_id, $user_id).'</span>';
1695 1695
     }
1696 1696
 
1697 1697
     /**
@@ -1700,24 +1700,24 @@  discard block
 block discarded – undo
1700 1700
      * @param $course_id
1701 1701
      * @return void
1702 1702
      */
1703
-    public function the_progress_meter( $course_id = 0, $user_id = 0 ){
1703
+    public function the_progress_meter($course_id = 0, $user_id = 0) {
1704 1704
 
1705
-        if( empty( $course_id ) ){
1705
+        if (empty($course_id)) {
1706 1706
             global $post;
1707 1707
             $course_id = $post->ID;
1708 1708
         }
1709 1709
 
1710
-        if( empty( $user_id ) ){
1710
+        if (empty($user_id)) {
1711 1711
             $user_id = get_current_user_id();
1712 1712
         }
1713 1713
 
1714
-        if( 'course' != get_post_type( $course_id ) || ! get_userdata( $user_id )
1715
-            || ! Sensei_Utils::user_started_course( $course_id ,$user_id ) ){
1714
+        if ('course' != get_post_type($course_id) || ! get_userdata($user_id)
1715
+            || ! Sensei_Utils::user_started_course($course_id, $user_id)) {
1716 1716
             return;
1717 1717
         }
1718
-        $percentage_completed = $this->get_completion_percentage( $course_id, $user_id );
1718
+        $percentage_completed = $this->get_completion_percentage($course_id, $user_id);
1719 1719
 
1720
-        echo $this->get_progress_meter( $percentage_completed );
1720
+        echo $this->get_progress_meter($percentage_completed);
1721 1721
 
1722 1722
     }// end the_progress_meter
1723 1723
 
@@ -1730,20 +1730,20 @@  discard block
 block discarded – undo
1730 1730
      * @param int $user_id
1731 1731
      * @return array $completed_lesson_ids
1732 1732
      */
1733
-    public function get_completed_lesson_ids( $course_id, $user_id = 0 ){
1733
+    public function get_completed_lesson_ids($course_id, $user_id = 0) {
1734 1734
 
1735
-        if( !( intval( $user_id ) ) > 0 ){
1735
+        if ( ! (intval($user_id)) > 0) {
1736 1736
             $user_id = get_current_user_id();
1737 1737
         }
1738 1738
 
1739 1739
         $completed_lesson_ids = array();
1740 1740
 
1741
-        $course_lessons = $this->course_lessons( $course_id );
1741
+        $course_lessons = $this->course_lessons($course_id);
1742 1742
 
1743
-        foreach( $course_lessons as $lesson ){
1743
+        foreach ($course_lessons as $lesson) {
1744 1744
 
1745
-            $is_lesson_completed = Sensei_Utils::user_completed_lesson( $lesson->ID, $user_id );
1746
-            if( $is_lesson_completed ){
1745
+            $is_lesson_completed = Sensei_Utils::user_completed_lesson($lesson->ID, $user_id);
1746
+            if ($is_lesson_completed) {
1747 1747
                 $completed_lesson_ids[] = $lesson->ID;
1748 1748
             }
1749 1749
 
@@ -1762,19 +1762,19 @@  discard block
 block discarded – undo
1762 1762
      * @param int $user_id
1763 1763
      * @return int $percentage
1764 1764
      */
1765
-    public function get_completion_percentage( $course_id, $user_id = 0 ){
1765
+    public function get_completion_percentage($course_id, $user_id = 0) {
1766 1766
 
1767
-        if( !( intval( $user_id ) ) > 0 ){
1767
+        if ( ! (intval($user_id)) > 0) {
1768 1768
             $user_id = get_current_user_id();
1769 1769
         }
1770 1770
 
1771
-        $completed = count( $this->get_completed_lesson_ids( $course_id, $user_id ) );
1771
+        $completed = count($this->get_completed_lesson_ids($course_id, $user_id));
1772 1772
 
1773
-        if( ! (  $completed  > 0 ) ){
1773
+        if ( ! ($completed > 0)) {
1774 1774
             return 0;
1775 1775
         }
1776 1776
 
1777
-        $total_lessons = count( $this->course_lessons( $course_id ) );
1777
+        $total_lessons = count($this->course_lessons($course_id));
1778 1778
         $percentage = $completed / $total_lessons * 100;
1779 1779
 
1780 1780
         /**
@@ -1786,7 +1786,7 @@  discard block
 block discarded – undo
1786 1786
          * @param $user_id
1787 1787
          * @since 1.8.0
1788 1788
          */
1789
-        return apply_filters( 'sensei_course_completion_percentage', $percentage, $course_id, $user_id );
1789
+        return apply_filters('sensei_course_completion_percentage', $percentage, $course_id, $user_id);
1790 1790
 
1791 1791
     }// end get_completed_lesson_ids
1792 1792
 
@@ -1798,28 +1798,28 @@  discard block
 block discarded – undo
1798 1798
      * @param $should_send
1799 1799
      * @return bool
1800 1800
      */
1801
-    public function block_notification_emails( $should_send ){
1801
+    public function block_notification_emails($should_send) {
1802 1802
         global $sensei_email_data;
1803 1803
         $email = $sensei_email_data;
1804 1804
 
1805 1805
         $course_id = '';
1806 1806
 
1807
-        if( isset( $email['course_id'] ) ){
1807
+        if (isset($email['course_id'])) {
1808 1808
 
1809 1809
             $course_id = $email['course_id'];
1810 1810
 
1811
-        }elseif( isset( $email['lesson_id'] ) ){
1811
+        }elseif (isset($email['lesson_id'])) {
1812 1812
 
1813
-            $course_id = Sensei()->lesson->get_course_id( $email['lesson_id'] );
1813
+            $course_id = Sensei()->lesson->get_course_id($email['lesson_id']);
1814 1814
 
1815
-        }elseif( isset( $email['quiz_id'] ) ){
1815
+        }elseif (isset($email['quiz_id'])) {
1816 1816
 
1817
-            $lesson_id = Sensei()->quiz->get_lesson_id( $email['quiz_id'] );
1818
-            $course_id = Sensei()->lesson->get_course_id( $lesson_id );
1817
+            $lesson_id = Sensei()->quiz->get_lesson_id($email['quiz_id']);
1818
+            $course_id = Sensei()->lesson->get_course_id($lesson_id);
1819 1819
 
1820 1820
         }
1821 1821
 
1822
-        if( !empty( $course_id ) && 'course'== get_post_type( $course_id ) ) {
1822
+        if ( ! empty($course_id) && 'course' == get_post_type($course_id)) {
1823 1823
 
1824 1824
             $course_emails_disabled = get_post_meta($course_id, 'disable_notification', true);
1825 1825
 
@@ -1840,19 +1840,19 @@  discard block
 block discarded – undo
1840 1840
      * @since 1.8.0
1841 1841
      * @param $course
1842 1842
      */
1843
-    public function course_notification_meta_box_content( $course ){
1843
+    public function course_notification_meta_box_content($course) {
1844 1844
 
1845
-        $checked = get_post_meta( $course->ID , 'disable_notification', true );
1845
+        $checked = get_post_meta($course->ID, 'disable_notification', true);
1846 1846
 
1847 1847
         // generate checked html
1848 1848
         $checked_html = '';
1849
-        if( $checked ){
1849
+        if ($checked) {
1850 1850
             $checked_html = 'checked="checked"';
1851 1851
         }
1852
-        wp_nonce_field( 'update-course-notification-setting','_sensei_course_notification' );
1852
+        wp_nonce_field('update-course-notification-setting', '_sensei_course_notification');
1853 1853
 
1854
-        echo '<input id="disable_sensei_course_notification" '.$checked_html .' type="checkbox" name="disable_sensei_course_notification" >';
1855
-        echo '<label for="disable_sensei_course_notification">'.__('Disable notifications on this course ?', 'woothemes-sensei'). '</label>';
1854
+        echo '<input id="disable_sensei_course_notification" '.$checked_html.' type="checkbox" name="disable_sensei_course_notification" >';
1855
+        echo '<label for="disable_sensei_course_notification">'.__('Disable notifications on this course ?', 'woothemes-sensei').'</label>';
1856 1856
 
1857 1857
     }// end course_notification_meta_box_content
1858 1858
 
@@ -1864,20 +1864,20 @@  discard block
 block discarded – undo
1864 1864
      *
1865 1865
      * @param $course_id
1866 1866
      */
1867
-    public function save_course_notification_meta_box( $course_id ){
1867
+    public function save_course_notification_meta_box($course_id) {
1868 1868
 
1869
-        if( !isset( $_POST['_sensei_course_notification']  )
1870
-            || ! wp_verify_nonce( $_POST['_sensei_course_notification'], 'update-course-notification-setting' ) ){
1869
+        if ( ! isset($_POST['_sensei_course_notification'])
1870
+            || ! wp_verify_nonce($_POST['_sensei_course_notification'], 'update-course-notification-setting')) {
1871 1871
             return;
1872 1872
         }
1873 1873
 
1874
-        if( isset( $_POST['disable_sensei_course_notification'] ) && 'on'== $_POST['disable_sensei_course_notification']  ) {
1874
+        if (isset($_POST['disable_sensei_course_notification']) && 'on' == $_POST['disable_sensei_course_notification']) {
1875 1875
             $new_val = true;
1876
-        }else{
1876
+        } else {
1877 1877
             $new_val = false;
1878 1878
         }
1879 1879
 
1880
-       update_post_meta( $course_id , 'disable_notification', $new_val );
1880
+       update_post_meta($course_id, 'disable_notification', $new_val);
1881 1881
 
1882 1882
     }// end save notification meta box
1883 1883
 
@@ -1891,10 +1891,10 @@  discard block
 block discarded – undo
1891 1891
      *
1892 1892
      * @param WP_Post $post
1893 1893
      */
1894
-    public function content_before_backwards_compatibility_hooks( $post ){
1894
+    public function content_before_backwards_compatibility_hooks($post) {
1895 1895
 
1896
-        sensei_do_deprecated_action( 'sensei_course_image','1.9.0','sensei_course_content_inside_before' );
1897
-        sensei_do_deprecated_action( 'sensei_course_archive_course_title','1.9.0','sensei_course_content_inside_before' );
1896
+        sensei_do_deprecated_action('sensei_course_image', '1.9.0', 'sensei_course_content_inside_before');
1897
+        sensei_do_deprecated_action('sensei_course_archive_course_title', '1.9.0', 'sensei_course_content_inside_before');
1898 1898
 
1899 1899
     }
1900 1900
 
@@ -1907,10 +1907,10 @@  discard block
 block discarded – undo
1907 1907
      *
1908 1908
      * @global WP_Post $post
1909 1909
      */
1910
-    public  function loop_before_backwards_compatibility_hooks( ){
1910
+    public  function loop_before_backwards_compatibility_hooks( ) {
1911 1911
 
1912 1912
         global $post;
1913
-        sensei_do_deprecated_action( 'sensei_course_archive_header','1.9.0','sensei_course_content_inside_before', $post->post_type  );
1913
+        sensei_do_deprecated_action('sensei_course_archive_header', '1.9.0', 'sensei_course_content_inside_before', $post->post_type);
1914 1914
 
1915 1915
     }
1916 1916
 
@@ -1923,18 +1923,18 @@  discard block
 block discarded – undo
1923 1923
      *
1924 1924
      * @param WP_Post $course
1925 1925
      */
1926
-    public function the_course_free_lesson_preview( $course ){
1926
+    public function the_course_free_lesson_preview($course) {
1927 1927
         // Meta data
1928
-        $preview_lesson_count = intval( Sensei()->course->course_lesson_preview_count( $course->ID ) );
1929
-        $is_user_taking_course = Sensei_Utils::user_started_course( $course->ID, get_current_user_id() );
1928
+        $preview_lesson_count = intval(Sensei()->course->course_lesson_preview_count($course->ID));
1929
+        $is_user_taking_course = Sensei_Utils::user_started_course($course->ID, get_current_user_id());
1930 1930
 
1931
-        if ( 0 < $preview_lesson_count && !$is_user_taking_course ) {
1931
+        if (0 < $preview_lesson_count && ! $is_user_taking_course) {
1932 1932
             ?>
1933 1933
             <p class="sensei-free-lessons">
1934 1934
                 <a href="<?php echo get_permalink(); ?>">
1935
-                    <?php _e( 'Preview this course', 'woothemes-sensei' ) ?>
1935
+                    <?php _e('Preview this course', 'woothemes-sensei') ?>
1936 1936
                 </a>
1937
-                - <?php echo sprintf( __( '(%d preview lessons)', 'woothemes-sensei' ), $preview_lesson_count ) ; ?>
1937
+                - <?php echo sprintf(__('(%d preview lessons)', 'woothemes-sensei'), $preview_lesson_count); ?>
1938 1938
             </p>
1939 1939
 
1940 1940
         <?php
@@ -1947,41 +1947,41 @@  discard block
 block discarded – undo
1947 1947
      * @since 1.9.0
1948 1948
      * @param WP_Post $course
1949 1949
      */
1950
-    public function the_course_meta( $course ){
1950
+    public function the_course_meta($course) {
1951 1951
         echo '<p class="sensei-course-meta">';
1952 1952
 
1953
-        $category_output = get_the_term_list( $course->ID, 'course-category', '', ', ', '' );
1954
-        $author_display_name = get_the_author_meta( 'display_name', $course->post_author  );
1953
+        $category_output = get_the_term_list($course->ID, 'course-category', '', ', ', '');
1954
+        $author_display_name = get_the_author_meta('display_name', $course->post_author);
1955 1955
 
1956
-        if ( isset( Sensei()->settings->settings[ 'course_author' ] ) && ( Sensei()->settings->settings[ 'course_author' ] ) ) {?>
1956
+        if (isset(Sensei()->settings->settings['course_author']) && (Sensei()->settings->settings['course_author'])) {?>
1957 1957
 
1958
-            <span class="course-author"><?php _e( 'by ', 'woothemes-sensei' ); ?>
1958
+            <span class="course-author"><?php _e('by ', 'woothemes-sensei'); ?>
1959 1959
 
1960
-                <a href="<?php esc_attr_e( get_author_posts_url( $course->post_author ) ); ?>" title="<?php esc_attr_e( $author_display_name ); ?>"><?php esc_attr_e( $author_display_name   ); ?></a>
1960
+                <a href="<?php esc_attr_e(get_author_posts_url($course->post_author)); ?>" title="<?php esc_attr_e($author_display_name); ?>"><?php esc_attr_e($author_display_name); ?></a>
1961 1961
 
1962 1962
             </span>
1963 1963
 
1964 1964
         <?php } // End If Statement ?>
1965 1965
 
1966
-        <span class="course-lesson-count"><?php echo Sensei()->course->course_lesson_count( $course->ID ) . '&nbsp;' .  __( 'Lessons', 'woothemes-sensei' ); ?></span>
1966
+        <span class="course-lesson-count"><?php echo Sensei()->course->course_lesson_count($course->ID).'&nbsp;'.__('Lessons', 'woothemes-sensei'); ?></span>
1967 1967
 
1968
-       <?php if ( '' != $category_output ) { ?>
1968
+       <?php if ('' != $category_output) { ?>
1969 1969
 
1970
-            <span class="course-category"><?php echo sprintf( __( 'in %s', 'woothemes-sensei' ), $category_output ); ?></span>
1970
+            <span class="course-category"><?php echo sprintf(__('in %s', 'woothemes-sensei'), $category_output); ?></span>
1971 1971
 
1972 1972
         <?php } // End If Statement
1973 1973
 
1974 1974
         // number of completed lessons
1975
-        if( Sensei_Utils::user_started_course( $course->ID,  get_current_user_id() )
1976
-            || Sensei_Utils::user_completed_course( $course->ID,  get_current_user_id() )  ){
1975
+        if (Sensei_Utils::user_started_course($course->ID, get_current_user_id())
1976
+            || Sensei_Utils::user_completed_course($course->ID, get_current_user_id())) {
1977 1977
 
1978
-            $completed = count( $this->get_completed_lesson_ids( $course->ID, get_current_user_id() ) );
1979
-            $lesson_count = count( $this->course_lessons( $course->ID ) );
1980
-            echo '<span class="course-lesson-progress">' . sprintf( __( '%1$d of %2$d lessons completed', 'woothemes-sensei' ) , $completed, $lesson_count  ) . '</span>';
1978
+            $completed = count($this->get_completed_lesson_ids($course->ID, get_current_user_id()));
1979
+            $lesson_count = count($this->course_lessons($course->ID));
1980
+            echo '<span class="course-lesson-progress">'.sprintf(__('%1$d of %2$d lessons completed', 'woothemes-sensei'), $completed, $lesson_count).'</span>';
1981 1981
 
1982 1982
         }
1983 1983
 
1984
-        sensei_simple_course_price( $course->ID );
1984
+        sensei_simple_course_price($course->ID);
1985 1985
 
1986 1986
         echo '</p>';
1987 1987
     } // end the course meta
@@ -1996,15 +1996,15 @@  discard block
 block discarded – undo
1996 1996
      *
1997 1997
      * @return array $classes
1998 1998
      */
1999
-    public static function add_course_user_status_class( $classes, $class, $course_id ){
1999
+    public static function add_course_user_status_class($classes, $class, $course_id) {
2000 2000
 
2001
-        if( 'course' == get_post_type( $course_id )  &&  is_user_logged_in() ){
2001
+        if ('course' == get_post_type($course_id) && is_user_logged_in()) {
2002 2002
 
2003
-            if( Sensei_Utils::user_completed_course( $course_id, get_current_user_id() ) ){
2003
+            if (Sensei_Utils::user_completed_course($course_id, get_current_user_id())) {
2004 2004
 
2005 2005
                 $classes[] = 'user-status-completed';
2006 2006
 
2007
-            }else{
2007
+            } else {
2008 2008
 
2009 2009
                 $classes[] = 'user-status-active';
2010 2010
 
@@ -2024,56 +2024,56 @@  discard block
 block discarded – undo
2024 2024
      *
2025 2025
      * @param WP_Post $course
2026 2026
      */
2027
-    public static function the_course_action_buttons( $course ){
2027
+    public static function the_course_action_buttons($course) {
2028 2028
 
2029
-        if( is_user_logged_in() ) { ?>
2029
+        if (is_user_logged_in()) { ?>
2030 2030
 
2031 2031
             <section class="entry-actions">
2032
-                <form method="POST" action="<?php  echo esc_url( remove_query_arg( array( 'active_page', 'completed_page' ) ) ); ?>">
2032
+                <form method="POST" action="<?php  echo esc_url(remove_query_arg(array('active_page', 'completed_page'))); ?>">
2033 2033
 
2034 2034
                     <input type="hidden"
2035
-                           name="<?php esc_attr_e( 'woothemes_sensei_complete_course_noonce' ) ?>"
2036
-                           id="<?php  esc_attr_e( 'woothemes_sensei_complete_course_noonce' ); ?>"
2037
-                           value="<?php esc_attr_e( wp_create_nonce( 'woothemes_sensei_complete_course_noonce' ) ); ?>"
2035
+                           name="<?php esc_attr_e('woothemes_sensei_complete_course_noonce') ?>"
2036
+                           id="<?php  esc_attr_e('woothemes_sensei_complete_course_noonce'); ?>"
2037
+                           value="<?php esc_attr_e(wp_create_nonce('woothemes_sensei_complete_course_noonce')); ?>"
2038 2038
                         />
2039 2039
 
2040
-                    <input type="hidden" name="course_complete_id" id="course-complete-id" value="<?php esc_attr_e( intval( $course->ID ) ); ?>" />
2040
+                    <input type="hidden" name="course_complete_id" id="course-complete-id" value="<?php esc_attr_e(intval($course->ID)); ?>" />
2041 2041
 
2042
-                    <?php if ( 0 < absint( count( Sensei()->course->course_lessons( $course->ID ) ) ) && Sensei()->settings->settings['course_completion'] == 'complete' ) { ?>
2042
+                    <?php if (0 < absint(count(Sensei()->course->course_lessons($course->ID))) && Sensei()->settings->settings['course_completion'] == 'complete') { ?>
2043 2043
 
2044
-                        <span><input name="course_complete" type="submit" class="course-complete" value="<?php  _e( 'Mark as Complete', 'woothemes-sensei' ); ?>" /></span>
2044
+                        <span><input name="course_complete" type="submit" class="course-complete" value="<?php  _e('Mark as Complete', 'woothemes-sensei'); ?>" /></span>
2045 2045
 
2046 2046
                    <?php  } // End If Statement
2047 2047
 
2048 2048
                     $course_purchased = false;
2049
-                    if ( Sensei_WC::is_woocommerce_active() ) {
2049
+                    if (Sensei_WC::is_woocommerce_active()) {
2050 2050
                         // Get the product ID
2051
-                        $wc_post_id = get_post_meta( intval( $course->ID ), '_course_woocommerce_product', true );
2052
-                        if ( 0 < $wc_post_id ) {
2051
+                        $wc_post_id = get_post_meta(intval($course->ID), '_course_woocommerce_product', true);
2052
+                        if (0 < $wc_post_id) {
2053 2053
 
2054 2054
                             $user = wp_get_current_user();
2055
-                            $course_purchased = Sensei_Utils::sensei_customer_bought_product( $user->user_email, $user->ID, $wc_post_id );
2055
+                            $course_purchased = Sensei_Utils::sensei_customer_bought_product($user->user_email, $user->ID, $wc_post_id);
2056 2056
 
2057 2057
                         } // End If Statement
2058 2058
                     } // End If Statement
2059 2059
 
2060
-                    if ( ! $course_purchased && ! Sensei_Utils::user_completed_course( $course->ID, get_current_user_id() ) ) {?>
2060
+                    if ( ! $course_purchased && ! Sensei_Utils::user_completed_course($course->ID, get_current_user_id())) {?>
2061 2061
 
2062
-                        <span><input name="course_complete" type="submit" class="course-delete" value="<?php echo __( 'Delete Course', 'woothemes-sensei' ); ?>"/></span>
2062
+                        <span><input name="course_complete" type="submit" class="course-delete" value="<?php echo __('Delete Course', 'woothemes-sensei'); ?>"/></span>
2063 2063
 
2064 2064
                     <?php } // End If Statement
2065 2065
 
2066
-                    $has_quizzes = Sensei()->course->course_quizzes( $course->ID, true );
2066
+                    $has_quizzes = Sensei()->course->course_quizzes($course->ID, true);
2067 2067
                     $results_link = '';
2068
-                    if( $has_quizzes ){
2069
-                        $results_link = '<a class="button view-results" href="' . Sensei()->course_results->get_permalink( $course->ID ) . '">' . __( 'View results', 'woothemes-sensei' ) . '</a>';
2068
+                    if ($has_quizzes) {
2069
+                        $results_link = '<a class="button view-results" href="'.Sensei()->course_results->get_permalink($course->ID).'">'.__('View results', 'woothemes-sensei').'</a>';
2070 2070
                     }
2071 2071
 
2072 2072
                     // Output only if there is content to display
2073
-                    if ( has_filter( 'sensei_results_links' ) || $has_quizzes ) { ?>
2073
+                    if (has_filter('sensei_results_links') || $has_quizzes) { ?>
2074 2074
 
2075 2075
                         <p class="sensei-results-links">
2076
-                            <?php echo apply_filters( 'sensei_results_links', $results_link ); ?>
2076
+                            <?php echo apply_filters('sensei_results_links', $results_link); ?>
2077 2077
                         </p>
2078 2078
 
2079 2079
                     <?php } // end if has filter  ?>
@@ -2098,17 +2098,17 @@  discard block
 block discarded – undo
2098 2098
      * @param WP_Query $query
2099 2099
      * @return WP_Query $query
2100 2100
      */
2101
-    public static function course_query_filter( $query ){
2101
+    public static function course_query_filter($query) {
2102 2102
 
2103 2103
         // exit early for no course queries and admin queries
2104
-        if( is_admin( ) || 'course' != $query->get( 'post_type' ) ){
2104
+        if (is_admin( ) || 'course' != $query->get('post_type')) {
2105 2105
             return $query;
2106 2106
         }
2107 2107
 
2108 2108
         global $post; // used to get the current page id for my courses
2109 2109
 
2110 2110
         // for the course archive page
2111
-        if( $query->is_main_query() && is_post_type_archive('course') )
2111
+        if ($query->is_main_query() && is_post_type_archive('course'))
2112 2112
         {
2113 2113
             /**
2114 2114
              * sensei_archive_courses_per_page
@@ -2119,11 +2119,11 @@  discard block
 block discarded – undo
2119 2119
              * @since 1.9.0
2120 2120
              * @param integer $posts_per_page default 10
2121 2121
              */
2122
-            $query->set( 'posts_per_page', apply_filters( 'sensei_archive_courses_per_page', 10 ) );
2122
+            $query->set('posts_per_page', apply_filters('sensei_archive_courses_per_page', 10));
2123 2123
 
2124 2124
         }
2125 2125
         // for the my courses page
2126
-        elseif( is_page() && Sensei()->settings->get( 'my_course_page' ) == $post->ID  )
2126
+        elseif (is_page() && Sensei()->settings->get('my_course_page') == $post->ID)
2127 2127
         {
2128 2128
             /**
2129 2129
              * sensei_my_courses_per_page
@@ -2134,7 +2134,7 @@  discard block
 block discarded – undo
2134 2134
              * @since 1.9.0
2135 2135
              * @param integer $posts_per_page default 10
2136 2136
              */
2137
-            $query->set( 'posts_per_page', apply_filters( 'sensei_my_courses_per_page', 10 ) );
2137
+            $query->set('posts_per_page', apply_filters('sensei_my_courses_per_page', 10));
2138 2138
 
2139 2139
         }
2140 2140
 
@@ -2150,21 +2150,21 @@  discard block
 block discarded – undo
2150 2150
      * @return array $extra_classes
2151 2151
      * @since 1.9.0
2152 2152
      */
2153
-    public static function get_course_loop_content_class ()
2153
+    public static function get_course_loop_content_class()
2154 2154
     {
2155 2155
 
2156 2156
         global $sensei_course_loop;
2157 2157
 
2158 2158
 
2159
-        if( !isset( $sensei_course_loop ) ){
2159
+        if ( ! isset($sensei_course_loop)) {
2160 2160
             $sensei_course_loop = array();
2161 2161
         }
2162 2162
 
2163
-        if (!isset($sensei_course_loop['counter'])) {
2163
+        if ( ! isset($sensei_course_loop['counter'])) {
2164 2164
             $sensei_course_loop['counter'] = 0;
2165 2165
         }
2166 2166
 
2167
-        if (!isset($sensei_course_loop['columns'])) {
2167
+        if ( ! isset($sensei_course_loop['columns'])) {
2168 2168
             $sensei_course_loop['columns'] = self::get_loop_number_of_columns();
2169 2169
         }
2170 2170
 
@@ -2172,16 +2172,16 @@  discard block
 block discarded – undo
2172 2172
         $sensei_course_loop['counter']++;
2173 2173
 
2174 2174
         $extra_classes = array();
2175
-        if( 0 == ( $sensei_course_loop['counter'] - 1 ) % $sensei_course_loop['columns'] || 1 == $sensei_course_loop['columns']  ){
2175
+        if (0 == ($sensei_course_loop['counter'] - 1) % $sensei_course_loop['columns'] || 1 == $sensei_course_loop['columns']) {
2176 2176
             $extra_classes[] = 'first';
2177 2177
         }
2178 2178
 
2179
-        if( 0 == $sensei_course_loop['counter'] % $sensei_course_loop['columns']  ){
2179
+        if (0 == $sensei_course_loop['counter'] % $sensei_course_loop['columns']) {
2180 2180
             $extra_classes[] = 'last';
2181 2181
         }
2182 2182
 
2183 2183
         // add the item number to the classes as well.
2184
-        $extra_classes[] = 'loop-item-number-'. $sensei_course_loop['counter'];
2184
+        $extra_classes[] = 'loop-item-number-'.$sensei_course_loop['counter'];
2185 2185
 
2186 2186
         /**
2187 2187
          * Filter the course loop class the fires in the  in get_course_loop_content_class function
@@ -2192,7 +2192,7 @@  discard block
 block discarded – undo
2192 2192
          * @param array $extra_classes
2193 2193
          * @param WP_Post $loop_current_course
2194 2194
          */
2195
-        return apply_filters( 'sensei_course_loop_content_class', $extra_classes ,get_post() );
2195
+        return apply_filters('sensei_course_loop_content_class', $extra_classes, get_post());
2196 2196
 
2197 2197
     }// end get_course_loop_class
2198 2198
 
@@ -2202,7 +2202,7 @@  discard block
 block discarded – undo
2202 2202
      * @since 1.9.0
2203 2203
      * @return mixed|void
2204 2204
      */
2205
-    public static function get_loop_number_of_columns(){
2205
+    public static function get_loop_number_of_columns() {
2206 2206
 
2207 2207
         /**
2208 2208
          * Filter the number of columns on the course archive page.
@@ -2222,10 +2222,10 @@  discard block
 block discarded – undo
2222 2222
      * @since 1.9.0
2223 2223
      * @param
2224 2224
      */
2225
-    public static function course_archive_sorting( $query ){
2225
+    public static function course_archive_sorting($query) {
2226 2226
 
2227 2227
         // don't show on category pages and other pages
2228
-        if( ! is_archive(  'course ') || is_tax('course-category') ){
2228
+        if ( ! is_archive('course ') || is_tax('course-category')) {
2229 2229
             return;
2230 2230
         }
2231 2231
 
@@ -2238,27 +2238,27 @@  discard block
 block discarded – undo
2238 2238
          *  @type string $option_string
2239 2239
          * }
2240 2240
          */
2241
-        $course_order_by_options = apply_filters( 'sensei_archive_course_order_by_options', array(
2242
-            "newness"     => __( "Sort by newest first", "woothemes-sensei"),
2243
-            "title"       => __( "Sort by title A-Z", "woothemes-sensei" ),
2241
+        $course_order_by_options = apply_filters('sensei_archive_course_order_by_options', array(
2242
+            "newness"     => __("Sort by newest first", "woothemes-sensei"),
2243
+            "title"       => __("Sort by title A-Z", "woothemes-sensei"),
2244 2244
         ));
2245 2245
 
2246 2246
         // setup the currently selected item
2247 2247
         $selected = 'newness';
2248
-        if( isset( $_GET['orderby'] ) ){
2248
+        if (isset($_GET['orderby'])) {
2249 2249
 
2250
-            $selected =  $_GET[ 'orderby' ];
2250
+            $selected = $_GET['orderby'];
2251 2251
 
2252 2252
         }
2253 2253
 
2254 2254
         ?>
2255 2255
 
2256
-        <form class="sensei-ordering" name="sensei-course-order" action="<?php echo esc_attr( Sensei_Utils::get_current_url() ) ; ?>" method="POST">
2256
+        <form class="sensei-ordering" name="sensei-course-order" action="<?php echo esc_attr(Sensei_Utils::get_current_url()); ?>" method="POST">
2257 2257
             <select name="course-orderby" class="orderby">
2258 2258
                 <?php
2259
-                foreach( $course_order_by_options as $value => $text ){
2259
+                foreach ($course_order_by_options as $value => $text) {
2260 2260
 
2261
-                    echo '<option value="'. $value . ' "' . selected( $selected, $value, false ) . '>'. $text. '</option>';
2261
+                    echo '<option value="'.$value.' "'.selected($selected, $value, false).'>'.$text.'</option>';
2262 2262
 
2263 2263
                 }
2264 2264
                 ?>
@@ -2276,10 +2276,10 @@  discard block
 block discarded – undo
2276 2276
      * @since 1.9.0
2277 2277
      * @param
2278 2278
      */
2279
-    public static function course_archive_filters( $query ){
2279
+    public static function course_archive_filters($query) {
2280 2280
 
2281 2281
         // don't show on category pages
2282
-        if( is_tax('course-category') ){
2282
+        if (is_tax('course-category')) {
2283 2283
             return;
2284 2284
         }
2285 2285
 
@@ -2292,9 +2292,9 @@  discard block
 block discarded – undo
2292 2292
          * }
2293 2293
          *
2294 2294
          */
2295
-        $filters = apply_filters( 'sensei_archive_course_filter_by_options', array(
2296
-            array( 'id' => 'all', 'url' => self::get_courses_page_url(), 'title'=> __( 'All', 'woothemes-sensei' ) ),
2297
-            array( 'id' => 'featured', 'url' => add_query_arg( array( 'course_filter'=>'featured'), self::get_courses_page_url()  ), 'title'=> __( 'Featured', 'woothemes-sensei' ) ),
2295
+        $filters = apply_filters('sensei_archive_course_filter_by_options', array(
2296
+            array('id' => 'all', 'url' => self::get_courses_page_url(), 'title'=> __('All', 'woothemes-sensei')),
2297
+            array('id' => 'featured', 'url' => add_query_arg(array('course_filter'=>'featured'), self::get_courses_page_url()), 'title'=> __('Featured', 'woothemes-sensei')),
2298 2298
         ));
2299 2299
 
2300 2300
 
@@ -2305,11 +2305,11 @@  discard block
 block discarded – undo
2305 2305
             //determine the current active url
2306 2306
             $current_url = Sensei_Utils::get_current_url();
2307 2307
 
2308
-            foreach( $filters as $filter ) {
2308
+            foreach ($filters as $filter) {
2309 2309
 
2310
-                $active_class =  $current_url == $filter['url'] ? ' class="active" ' : '';
2310
+                $active_class = $current_url == $filter['url'] ? ' class="active" ' : '';
2311 2311
 
2312
-                echo '<li><a '. $active_class .' id="'. $filter['id'] .'" href="'. esc_url( $filter['url'] ).'" >'. $filter['title']  .'</a></li>';
2312
+                echo '<li><a '.$active_class.' id="'.$filter['id'].'" href="'.esc_url($filter['url']).'" >'.$filter['title'].'</a></li>';
2313 2313
 
2314 2314
             }
2315 2315
             ?>
@@ -2330,13 +2330,13 @@  discard block
 block discarded – undo
2330 2330
      * @param WP_Query $query
2331 2331
      * @return WP_Query $query
2332 2332
      */
2333
-    public static function course_archive_featured_filter( $query ){
2333
+    public static function course_archive_featured_filter($query) {
2334 2334
 
2335
-        if( isset ( $_GET[ 'course_filter' ] ) && 'featured'== $_GET['course_filter'] && $query->is_main_query()  ){
2335
+        if (isset ($_GET['course_filter']) && 'featured' == $_GET['course_filter'] && $query->is_main_query()) {
2336 2336
             //setup meta query for featured courses
2337
-            $query->set( 'meta_value', 'featured'  );
2338
-            $query->set( 'meta_key', '_course_featured'  );
2339
-            $query->set( 'meta_compare', '='  );
2337
+            $query->set('meta_value', 'featured');
2338
+            $query->set('meta_key', '_course_featured');
2339
+            $query->set('meta_compare', '=');
2340 2340
         }
2341 2341
 
2342 2342
         return $query;
@@ -2351,13 +2351,13 @@  discard block
 block discarded – undo
2351 2351
      * @param WP_Query $query
2352 2352
      * @return WP_Query $query
2353 2353
      */
2354
-    public static function course_archive_order_by_title( $query ){
2354
+    public static function course_archive_order_by_title($query) {
2355 2355
 
2356
-        if( isset ( $_POST[ 'course-orderby' ] ) && 'title '== $_POST['course-orderby']
2357
-            && 'course'== $query->get('post_type') && $query->is_main_query()  ){
2356
+        if (isset ($_POST['course-orderby']) && 'title ' == $_POST['course-orderby']
2357
+            && 'course' == $query->get('post_type') && $query->is_main_query()) {
2358 2358
             // setup the order by title for this query
2359
-            $query->set( 'orderby', 'title'  );
2360
-            $query->set( 'order', 'ASC'  );
2359
+            $query->set('orderby', 'title');
2360
+            $query->set('order', 'ASC');
2361 2361
         }
2362 2362
 
2363 2363
         return $query;
@@ -2371,10 +2371,10 @@  discard block
 block discarded – undo
2371 2371
      * @since 1.9.0
2372 2372
      * @return string $course_page_url
2373 2373
      */
2374
-    public static function get_courses_page_url(){
2374
+    public static function get_courses_page_url() {
2375 2375
 
2376
-        $course_page_id = intval( Sensei()->settings->settings[ 'course_page' ] );
2377
-        $course_page_url = empty( $course_page_id ) ? get_post_type_archive_link('course') : get_permalink( $course_page_id );
2376
+        $course_page_id = intval(Sensei()->settings->settings['course_page']);
2377
+        $course_page_url = empty($course_page_id) ? get_post_type_archive_link('course') : get_permalink($course_page_id);
2378 2378
 
2379 2379
         return $course_page_url;
2380 2380
 
@@ -2391,61 +2391,61 @@  discard block
 block discarded – undo
2391 2391
      * @param string $after_html
2392 2392
      * @return void
2393 2393
      */
2394
-    public static function archive_header( $query_type ='' , $before_html='', $after_html =''  ){
2394
+    public static function archive_header($query_type = '', $before_html = '', $after_html = '') {
2395 2395
 
2396
-        if( ! is_post_type_archive('course') ){
2396
+        if ( ! is_post_type_archive('course')) {
2397 2397
             return;
2398 2398
         }
2399 2399
 
2400 2400
         // deprecated since 1.9.0
2401
-        sensei_do_deprecated_action('sensei_archive_title','1.9.0','sensei_archive_before_course_loop');
2401
+        sensei_do_deprecated_action('sensei_archive_title', '1.9.0', 'sensei_archive_before_course_loop');
2402 2402
 
2403 2403
         $html = '';
2404 2404
 
2405
-        if( empty( $before_html ) ){
2405
+        if (empty($before_html)) {
2406 2406
 
2407 2407
             $before_html = '<header class="archive-header"><h1>';
2408 2408
 
2409 2409
         }
2410 2410
 
2411
-        if( empty( $after_html ) ){
2411
+        if (empty($after_html)) {
2412 2412
 
2413 2413
             $after_html = '</h1></header>';
2414 2414
 
2415 2415
         }
2416 2416
 
2417
-        if ( is_tax( 'course-category' ) ) {
2417
+        if (is_tax('course-category')) {
2418 2418
 
2419 2419
             global $wp_query;
2420 2420
 
2421 2421
             $taxonomy_obj = $wp_query->get_queried_object();
2422 2422
             $taxonomy_short_name = $taxonomy_obj->taxonomy;
2423
-            $taxonomy_raw_obj = get_taxonomy( $taxonomy_short_name );
2424
-            $title = sprintf( __( '%1$s Archives: %2$s', 'woothemes-sensei' ), $taxonomy_raw_obj->labels->name, $taxonomy_obj->name );
2425
-            echo apply_filters( 'course_category_archive_title', $before_html . $title . $after_html );
2423
+            $taxonomy_raw_obj = get_taxonomy($taxonomy_short_name);
2424
+            $title = sprintf(__('%1$s Archives: %2$s', 'woothemes-sensei'), $taxonomy_raw_obj->labels->name, $taxonomy_obj->name);
2425
+            echo apply_filters('course_category_archive_title', $before_html.$title.$after_html);
2426 2426
             return;
2427 2427
 
2428 2428
         } // End If Statement
2429 2429
 
2430
-        switch ( $query_type ) {
2430
+        switch ($query_type) {
2431 2431
             case 'newcourses':
2432
-                $html .= $before_html . __( 'New Courses', 'woothemes-sensei' ) . $after_html;
2432
+                $html .= $before_html.__('New Courses', 'woothemes-sensei').$after_html;
2433 2433
                 break;
2434 2434
             case 'featuredcourses':
2435
-                $html .= $before_html .  __( 'Featured Courses', 'woothemes-sensei' ) . $after_html;
2435
+                $html .= $before_html.__('Featured Courses', 'woothemes-sensei').$after_html;
2436 2436
                 break;
2437 2437
             case 'freecourses':
2438
-                $html .= $before_html .  __( 'Free Courses', 'woothemes-sensei' ) . $after_html;
2438
+                $html .= $before_html.__('Free Courses', 'woothemes-sensei').$after_html;
2439 2439
                 break;
2440 2440
             case 'paidcourses':
2441
-                $html .= $before_html .  __( 'Paid Courses', 'woothemes-sensei' ) . $after_html;
2441
+                $html .= $before_html.__('Paid Courses', 'woothemes-sensei').$after_html;
2442 2442
                 break;
2443 2443
             default:
2444
-                $html .= $before_html . __( 'Courses', 'woothemes-sensei' ) . $after_html;
2444
+                $html .= $before_html.__('Courses', 'woothemes-sensei').$after_html;
2445 2445
                 break;
2446 2446
         } // End Switch Statement
2447 2447
 
2448
-        echo apply_filters( 'course_archive_title', $html );
2448
+        echo apply_filters('course_archive_title', $html);
2449 2449
 
2450 2450
     }//course_archive_header
2451 2451
 
@@ -2459,9 +2459,9 @@  discard block
 block discarded – undo
2459 2459
      * @param string $content
2460 2460
      * @return string $content or $excerpt
2461 2461
      */
2462
-    public static function single_course_content( $content ){
2462
+    public static function single_course_content($content) {
2463 2463
 
2464
-        if( ! is_singular('course') ){
2464
+        if ( ! is_singular('course')) {
2465 2465
 
2466 2466
             return $content;
2467 2467
 
@@ -2470,21 +2470,21 @@  discard block
 block discarded – undo
2470 2470
         // Content Access Permissions
2471 2471
         $access_permission = false;
2472 2472
 
2473
-        if ( ! Sensei()->settings->get('access_permission')  || sensei_all_access() ) {
2473
+        if ( ! Sensei()->settings->get('access_permission') || sensei_all_access()) {
2474 2474
 
2475 2475
             $access_permission = true;
2476 2476
 
2477 2477
         } // End If Statement
2478 2478
 
2479 2479
         // Check if the user is taking the course
2480
-        $is_user_taking_course = Sensei_Utils::user_started_course( get_the_ID(), get_current_user_id() );
2480
+        $is_user_taking_course = Sensei_Utils::user_started_course(get_the_ID(), get_current_user_id());
2481 2481
 
2482
-        if(Sensei_WC::is_woocommerce_active()) {
2482
+        if (Sensei_WC::is_woocommerce_active()) {
2483 2483
 
2484
-            $wc_post_id = get_post_meta( get_the_ID(), '_course_woocommerce_product', true );
2485
-            $product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id );
2484
+            $wc_post_id = get_post_meta(get_the_ID(), '_course_woocommerce_product', true);
2485
+            $product = Sensei()->sensei_get_woocommerce_product_object($wc_post_id);
2486 2486
 
2487
-            $has_product_attached = isset ( $product ) && is_object ( $product );
2487
+            $has_product_attached = isset ($product) && is_object($product);
2488 2488
 
2489 2489
         } else {
2490 2490
 
@@ -2492,15 +2492,15 @@  discard block
 block discarded – undo
2492 2492
 
2493 2493
         }
2494 2494
 
2495
-        if ( ( is_user_logged_in() && $is_user_taking_course )
2496
-            || ( $access_permission && !$has_product_attached)
2497
-            || 'full' == Sensei()->settings->get( 'course_single_content_display' ) ) {
2495
+        if ((is_user_logged_in() && $is_user_taking_course)
2496
+            || ($access_permission && ! $has_product_attached)
2497
+            || 'full' == Sensei()->settings->get('course_single_content_display')) {
2498 2498
 
2499 2499
             return $content;
2500 2500
 
2501 2501
         } else {
2502 2502
 
2503
-            return '<p class="course-excerpt">' . get_post(  get_the_ID() )->post_excerpt . '</p>';
2503
+            return '<p class="course-excerpt">'.get_post(get_the_ID())->post_excerpt.'</p>';
2504 2504
 
2505 2505
         }
2506 2506
 
@@ -2511,14 +2511,14 @@  discard block
 block discarded – undo
2511 2511
      *
2512 2512
      * @since 1.9.0
2513 2513
      */
2514
-    public static function the_course_lessons_title(){
2514
+    public static function the_course_lessons_title() {
2515 2515
         global $post;
2516
-        $none_module_lessons = Sensei()->modules->get_none_module_lessons( $post->ID  );
2517
-        $course_lessons = Sensei()->course->course_lessons( $post->ID );
2516
+        $none_module_lessons = Sensei()->modules->get_none_module_lessons($post->ID);
2517
+        $course_lessons = Sensei()->course->course_lessons($post->ID);
2518 2518
 
2519 2519
         // title should be Other Lessons if there are lessons belonging to models.
2520 2520
         $title = __('Other Lessons', 'woothemes-sensei');
2521
-        if( count( $course_lessons ) == count( $none_module_lessons )  ){
2521
+        if (count($course_lessons) == count($none_module_lessons)) {
2522 2522
 
2523 2523
             $title = __('Lessons', 'woothemes-sensei');
2524 2524
 
@@ -2527,7 +2527,7 @@  discard block
 block discarded – undo
2527 2527
         /**
2528 2528
          * hook document in class-woothemes-sensei-message.php
2529 2529
          */
2530
-        $title = apply_filters( 'sensei_single_title', $title, $post->post_type );
2530
+        $title = apply_filters('sensei_single_title', $title, $post->post_type);
2531 2531
 
2532 2532
         ob_start(); // start capturing the following output.
2533 2533
 
@@ -2546,7 +2546,7 @@  discard block
 block discarded – undo
2546 2546
          * @since 1.9.0
2547 2547
          * @param string $lessons_title_html
2548 2548
          */
2549
-        echo apply_filters('the_course_lessons_title', ob_get_clean() ); // output and filter the captured output and stop capturing.
2549
+        echo apply_filters('the_course_lessons_title', ob_get_clean()); // output and filter the captured output and stop capturing.
2550 2550
 
2551 2551
     }// end the_course_lessons_title
2552 2552
 
@@ -2561,13 +2561,13 @@  discard block
 block discarded – undo
2561 2561
      * @since 1.9.0
2562 2562
      * @global $wp_query
2563 2563
      */
2564
-    public static function load_single_course_lessons_query(){
2564
+    public static function load_single_course_lessons_query() {
2565 2565
 
2566 2566
         global $post, $wp_query;
2567 2567
 
2568 2568
         $course_id = $post->ID;
2569 2569
 
2570
-        if( 'course' != get_post_type( $course_id ) ){
2570
+        if ('course' != get_post_type($course_id)) {
2571 2571
             return;
2572 2572
         }
2573 2573
 
@@ -2579,7 +2579,7 @@  discard block
 block discarded – undo
2579 2579
             'meta_query'        => array(
2580 2580
                 array(
2581 2581
                     'key' => '_lesson_course',
2582
-                    'value' => intval( $course_id ),
2582
+                    'value' => intval($course_id),
2583 2583
                 ),
2584 2584
             ),
2585 2585
             'post_status'       => 'public',
@@ -2587,17 +2587,17 @@  discard block
 block discarded – undo
2587 2587
         );
2588 2588
 
2589 2589
         // Exclude lessons belonging to modules as they are queried along with the modules.
2590
-        $modules = Sensei()->modules->get_course_modules( $course_id );
2591
-        if( !is_wp_error( $modules ) && ! empty( $modules ) && is_array( $modules ) ){
2590
+        $modules = Sensei()->modules->get_course_modules($course_id);
2591
+        if ( ! is_wp_error($modules) && ! empty($modules) && is_array($modules)) {
2592 2592
 
2593 2593
             $terms_ids = array();
2594
-            foreach( $modules as $term ){
2594
+            foreach ($modules as $term) {
2595 2595
 
2596 2596
                 $terms_ids[] = $term->term_id;
2597 2597
 
2598 2598
             }
2599 2599
 
2600
-            $course_lesson_query_args[ 'tax_query'] = array(
2600
+            $course_lesson_query_args['tax_query'] = array(
2601 2601
                 array(
2602 2602
                     'taxonomy' => 'module',
2603 2603
                     'field'    => 'id',
@@ -2607,7 +2607,7 @@  discard block
 block discarded – undo
2607 2607
             );
2608 2608
         }
2609 2609
 
2610
-        $wp_query = new WP_Query( $course_lesson_query_args );
2610
+        $wp_query = new WP_Query($course_lesson_query_args);
2611 2611
 
2612 2612
     }// load_single_course_lessons
2613 2613
 
@@ -2618,16 +2618,16 @@  discard block
 block discarded – undo
2618 2618
      *
2619 2619
      * @param $post_id
2620 2620
      */
2621
-    public static function flush_rewrite_rules( $post_id ){
2621
+    public static function flush_rewrite_rules($post_id) {
2622 2622
 
2623
-        if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){
2623
+        if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
2624 2624
 
2625 2625
             return;
2626 2626
 
2627 2627
         }
2628 2628
 
2629 2629
 
2630
-        if( 'course' == get_post_type( $post_id )  ){
2630
+        if ('course' == get_post_type($post_id)) {
2631 2631
 
2632 2632
             Sensei()->initiate_rewrite_rules_flush();
2633 2633
 
@@ -2643,10 +2643,10 @@  discard block
 block discarded – undo
2643 2643
      * @param $excerpt
2644 2644
      * @return string
2645 2645
      */
2646
-    public static function full_content_excerpt_override( $excerpt ){
2646
+    public static function full_content_excerpt_override($excerpt) {
2647 2647
 
2648
-        if (   is_singular('course')  &&
2649
-                'full' == Sensei()->settings->get( 'course_single_content_display' ) ){
2648
+        if (is_singular('course') &&
2649
+                'full' == Sensei()->settings->get('course_single_content_display')) {
2650 2650
 
2651 2651
             return get_the_content();
2652 2652
 
@@ -2663,60 +2663,60 @@  discard block
 block discarded – undo
2663 2663
      *
2664 2664
      * @since 1.9.0
2665 2665
      */
2666
-    public static function the_course_enrolment_actions(){
2666
+    public static function the_course_enrolment_actions() {
2667 2667
         ?>
2668 2668
         <section class="course-meta course-enrolment">
2669 2669
         <?php
2670 2670
         global  $post, $current_user;
2671
-        $is_user_taking_course = Sensei_Utils::user_started_course( $post->ID, $current_user->ID );
2672
-        if ( is_user_logged_in() && ! $is_user_taking_course ) {
2671
+        $is_user_taking_course = Sensei_Utils::user_started_course($post->ID, $current_user->ID);
2672
+        if (is_user_logged_in() && ! $is_user_taking_course) {
2673 2673
 
2674 2674
             // Get the product ID
2675
-            $wc_post_id = absint( get_post_meta( $post->ID, '_course_woocommerce_product', true ) );
2675
+            $wc_post_id = absint(get_post_meta($post->ID, '_course_woocommerce_product', true));
2676 2676
 
2677 2677
             // Check for woocommerce
2678
-            if ( Sensei_WC::is_woocommerce_active() && ( 0 < intval( $wc_post_id ) ) ) {
2678
+            if (Sensei_WC::is_woocommerce_active() && (0 < intval($wc_post_id))) {
2679 2679
                 sensei_wc_add_to_cart($post->ID);
2680 2680
             } else {
2681 2681
                 sensei_start_course_form($post->ID);
2682 2682
             } // End If Statement
2683 2683
 
2684
-        } elseif ( is_user_logged_in() ) {
2684
+        } elseif (is_user_logged_in()) {
2685 2685
 
2686 2686
             // Check if course is completed
2687
-            $user_course_status = Sensei_Utils::user_course_status( $post->ID, $current_user->ID );
2688
-            $completed_course = Sensei_Utils::user_completed_course( $user_course_status );
2687
+            $user_course_status = Sensei_Utils::user_course_status($post->ID, $current_user->ID);
2688
+            $completed_course = Sensei_Utils::user_completed_course($user_course_status);
2689 2689
             // Success message
2690
-            if ( $completed_course ) { ?>
2691
-                <div class="status completed"><?php  _e( 'Completed', 'woothemes-sensei' ); ?></div>
2690
+            if ($completed_course) { ?>
2691
+                <div class="status completed"><?php  _e('Completed', 'woothemes-sensei'); ?></div>
2692 2692
                 <?php
2693
-                $has_quizzes = Sensei()->course->course_quizzes( $post->ID, true );
2694
-                if( has_filter( 'sensei_results_links' ) || $has_quizzes ) { ?>
2693
+                $has_quizzes = Sensei()->course->course_quizzes($post->ID, true);
2694
+                if (has_filter('sensei_results_links') || $has_quizzes) { ?>
2695 2695
                     <p class="sensei-results-links">
2696 2696
                         <?php
2697 2697
                         $results_link = '';
2698
-                        if( $has_quizzes ) {
2699
-                            $results_link = '<a class="view-results" href="' . Sensei()->course_results->get_permalink( $post->ID ) . '">' .  __( 'View results', 'woothemes-sensei' ) . '</a>';
2698
+                        if ($has_quizzes) {
2699
+                            $results_link = '<a class="view-results" href="'.Sensei()->course_results->get_permalink($post->ID).'">'.__('View results', 'woothemes-sensei').'</a>';
2700 2700
                         }
2701
-                        $results_link = apply_filters( 'sensei_results_links', $results_link );
2701
+                        $results_link = apply_filters('sensei_results_links', $results_link);
2702 2702
                         echo $results_link;
2703 2703
                         ?></p>
2704 2704
                 <?php } ?>
2705 2705
             <?php } else { ?>
2706
-                <div class="status in-progress"><?php echo __( 'In Progress', 'woothemes-sensei' ); ?></div>
2706
+                <div class="status in-progress"><?php echo __('In Progress', 'woothemes-sensei'); ?></div>
2707 2707
             <?php }
2708 2708
 
2709 2709
         } else {
2710 2710
             // Get the product ID
2711
-            $wc_post_id = absint( get_post_meta( $post->ID, '_course_woocommerce_product', true ) );
2711
+            $wc_post_id = absint(get_post_meta($post->ID, '_course_woocommerce_product', true));
2712 2712
             // Check for woocommerce
2713
-            if ( Sensei_WC::is_woocommerce_active() && ( 0 < intval( $wc_post_id ) ) ) {
2713
+            if (Sensei_WC::is_woocommerce_active() && (0 < intval($wc_post_id))) {
2714 2714
 
2715 2715
                 sensei_wc_add_to_cart($post->ID);
2716 2716
 
2717 2717
             } else {
2718 2718
 
2719
-                if( get_option( 'users_can_register') ) {
2719
+                if (get_option('users_can_register')) {
2720 2720
 
2721 2721
 
2722 2722
                     $my_courses_page_id = '';
@@ -2732,24 +2732,24 @@  discard block
 block discarded – undo
2732 2732
                     $wp_register_link = apply_filters('sensei_use_wp_register_link', false);
2733 2733
 
2734 2734
                     $settings = Sensei()->settings->get_settings();
2735
-                    if( isset( $settings[ 'my_course_page' ] )
2736
-                        && 0 < intval( $settings[ 'my_course_page' ] ) ){
2735
+                    if (isset($settings['my_course_page'])
2736
+                        && 0 < intval($settings['my_course_page'])) {
2737 2737
 
2738
-                        $my_courses_page_id = $settings[ 'my_course_page' ];
2738
+                        $my_courses_page_id = $settings['my_course_page'];
2739 2739
 
2740 2740
                     }
2741 2741
 
2742 2742
                     // If a My Courses page was set in Settings, and 'sensei_use_wp_register_link'
2743 2743
                     // is false, link to My Courses. If not, link to default WordPress registration page.
2744
-                    if( !empty( $my_courses_page_id ) && $my_courses_page_id && !$wp_register_link){
2744
+                    if ( ! empty($my_courses_page_id) && $my_courses_page_id && ! $wp_register_link) {
2745 2745
 
2746
-                        $my_courses_url = get_permalink( $my_courses_page_id  );
2747
-                        $register_link = '<a href="'.$my_courses_url. '">' . __('Register', 'woothemes-sensei') .'</a>';
2748
-                        echo '<div class="status register">' . $register_link . '</div>' ;
2746
+                        $my_courses_url = get_permalink($my_courses_page_id);
2747
+                        $register_link = '<a href="'.$my_courses_url.'">'.__('Register', 'woothemes-sensei').'</a>';
2748
+                        echo '<div class="status register">'.$register_link.'</div>';
2749 2749
 
2750
-                    } else{
2750
+                    } else {
2751 2751
 
2752
-                        wp_register( '<div class="status register">', '</div>' );
2752
+                        wp_register('<div class="status register">', '</div>');
2753 2753
 
2754 2754
                     }
2755 2755
 
@@ -2768,19 +2768,19 @@  discard block
 block discarded – undo
2768 2768
      *
2769 2769
      * @since 1.9.0
2770 2770
      */
2771
-    public static function the_course_video(){
2771
+    public static function the_course_video() {
2772 2772
 
2773 2773
         global $post;
2774 2774
         // Get the meta info
2775
-        $course_video_embed = get_post_meta( $post->ID, '_course_video_embed', true );
2775
+        $course_video_embed = get_post_meta($post->ID, '_course_video_embed', true);
2776 2776
 
2777
-        if ( 'http' == substr( $course_video_embed, 0, 4) ) {
2777
+        if ('http' == substr($course_video_embed, 0, 4)) {
2778 2778
 
2779
-            $course_video_embed = wp_oembed_get( esc_url( $course_video_embed ) );
2779
+            $course_video_embed = wp_oembed_get(esc_url($course_video_embed));
2780 2780
 
2781 2781
         } // End If Statement
2782 2782
 
2783
-        if ( '' != $course_video_embed ) { ?>
2783
+        if ('' != $course_video_embed) { ?>
2784 2784
 
2785 2785
             <div class="course-video">
2786 2786
                 <?php echo html_entity_decode($course_video_embed); ?>
@@ -2795,7 +2795,7 @@  discard block
 block discarded – undo
2795 2795
      * @global $post
2796 2796
      * @since 1.9.0
2797 2797
      */
2798
-    public static function the_title(){
2798
+    public static function the_title() {
2799 2799
 
2800 2800
         global $post;
2801 2801
 
@@ -2808,7 +2808,7 @@  discard block
 block discarded – undo
2808 2808
                 /**
2809 2809
                  * Filter documented in class-sensei-messages.php the_title
2810 2810
                  */
2811
-                echo apply_filters( 'sensei_single_title', get_the_title( $post ), $post->post_type );
2811
+                echo apply_filters('sensei_single_title', get_the_title($post), $post->post_type);
2812 2812
                 ?>
2813 2813
 
2814 2814
             </h1>
@@ -2824,30 +2824,30 @@  discard block
 block discarded – undo
2824 2824
      *
2825 2825
      * @since 1.9.0
2826 2826
      */
2827
-    public static function course_category_title(){
2827
+    public static function course_category_title() {
2828 2828
 
2829
-        if( ! is_tax( 'course-category' ) ){
2829
+        if ( ! is_tax('course-category')) {
2830 2830
             return;
2831 2831
         }
2832 2832
 
2833 2833
         $category_slug = get_query_var('course-category');
2834
-        $term  = get_term_by('slug',$category_slug,'course-category');
2834
+        $term = get_term_by('slug', $category_slug, 'course-category');
2835 2835
 
2836
-        if( ! empty($term) ){
2836
+        if ( ! empty($term)) {
2837 2837
 
2838 2838
             $title = $term->name;
2839 2839
 
2840
-        }else{
2840
+        } else {
2841 2841
 
2842 2842
             $title = 'Course Category';
2843 2843
 
2844 2844
         }
2845 2845
 
2846 2846
         $html = '<h2 class="sensei-category-title">';
2847
-        $html .= __('Category') . ' ' . $title;
2847
+        $html .= __('Category').' '.$title;
2848 2848
         $html .= '</h2>';
2849 2849
 
2850
-        echo apply_filters( 'course_category_title', $html , $term->term_id );
2850
+        echo apply_filters('course_category_title', $html, $term->term_id);
2851 2851
 
2852 2852
     }// course_category_title
2853 2853
 
@@ -2860,16 +2860,16 @@  discard block
 block discarded – undo
2860 2860
      * @param WP_Query $query
2861 2861
      * @return WP_Query
2862 2862
      */
2863
-    public static function alter_course_category_order( $query ){
2863
+    public static function alter_course_category_order($query) {
2864 2864
 
2865
-        if( ! is_tax( 'course-category' ) || ! $query->is_main_query() ){
2865
+        if ( ! is_tax('course-category') || ! $query->is_main_query()) {
2866 2866
             return $query;
2867 2867
         }
2868 2868
 
2869
-        $order = get_option( 'sensei_course_order', '' );
2870
-        if( !empty( $order )  ){
2871
-            $query->set('orderby', 'menu_order' );
2872
-            $query->set('order', 'ASC' );
2869
+        $order = get_option('sensei_course_order', '');
2870
+        if ( ! empty($order)) {
2871
+            $query->set('orderby', 'menu_order');
2872
+            $query->set('order', 'ASC');
2873 2873
         }
2874 2874
 
2875 2875
         return $query;
@@ -2890,7 +2890,7 @@  discard block
 block discarded – undo
2890 2890
      *
2891 2891
      * @return array
2892 2892
      */
2893
-    public static function get_default_query_args(){
2893
+    public static function get_default_query_args() {
2894 2894
         return array(
2895 2895
             'post_type' 		=> 'course',
2896 2896
             'posts_per_page' 		=> 1000,
@@ -2908,14 +2908,14 @@  discard block
 block discarded – undo
2908 2908
      * @param $course_id
2909 2909
      * @return bool
2910 2910
      */
2911
-    public static function is_prerequisite_complete( $course_id ){
2911
+    public static function is_prerequisite_complete($course_id) {
2912 2912
 
2913
-        $course_prerequisite_id = get_post_meta( $course_id, '_course_prerequisite', true );
2913
+        $course_prerequisite_id = get_post_meta($course_id, '_course_prerequisite', true);
2914 2914
 
2915 2915
         // if it has a pre requisite course check it
2916
-        if( ! empty(  $course_prerequisite_id ) ){
2916
+        if ( ! empty($course_prerequisite_id)) {
2917 2917
 
2918
-            return Sensei_Utils::user_completed_course( $course_prerequisite_id, get_current_user_id() );
2918
+            return Sensei_Utils::user_completed_course($course_prerequisite_id, get_current_user_id());
2919 2919
 
2920 2920
         }
2921 2921
 
@@ -2931,4 +2931,4 @@  discard block
 block discarded – undo
2931 2931
  * for backward compatibility
2932 2932
  * @since 1.9.0
2933 2933
  */
2934
-class WooThemes_Sensei_Course extends Sensei_Course{}
2934
+class WooThemes_Sensei_Course extends Sensei_Course {}
Please login to merge, or discard this patch.
includes/class-sensei-modules.php 2 patches
Indentation   +1881 added lines, -1881 removed lines patch added patch discarded remove patch
@@ -14,265 +14,265 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class Sensei_Core_Modules
16 16
 {
17
-    private $dir;
18
-    private $file;
19
-    private $assets_dir;
20
-    private $assets_url;
21
-    private $order_page_slug;
22
-    public $taxonomy;
23
-
24
-    public function __construct( $file )
25
-    {
26
-        $this->file = $file;
27
-        $this->dir = dirname($this->file);
28
-        $this->assets_dir = trailingslashit($this->dir) . 'assets';
29
-        $this->assets_url = esc_url(trailingslashit(plugins_url('/assets/', $this->file)));
30
-        $this->taxonomy = 'module';
31
-        $this->order_page_slug = 'module-order';
32
-
33
-        // setup taxonomy
34
-        add_action( 'init', array( $this, 'setup_modules_taxonomy' ), 10 );
35
-
36
-        // Manage lesson meta boxes for taxonomy
37
-        add_action('add_meta_boxes', array($this, 'modules_metaboxes'), 20, 2 );
38
-
39
-        // Save lesson meta box
40
-        add_action('save_post', array($this, 'save_lesson_module'), 10, 1);
41
-
42
-        //Reset the none modules lessons transient
43
-        add_action( 'save_post', array( 'Sensei_Core_Modules', 'reset_none_modules_transient' ) );
44
-
45
-        // Frontend styling
46
-        add_action('wp_enqueue_scripts', array($this, 'enqueue_styles'));
47
-
48
-        // Admin styling
49
-        add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_styles'));
50
-        add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'),  20 , 2 );
51
-
52
-        // Handle module completion record
53
-        add_action('sensei_lesson_status_updated', array($this, 'update_lesson_status_module_progress'), 10, 3);
54
-        add_action('sensei_user_lesson_reset', array($this, 'save_lesson_module_progress'), 10, 2);
55
-        add_action('wp', array($this, 'save_module_progress'), 10);
56
-
57
-        // Handle module ordering
58
-        add_action('admin_menu', array($this, 'register_modules_admin_menu_items'), 30 );
59
-        add_filter('manage_edit-course_columns', array($this, 'course_columns'), 11, 1);
60
-        add_action('manage_posts_custom_column', array($this, 'course_column_content'), 11, 2);
61
-
62
-        // Ensure modules always show under courses
63
-        add_action( 'admin_menu', array( $this, 'remove_lessons_menu_model_taxonomy' ) , 10 );
64
-        add_action( 'admin_menu', array( $this, 'remove_courses_menu_model_taxonomy' ) , 10 );
65
-        add_action( 'admin_menu', array( $this, 'redirect_to_lesson_module_taxonomy_to_course' ) , 20 );
66
-
67
-        // Add course field to taxonomy
68
-        add_action($this->taxonomy . '_add_form_fields', array($this, 'add_module_fields'), 50, 1);
69
-        add_action($this->taxonomy . '_edit_form_fields', array($this, 'edit_module_fields'), 1, 1);
70
-        add_action('edited_' . $this->taxonomy, array($this, 'save_module_course'), 10, 2);
71
-        add_action('created_' . $this->taxonomy, array($this, 'save_module_course'), 10, 2);
72
-        add_action('wp_ajax_sensei_json_search_courses', array($this, 'search_courses_json'));
73
-
74
-        // Manage module taxonomy archive page
75
-        add_filter('template_include', array($this, 'module_archive_template'), 10);
76
-        add_action('pre_get_posts', array($this, 'module_archive_filter'), 10, 1);
77
-        add_filter('sensei_lessons_archive_text', array($this, 'module_archive_title'));
78
-        add_action('sensei_content_lesson_inside_before', array($this, 'module_archive_description'), 11);
79
-        add_action('sensei_pagination', array($this, 'module_navigation_links'), 11);
80
-        add_filter('body_class', array($this, 'module_archive_body_class'));
81
-
82
-        // add modules to the single course template
83
-        add_action( 'sensei_single_course_content_inside_after', array($this, 'load_course_module_content_template') , 8 );
84
-
85
-        //Single Course modules actions. Add to single-course/course-modules.php
86
-        add_action('sensei_single_course_modules_before',array( $this,'course_modules_title' ), 20);
87
-
88
-        // Set up display on single lesson page
89
-        add_filter('sensei_breadcrumb_output', array($this, 'module_breadcrumb_link'), 10, 2);
90
-
91
-        // Add 'Modules' columns to Analysis tables
92
-        add_filter('sensei_analysis_overview_columns', array($this, 'analysis_overview_column_title'), 10, 2);
93
-        add_filter('sensei_analysis_overview_column_data', array($this, 'analysis_overview_column_data'), 10, 3);
94
-        add_filter('sensei_analysis_course_columns', array($this, 'analysis_course_column_title'), 10, 2);
95
-        add_filter('sensei_analysis_course_column_data', array($this, 'analysis_course_column_data'), 10, 3);
96
-
97
-        // Manage module taxonomy columns
98
-        add_filter('manage_edit-' . $this->taxonomy . '_columns', array($this, 'taxonomy_column_headings'), 1, 1);
99
-        add_filter('manage_' . $this->taxonomy . '_custom_column', array($this, 'taxonomy_column_content'), 1, 3);
100
-        add_filter('sensei_module_lesson_list_title', array($this, 'sensei_course_preview_titles'), 10, 2);
101
-
102
-        //store new modules created on the course edit screen
103
-        add_action( 'wp_ajax_sensei_add_new_module_term', array( 'Sensei_Core_Modules','add_new_module_term' ) );
104
-
105
-        // for non admin users, only show taxonomies that belong to them
106
-        add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
107
-        add_filter('get_object_terms', array( $this, 'filter_course_selected_terms' ), 20, 3 );
108
-
109
-        // add the teacher name next to the module term in for admin users
110
-        add_filter('get_terms', array( $this, 'append_teacher_name_to_module' ), 70, 3 );
111
-
112
-        // remove the default modules  metabox
113
-        add_action('admin_init',array( 'Sensei_Core_Modules' , 'remove_default_modules_box' ));
114
-
115
-    } // end constructor
116
-
117
-    /**
118
-     * Alter a module term slug when a new taxonomy term is created
119
-     * This will add the creators user name to the slug for uniqueness.
120
-     *
121
-     * @since 1.8.0
122
-     *
123
-     * @param $term_id
124
-     * @param $tt_id
125
-     * @param $taxonomy
126
-     *
127
-     * @return void
128
-     * @deprecated since 1.9.0
129
-     */
130
-    public function change_module_term_slug( $term_id, $tt_id, $taxonomy ){
131
-
132
-        _deprecated_function('change_module_term_slug', '1.9.0' );
133
-
134
-    }// end add_module_term_group
135
-
136
-    /**
137
-     * Hook in all meta boxes related tot he modules taxonomy
138
-     *
139
-     * @since 1.8.0
140
-     *
141
-     * @param string $post_type
142
-     * @param WP_Post $post
143
-     *
144
-     * @return void
145
-     */
146
-    public function modules_metaboxes( $post_type, $post )
147
-    {
148
-        if ('lesson' == $post_type ) {
149
-
150
-            // Remove default taxonomy meta box from Lesson edit screen
151
-            remove_meta_box($this->taxonomy . 'div', 'lesson', 'side');
152
-
153
-            // Add custom meta box to limit module selection to one per lesson
154
-            add_meta_box($this->taxonomy . '_select', __('Lesson Module', 'woothemes-sensei'), array($this, 'lesson_module_metabox'), 'lesson', 'side', 'default');
155
-        }
156
-
157
-        if( 'course' == $post_type ){
158
-            // Course modules selection metabox
159
-            add_meta_box( $this->taxonomy . '_course_mb', __('Course Modules', 'woothemes-sensei'), array( $this, 'course_module_metabox'), 'course', 'side', 'core');
160
-        }
161
-    }
162
-
163
-    /**
164
-     * Build content for custom module meta box
165
-     *
166
-     * @since 1.8.0
167
-     * @param  object $post Current post object
168
-     * @return void
169
-     */
170
-    public function lesson_module_metabox($post)
171
-    {
172
-
173
-        // Get lesson course
174
-        $lesson_course = get_post_meta($post->ID, '_lesson_course', true);
175
-
176
-        $html = '';
177
-
178
-        // Only show module selection if this lesson is part of a course
179
-        if ($lesson_course && $lesson_course > 0) {
180
-
181
-            // Get existing lesson module
182
-            $lesson_module = 0;
183
-            $lesson_module_list = wp_get_post_terms($post->ID, $this->taxonomy);
184
-            if (is_array($lesson_module_list) && count($lesson_module_list) > 0) {
185
-                foreach ($lesson_module_list as $single_module) {
186
-                    $lesson_module = $single_module->term_id;
187
-                    break;
188
-                }
189
-            }
190
-
191
-            // Get the available modules for this lesson's course
192
-            $modules = $this->get_course_modules($lesson_course);
193
-
194
-            // Build the HTML to output
195
-            $html .= '<input type="hidden" name="' . esc_attr('woo_lesson_' . $this->taxonomy . '_nonce') . '" id="' . esc_attr('woo_lesson_' . $this->taxonomy . '_nonce') . '" value="' . esc_attr(wp_create_nonce(plugin_basename($this->file))) . '" />';
196
-            if (is_array($modules) && count($modules) > 0) {
197
-                $html .= '<select id="lesson-module-options" name="lesson_module" class="widefat">' . "\n";
198
-                $html .= '<option value="">' . __('None', 'woothemes-sensei') . '</option>';
199
-                foreach ($modules as $module) {
200
-                    $html .= '<option value="' . esc_attr(absint($module->term_id)) . '"' . selected($module->term_id, $lesson_module, false) . '>' . esc_html($module->name) . '</option>' . "\n";
201
-                }
202
-                $html .= '</select>' . "\n";
203
-            } else {
204
-                $course_url = admin_url('post.php?post=' . urlencode($lesson_course) . '&action=edit');
205
-                $html .= '<p>' . sprintf(__('No modules are available for this lesson yet. %1$sPlease add some to %3$sthe course%4$s.%2$s', 'woothemes-sensei'), '<em>', '</em>', '<a href="' . esc_url($course_url) . '">', '</a>') . '</p>';
206
-            } // End If Statement
207
-
208
-        } else {
209
-            $html .= '<p>' . sprintf(__('No modules are available for this lesson yet. %1$sPlease select a course first.%2$s', 'woothemes-sensei'), '<em>', '</em>') . '</p>';
210
-        } // End If Statement
211
-
212
-        // Output the HTML
213
-        echo $html;
214
-    }
215
-
216
-    /**
217
-     * Save module to lesson
218
-     *
219
-     * @since 1.8.0
220
-     * @param  integer $post_id ID of post
221
-     * @return mixed            Post ID on permissions failure, boolean true on success
222
-     */
223
-    public function save_lesson_module($post_id)
224
-    {
225
-        global $post;
226
-
227
-        // Verify post type and nonce
228
-        if ((get_post_type() != 'lesson') || !isset($_POST['woo_lesson_' . $this->taxonomy . '_nonce'] )
229
-            ||!wp_verify_nonce($_POST['woo_lesson_' . $this->taxonomy . '_nonce'], plugin_basename($this->file))) {
230
-            return $post_id;
231
-        }
232
-
233
-        // Check if user has permissions to edit lessons
234
-        $post_type = get_post_type_object($post->post_type);
235
-        if (!current_user_can($post_type->cap->edit_post, $post_id)) {
236
-            return $post_id;
237
-        }
238
-
239
-        // Check if user has permissions to edit this specific post
240
-        if (!current_user_can('edit_post', $post_id)) {
241
-            return $post_id;
242
-        }
243
-
244
-        // Cast module ID as an integer if selected, otherwise leave as empty string
245
-        if ( isset( $_POST['lesson_module'] ) ) {
246
-
247
-            if( empty ( $_POST['lesson_module'] ) ){
248
-                wp_delete_object_term_relationships($post_id, $this->taxonomy  );
249
-                return true;
250
-            }
251
-
252
-            $module_id = intval( $_POST['lesson_module'] );
253
-
254
-            // Assign lesson to selected module
255
-            wp_set_object_terms($post_id, $module_id, $this->taxonomy, false);
256
-
257
-            // Set default order for lesson inside module
258
-            if (!get_post_meta($post_id, '_order_module_' . $module_id, true)) {
259
-                update_post_meta($post_id, '_order_module_' . $module_id, 0);
260
-            }
261
-        }
262
-
263
-        return true;
264
-    }
265
-
266
-    /**
267
-     * Display course field on new module screen
268
-     *
269
-     * @since 1.8.0
270
-     * @param object $taxonomy Taxonomy object
271
-     * @return void
272
-     */
273
-    public function add_module_fields($taxonomy)
274
-    {
275
-        ?>
17
+	private $dir;
18
+	private $file;
19
+	private $assets_dir;
20
+	private $assets_url;
21
+	private $order_page_slug;
22
+	public $taxonomy;
23
+
24
+	public function __construct( $file )
25
+	{
26
+		$this->file = $file;
27
+		$this->dir = dirname($this->file);
28
+		$this->assets_dir = trailingslashit($this->dir) . 'assets';
29
+		$this->assets_url = esc_url(trailingslashit(plugins_url('/assets/', $this->file)));
30
+		$this->taxonomy = 'module';
31
+		$this->order_page_slug = 'module-order';
32
+
33
+		// setup taxonomy
34
+		add_action( 'init', array( $this, 'setup_modules_taxonomy' ), 10 );
35
+
36
+		// Manage lesson meta boxes for taxonomy
37
+		add_action('add_meta_boxes', array($this, 'modules_metaboxes'), 20, 2 );
38
+
39
+		// Save lesson meta box
40
+		add_action('save_post', array($this, 'save_lesson_module'), 10, 1);
41
+
42
+		//Reset the none modules lessons transient
43
+		add_action( 'save_post', array( 'Sensei_Core_Modules', 'reset_none_modules_transient' ) );
44
+
45
+		// Frontend styling
46
+		add_action('wp_enqueue_scripts', array($this, 'enqueue_styles'));
47
+
48
+		// Admin styling
49
+		add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_styles'));
50
+		add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'),  20 , 2 );
51
+
52
+		// Handle module completion record
53
+		add_action('sensei_lesson_status_updated', array($this, 'update_lesson_status_module_progress'), 10, 3);
54
+		add_action('sensei_user_lesson_reset', array($this, 'save_lesson_module_progress'), 10, 2);
55
+		add_action('wp', array($this, 'save_module_progress'), 10);
56
+
57
+		// Handle module ordering
58
+		add_action('admin_menu', array($this, 'register_modules_admin_menu_items'), 30 );
59
+		add_filter('manage_edit-course_columns', array($this, 'course_columns'), 11, 1);
60
+		add_action('manage_posts_custom_column', array($this, 'course_column_content'), 11, 2);
61
+
62
+		// Ensure modules always show under courses
63
+		add_action( 'admin_menu', array( $this, 'remove_lessons_menu_model_taxonomy' ) , 10 );
64
+		add_action( 'admin_menu', array( $this, 'remove_courses_menu_model_taxonomy' ) , 10 );
65
+		add_action( 'admin_menu', array( $this, 'redirect_to_lesson_module_taxonomy_to_course' ) , 20 );
66
+
67
+		// Add course field to taxonomy
68
+		add_action($this->taxonomy . '_add_form_fields', array($this, 'add_module_fields'), 50, 1);
69
+		add_action($this->taxonomy . '_edit_form_fields', array($this, 'edit_module_fields'), 1, 1);
70
+		add_action('edited_' . $this->taxonomy, array($this, 'save_module_course'), 10, 2);
71
+		add_action('created_' . $this->taxonomy, array($this, 'save_module_course'), 10, 2);
72
+		add_action('wp_ajax_sensei_json_search_courses', array($this, 'search_courses_json'));
73
+
74
+		// Manage module taxonomy archive page
75
+		add_filter('template_include', array($this, 'module_archive_template'), 10);
76
+		add_action('pre_get_posts', array($this, 'module_archive_filter'), 10, 1);
77
+		add_filter('sensei_lessons_archive_text', array($this, 'module_archive_title'));
78
+		add_action('sensei_content_lesson_inside_before', array($this, 'module_archive_description'), 11);
79
+		add_action('sensei_pagination', array($this, 'module_navigation_links'), 11);
80
+		add_filter('body_class', array($this, 'module_archive_body_class'));
81
+
82
+		// add modules to the single course template
83
+		add_action( 'sensei_single_course_content_inside_after', array($this, 'load_course_module_content_template') , 8 );
84
+
85
+		//Single Course modules actions. Add to single-course/course-modules.php
86
+		add_action('sensei_single_course_modules_before',array( $this,'course_modules_title' ), 20);
87
+
88
+		// Set up display on single lesson page
89
+		add_filter('sensei_breadcrumb_output', array($this, 'module_breadcrumb_link'), 10, 2);
90
+
91
+		// Add 'Modules' columns to Analysis tables
92
+		add_filter('sensei_analysis_overview_columns', array($this, 'analysis_overview_column_title'), 10, 2);
93
+		add_filter('sensei_analysis_overview_column_data', array($this, 'analysis_overview_column_data'), 10, 3);
94
+		add_filter('sensei_analysis_course_columns', array($this, 'analysis_course_column_title'), 10, 2);
95
+		add_filter('sensei_analysis_course_column_data', array($this, 'analysis_course_column_data'), 10, 3);
96
+
97
+		// Manage module taxonomy columns
98
+		add_filter('manage_edit-' . $this->taxonomy . '_columns', array($this, 'taxonomy_column_headings'), 1, 1);
99
+		add_filter('manage_' . $this->taxonomy . '_custom_column', array($this, 'taxonomy_column_content'), 1, 3);
100
+		add_filter('sensei_module_lesson_list_title', array($this, 'sensei_course_preview_titles'), 10, 2);
101
+
102
+		//store new modules created on the course edit screen
103
+		add_action( 'wp_ajax_sensei_add_new_module_term', array( 'Sensei_Core_Modules','add_new_module_term' ) );
104
+
105
+		// for non admin users, only show taxonomies that belong to them
106
+		add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
107
+		add_filter('get_object_terms', array( $this, 'filter_course_selected_terms' ), 20, 3 );
108
+
109
+		// add the teacher name next to the module term in for admin users
110
+		add_filter('get_terms', array( $this, 'append_teacher_name_to_module' ), 70, 3 );
111
+
112
+		// remove the default modules  metabox
113
+		add_action('admin_init',array( 'Sensei_Core_Modules' , 'remove_default_modules_box' ));
114
+
115
+	} // end constructor
116
+
117
+	/**
118
+	 * Alter a module term slug when a new taxonomy term is created
119
+	 * This will add the creators user name to the slug for uniqueness.
120
+	 *
121
+	 * @since 1.8.0
122
+	 *
123
+	 * @param $term_id
124
+	 * @param $tt_id
125
+	 * @param $taxonomy
126
+	 *
127
+	 * @return void
128
+	 * @deprecated since 1.9.0
129
+	 */
130
+	public function change_module_term_slug( $term_id, $tt_id, $taxonomy ){
131
+
132
+		_deprecated_function('change_module_term_slug', '1.9.0' );
133
+
134
+	}// end add_module_term_group
135
+
136
+	/**
137
+	 * Hook in all meta boxes related tot he modules taxonomy
138
+	 *
139
+	 * @since 1.8.0
140
+	 *
141
+	 * @param string $post_type
142
+	 * @param WP_Post $post
143
+	 *
144
+	 * @return void
145
+	 */
146
+	public function modules_metaboxes( $post_type, $post )
147
+	{
148
+		if ('lesson' == $post_type ) {
149
+
150
+			// Remove default taxonomy meta box from Lesson edit screen
151
+			remove_meta_box($this->taxonomy . 'div', 'lesson', 'side');
152
+
153
+			// Add custom meta box to limit module selection to one per lesson
154
+			add_meta_box($this->taxonomy . '_select', __('Lesson Module', 'woothemes-sensei'), array($this, 'lesson_module_metabox'), 'lesson', 'side', 'default');
155
+		}
156
+
157
+		if( 'course' == $post_type ){
158
+			// Course modules selection metabox
159
+			add_meta_box( $this->taxonomy . '_course_mb', __('Course Modules', 'woothemes-sensei'), array( $this, 'course_module_metabox'), 'course', 'side', 'core');
160
+		}
161
+	}
162
+
163
+	/**
164
+	 * Build content for custom module meta box
165
+	 *
166
+	 * @since 1.8.0
167
+	 * @param  object $post Current post object
168
+	 * @return void
169
+	 */
170
+	public function lesson_module_metabox($post)
171
+	{
172
+
173
+		// Get lesson course
174
+		$lesson_course = get_post_meta($post->ID, '_lesson_course', true);
175
+
176
+		$html = '';
177
+
178
+		// Only show module selection if this lesson is part of a course
179
+		if ($lesson_course && $lesson_course > 0) {
180
+
181
+			// Get existing lesson module
182
+			$lesson_module = 0;
183
+			$lesson_module_list = wp_get_post_terms($post->ID, $this->taxonomy);
184
+			if (is_array($lesson_module_list) && count($lesson_module_list) > 0) {
185
+				foreach ($lesson_module_list as $single_module) {
186
+					$lesson_module = $single_module->term_id;
187
+					break;
188
+				}
189
+			}
190
+
191
+			// Get the available modules for this lesson's course
192
+			$modules = $this->get_course_modules($lesson_course);
193
+
194
+			// Build the HTML to output
195
+			$html .= '<input type="hidden" name="' . esc_attr('woo_lesson_' . $this->taxonomy . '_nonce') . '" id="' . esc_attr('woo_lesson_' . $this->taxonomy . '_nonce') . '" value="' . esc_attr(wp_create_nonce(plugin_basename($this->file))) . '" />';
196
+			if (is_array($modules) && count($modules) > 0) {
197
+				$html .= '<select id="lesson-module-options" name="lesson_module" class="widefat">' . "\n";
198
+				$html .= '<option value="">' . __('None', 'woothemes-sensei') . '</option>';
199
+				foreach ($modules as $module) {
200
+					$html .= '<option value="' . esc_attr(absint($module->term_id)) . '"' . selected($module->term_id, $lesson_module, false) . '>' . esc_html($module->name) . '</option>' . "\n";
201
+				}
202
+				$html .= '</select>' . "\n";
203
+			} else {
204
+				$course_url = admin_url('post.php?post=' . urlencode($lesson_course) . '&action=edit');
205
+				$html .= '<p>' . sprintf(__('No modules are available for this lesson yet. %1$sPlease add some to %3$sthe course%4$s.%2$s', 'woothemes-sensei'), '<em>', '</em>', '<a href="' . esc_url($course_url) . '">', '</a>') . '</p>';
206
+			} // End If Statement
207
+
208
+		} else {
209
+			$html .= '<p>' . sprintf(__('No modules are available for this lesson yet. %1$sPlease select a course first.%2$s', 'woothemes-sensei'), '<em>', '</em>') . '</p>';
210
+		} // End If Statement
211
+
212
+		// Output the HTML
213
+		echo $html;
214
+	}
215
+
216
+	/**
217
+	 * Save module to lesson
218
+	 *
219
+	 * @since 1.8.0
220
+	 * @param  integer $post_id ID of post
221
+	 * @return mixed            Post ID on permissions failure, boolean true on success
222
+	 */
223
+	public function save_lesson_module($post_id)
224
+	{
225
+		global $post;
226
+
227
+		// Verify post type and nonce
228
+		if ((get_post_type() != 'lesson') || !isset($_POST['woo_lesson_' . $this->taxonomy . '_nonce'] )
229
+			||!wp_verify_nonce($_POST['woo_lesson_' . $this->taxonomy . '_nonce'], plugin_basename($this->file))) {
230
+			return $post_id;
231
+		}
232
+
233
+		// Check if user has permissions to edit lessons
234
+		$post_type = get_post_type_object($post->post_type);
235
+		if (!current_user_can($post_type->cap->edit_post, $post_id)) {
236
+			return $post_id;
237
+		}
238
+
239
+		// Check if user has permissions to edit this specific post
240
+		if (!current_user_can('edit_post', $post_id)) {
241
+			return $post_id;
242
+		}
243
+
244
+		// Cast module ID as an integer if selected, otherwise leave as empty string
245
+		if ( isset( $_POST['lesson_module'] ) ) {
246
+
247
+			if( empty ( $_POST['lesson_module'] ) ){
248
+				wp_delete_object_term_relationships($post_id, $this->taxonomy  );
249
+				return true;
250
+			}
251
+
252
+			$module_id = intval( $_POST['lesson_module'] );
253
+
254
+			// Assign lesson to selected module
255
+			wp_set_object_terms($post_id, $module_id, $this->taxonomy, false);
256
+
257
+			// Set default order for lesson inside module
258
+			if (!get_post_meta($post_id, '_order_module_' . $module_id, true)) {
259
+				update_post_meta($post_id, '_order_module_' . $module_id, 0);
260
+			}
261
+		}
262
+
263
+		return true;
264
+	}
265
+
266
+	/**
267
+	 * Display course field on new module screen
268
+	 *
269
+	 * @since 1.8.0
270
+	 * @param object $taxonomy Taxonomy object
271
+	 * @return void
272
+	 */
273
+	public function add_module_fields($taxonomy)
274
+	{
275
+		?>
276 276
         <div class="form-field">
277 277
             <label for="module_courses"><?php _e('Course(s)', 'woothemes-sensei'); ?></label>
278 278
             <input type="hidden" id="module_courses" name="module_courses" class="ajax_chosen_select_courses"
@@ -281,44 +281,44 @@  discard block
 block discarded – undo
281 281
                 class="description"><?php _e('Search for and select the courses that this module will belong to.', 'woothemes-sensei'); ?></span>
282 282
         </div>
283 283
     <?php
284
-    }
285
-
286
-    /**
287
-     * Display course field on module edit screen
288
-     *
289
-     * @since 1.8.0
290
-     * @param  object $module Module term object
291
-     * @return void
292
-     */
293
-    public function edit_module_fields($module)
294
-    {
295
-
296
-        $module_id = $module->term_id;
297
-
298
-        // Get module's existing courses
299
-        $args = array(
300
-            'post_type' => 'course',
301
-            'post_status' => array('publish', 'draft', 'future', 'private'),
302
-            'posts_per_page' => -1,
303
-            'tax_query' => array(
304
-                array(
305
-                    'taxonomy' => $this->taxonomy,
306
-                    'field' => 'id',
307
-                    'terms' => $module_id
308
-                )
309
-            )
310
-        );
311
-        $courses = get_posts($args);
312
-
313
-        //build the defaults array
314
-        $module_courses = array();
315
-        if (isset($courses) && is_array($courses)) {
316
-            foreach ($courses as $course) {
317
-                $module_courses[] =   array( 'id' =>$course->ID, 'details'=>$course->post_title );
318
-            }
319
-        }
320
-
321
-        ?>
284
+	}
285
+
286
+	/**
287
+	 * Display course field on module edit screen
288
+	 *
289
+	 * @since 1.8.0
290
+	 * @param  object $module Module term object
291
+	 * @return void
292
+	 */
293
+	public function edit_module_fields($module)
294
+	{
295
+
296
+		$module_id = $module->term_id;
297
+
298
+		// Get module's existing courses
299
+		$args = array(
300
+			'post_type' => 'course',
301
+			'post_status' => array('publish', 'draft', 'future', 'private'),
302
+			'posts_per_page' => -1,
303
+			'tax_query' => array(
304
+				array(
305
+					'taxonomy' => $this->taxonomy,
306
+					'field' => 'id',
307
+					'terms' => $module_id
308
+				)
309
+			)
310
+		);
311
+		$courses = get_posts($args);
312
+
313
+		//build the defaults array
314
+		$module_courses = array();
315
+		if (isset($courses) && is_array($courses)) {
316
+			foreach ($courses as $course) {
317
+				$module_courses[] =   array( 'id' =>$course->ID, 'details'=>$course->post_title );
318
+			}
319
+		}
320
+
321
+		?>
322 322
         <tr class="form-field">
323 323
             <th scope="row" valign="top"><label
324 324
                     for="module_courses"><?php _e('Course(s)', 'woothemes-sensei'); ?></label></th>
@@ -335,1399 +335,1399 @@  discard block
 block discarded – undo
335 335
             </td>
336 336
         </tr>
337 337
     <?php
338
-    }
339
-
340
-    /**
341
-     * Save module course on add/edit
342
-     *
343
-     * @since 1.8.0
344
-     * @param  integer $module_id ID of module
345
-     * @return void
346
-     */
347
-    public function save_module_course($module_id)
348
-    {
349
-
350
-        // Get module's existing courses
351
-        $args = array(
352
-            'post_type' => 'course',
353
-            'post_status' => array('publish', 'draft', 'future', 'private'),
354
-            'posts_per_page' => -1,
355
-            'tax_query' => array(
356
-                array(
357
-                    'taxonomy' => $this->taxonomy,
358
-                    'field' => 'id',
359
-                    'terms' => $module_id
360
-                )
361
-            )
362
-        );
363
-        $courses = get_posts($args);
364
-
365
-        // Remove module from existing courses
366
-        if (isset($courses) && is_array($courses)) {
367
-            foreach ($courses as $course) {
368
-                wp_remove_object_terms($course->ID, $module_id, $this->taxonomy);
369
-            }
370
-        }
371
-
372
-        // Add module to selected courses
373
-        if ( isset( $_POST['module_courses'] ) && ! empty( $_POST['module_courses'] ) ) {
374
-
375
-            $course_ids = explode( ",", $_POST['module_courses'] );
376
-
377
-            foreach ( $course_ids as $course_id ) {
378
-
379
-                wp_set_object_terms($course_id, $module_id, $this->taxonomy, true);
380
-
381
-            }
382
-        }
383
-    }
384
-
385
-    /**
386
-     * Ajax function to search for courses matching term
387
-     *
388
-     * @since 1.8.0
389
-     * @return void
390
-     */
391
-    public function search_courses_json()
392
-    {
393
-
394
-        // Security check
395
-        check_ajax_referer('search-courses', 'security');
396
-
397
-        // Set content type
398
-        header('Content-Type: application/json; charset=utf-8');
399
-
400
-        // Get user input
401
-        $term = urldecode(stripslashes($_GET['term']));
402
-
403
-        // Return nothing if term is empty
404
-        if (empty($term))
405
-            die();
406
-
407
-        // Set a default if none is given
408
-        $default = isset($_GET['default']) ? $_GET['default'] : __('No course', 'woothemes-sensei');
409
-
410
-        // Set up array of results
411
-        $found_courses = array('' => $default);
412
-
413
-        // Fetch results
414
-        $args = array(
415
-            'post_type' => 'course',
416
-            'post_status' => array('publish', 'draft', 'future', 'private'),
417
-            'posts_per_page' => -1,
418
-            'orderby' => 'title',
419
-            's' => $term
420
-        );
421
-        $courses = get_posts($args);
422
-
423
-        // Add results to array
424
-        if ($courses) {
425
-            foreach ($courses as $course) {
426
-                $found_courses[$course->ID] = $course->post_title;
427
-            }
428
-        }
429
-
430
-        // Encode and return results for processing & selection
431
-        echo json_encode($found_courses);
432
-        die();
433
-    }
434
-
435
-    /**
436
-     * display modules on single course pages
437
-     *
438
-     * @since 1.8.0
439
-     * @return void
440
-     */
441
-    public function single_course_modules(){
442
-
443
-        _deprecated_function('Sensei_Modules->single_course_modules','Sensei 1.9.0', 'Sensei()->modules->load_course_module_content_template');
444
-        // only show modules on the course that has modules
445
-        if( is_singular( 'course' ) && has_term( '', 'module' )  )  {
446
-
447
-            $this->load_course_module_content_template();
448
-
449
-        }
450
-
451
-    } // end single_course_modules
452
-
453
-    public function sensei_course_preview_titles($title, $lesson_id)
454
-    {
455
-        global $post, $current_user;
456
-
457
-        $course_id = $post->ID;
458
-        $title_text = '';
459
-
460
-        if (method_exists('Sensei_Utils', 'is_preview_lesson') && Sensei_Utils::is_preview_lesson($lesson_id)) {
461
-            $is_user_taking_course = Sensei_Utils::sensei_check_for_activity(array('post_id' => $course_id, 'user_id' => $current_user->ID, 'type' => 'sensei_course_status'));
462
-            if (!$is_user_taking_course) {
463
-                if (method_exists('WooThemes_Sensei_Frontend', 'sensei_lesson_preview_title_text')) {
464
-                    $title_text = Sensei()->frontend->sensei_lesson_preview_title_text($course_id);
465
-                    // Remove brackets for display here
466
-                    $title_text = str_replace('(', '', $title_text);
467
-                    $title_text = str_replace(')', '', $title_text);
468
-                    $title_text = '<span class="preview-label">' . $title_text . '</span>';
469
-                }
470
-                $title .= ' ' . $title_text;
471
-            }
472
-        }
473
-
474
-        return $title;
475
-    }
476
-
477
-    public function module_breadcrumb_link($html, $separator)
478
-    {
479
-        global $post;
480
-        // Lesson
481
-        if (is_singular('lesson')) {
482
-            if (has_term('', $this->taxonomy, $post->ID)) {
483
-                $module = $this->get_lesson_module($post->ID);
484
-                if( $module ) {
485
-                    $html .= ' ' . $separator . ' <a href="' . esc_url($module->url) . '" title="' .  __('Back to the module', 'woothemes-sensei') . '">' . $module->name . '</a>';
486
-                }
487
-            }
488
-        }
489
-        // Module
490
-        if (is_tax($this->taxonomy)) {
491
-            if (isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) {
492
-                $course_id = intval($_GET['course_id']);
493
-                $html .= '<a href="' . esc_url(get_permalink($course_id)) . '" title="' .  __('Back to the course', 'woothemes-sensei') . '">' . get_the_title($course_id) . '</a>';
494
-            }
495
-        }
496
-        return $html;
497
-    }
498
-
499
-    /**
500
-     * Set lesson archive template to display on module taxonomy archive page
501
-     *
502
-     * @since 1.8.0
503
-     * @param  string $template Default template
504
-     * @return string           Modified template
505
-     */
506
-    public function module_archive_template($template) {
507
-
508
-        if ( ! is_tax($this->taxonomy) ) {
509
-            return $template;
510
-        }
511
-
512
-        $file = 'archive-lesson.php';
513
-        $find = array( $file, Sensei()->template_url . $file );
514
-
515
-        // locate the template file
516
-        $template = locate_template($find);
517
-        if (!$template) {
518
-
519
-            $template = Sensei()->plugin_path() . 'templates/' . $file;
520
-
521
-        }
522
-
523
-
524
-        return $template;
525
-    }
526
-
527
-    /**
528
-     * Modify module taxonomy archive query
529
-     *
530
-     * @since 1.8.0
531
-     * @param  object $query The query object passed by reference
532
-     * @return void
533
-     */
534
-    public function module_archive_filter($query)
535
-    {
536
-        if (is_tax($this->taxonomy) && $query->is_main_query()) {
537
-
538
-
539
-            // Limit to lessons only
540
-            $query->set('post_type', 'lesson');
541
-
542
-            // Set order of lessons
543
-            if (version_compare(Sensei()->version, '1.6.0', '>=')) {
544
-                $module_id = $query->queried_object_id;
545
-                $query->set('meta_key', '_order_module_' . $module_id);
546
-                $query->set('orderby', 'meta_value_num date');
547
-            } else {
548
-                $query->set('orderby', 'menu_order');
549
-            }
550
-            $query->set('order', 'ASC');
551
-
552
-            // Limit to specific course if specified
553
-            if (isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) {
554
-                $course_id = intval($_GET['course_id']);
555
-                $meta_query[] = array(
556
-                    'key' => '_lesson_course',
557
-                    'value' => intval($course_id)
558
-                );
559
-                $query->set('meta_query', $meta_query);
560
-            }
561
-
562
-        }
563
-    }
564
-
565
-    /**
566
-     * Modify archive page title
567
-     *
568
-     * @since 1.8.0
569
-     * @param  string $title Default title
570
-     * @return string        Modified title
571
-     */
572
-    public function module_archive_title($title)
573
-    {
574
-        if (is_tax($this->taxonomy)) {
575
-            $title = apply_filters('sensei_module_archive_title', get_queried_object()->name);
576
-        }
577
-        return $title;
578
-    }
579
-
580
-    /**
581
-     * Display module description on taxonomy archive page
582
-     *
583
-     * @since 1.8.0
584
-     * @return void
585
-     */
586
-    public function module_archive_description()
587
-    {
588
-        if (is_tax($this->taxonomy)) {
589
-
590
-            $module = get_queried_object();
591
-
592
-            $module_progress = false;
593
-            if (is_user_logged_in() && isset($_GET['course_id']) && intval($_GET['course_id']) > 0) {
594
-                global $current_user;
595
-                wp_get_current_user();
596
-                $module_progress = $this->get_user_module_progress($module->term_id, $_GET['course_id'], $current_user->ID);
597
-            }
598
-
599
-            if ($module_progress && $module_progress > 0) {
600
-                $status = __('Completed', 'woothemes-sensei');
601
-                $class = 'completed';
602
-                if ($module_progress < 100) {
603
-                    $status = __('In progress', 'woothemes-sensei');
604
-                    $class = 'in-progress';
605
-                }
606
-                echo '<p class="status ' . esc_attr($class) . '">' . $status . '</p>';
607
-            }
608
-
609
-            echo '<p class="archive-description module-description">' . apply_filters('sensei_module_archive_description', nl2br($module->description), $module->term_id) . '</p>';
610
-        }
611
-    }
612
-
613
-    public function module_archive_body_class($classes)
614
-    {
615
-        if (is_tax($this->taxonomy)) {
616
-            $classes[] = 'module-archive';
617
-        }
618
-        return $classes;
619
-    }
620
-
621
-    /**
622
-     * Display module navigation links on module taxonomy archive page
623
-     *
624
-     * @since 1.8.0
625
-     * @return void
626
-     */
627
-    public function module_navigation_links()
628
-    {
629
-        if (is_tax($this->taxonomy) && isset($_GET['course_id'])) {
630
-
631
-            $queried_module = get_queried_object();
632
-            $course_modules = $this->get_course_modules($_GET['course_id']);
633
-
634
-            $prev_module = false;
635
-            $next_module = false;
636
-            $on_current = false;
637
-            foreach ($course_modules as $module) {
638
-                $this_module = $module;
639
-                if ($on_current) {
640
-                    $next_module = $this_module;
641
-                    break;
642
-                }
643
-                if ($this_module == $queried_module) {
644
-                    $on_current = true;
645
-                } else {
646
-                    $prev_module = $module;
647
-                }
648
-            }
649
-
650
-            ?>
338
+	}
339
+
340
+	/**
341
+	 * Save module course on add/edit
342
+	 *
343
+	 * @since 1.8.0
344
+	 * @param  integer $module_id ID of module
345
+	 * @return void
346
+	 */
347
+	public function save_module_course($module_id)
348
+	{
349
+
350
+		// Get module's existing courses
351
+		$args = array(
352
+			'post_type' => 'course',
353
+			'post_status' => array('publish', 'draft', 'future', 'private'),
354
+			'posts_per_page' => -1,
355
+			'tax_query' => array(
356
+				array(
357
+					'taxonomy' => $this->taxonomy,
358
+					'field' => 'id',
359
+					'terms' => $module_id
360
+				)
361
+			)
362
+		);
363
+		$courses = get_posts($args);
364
+
365
+		// Remove module from existing courses
366
+		if (isset($courses) && is_array($courses)) {
367
+			foreach ($courses as $course) {
368
+				wp_remove_object_terms($course->ID, $module_id, $this->taxonomy);
369
+			}
370
+		}
371
+
372
+		// Add module to selected courses
373
+		if ( isset( $_POST['module_courses'] ) && ! empty( $_POST['module_courses'] ) ) {
374
+
375
+			$course_ids = explode( ",", $_POST['module_courses'] );
376
+
377
+			foreach ( $course_ids as $course_id ) {
378
+
379
+				wp_set_object_terms($course_id, $module_id, $this->taxonomy, true);
380
+
381
+			}
382
+		}
383
+	}
384
+
385
+	/**
386
+	 * Ajax function to search for courses matching term
387
+	 *
388
+	 * @since 1.8.0
389
+	 * @return void
390
+	 */
391
+	public function search_courses_json()
392
+	{
393
+
394
+		// Security check
395
+		check_ajax_referer('search-courses', 'security');
396
+
397
+		// Set content type
398
+		header('Content-Type: application/json; charset=utf-8');
399
+
400
+		// Get user input
401
+		$term = urldecode(stripslashes($_GET['term']));
402
+
403
+		// Return nothing if term is empty
404
+		if (empty($term))
405
+			die();
406
+
407
+		// Set a default if none is given
408
+		$default = isset($_GET['default']) ? $_GET['default'] : __('No course', 'woothemes-sensei');
409
+
410
+		// Set up array of results
411
+		$found_courses = array('' => $default);
412
+
413
+		// Fetch results
414
+		$args = array(
415
+			'post_type' => 'course',
416
+			'post_status' => array('publish', 'draft', 'future', 'private'),
417
+			'posts_per_page' => -1,
418
+			'orderby' => 'title',
419
+			's' => $term
420
+		);
421
+		$courses = get_posts($args);
422
+
423
+		// Add results to array
424
+		if ($courses) {
425
+			foreach ($courses as $course) {
426
+				$found_courses[$course->ID] = $course->post_title;
427
+			}
428
+		}
429
+
430
+		// Encode and return results for processing & selection
431
+		echo json_encode($found_courses);
432
+		die();
433
+	}
434
+
435
+	/**
436
+	 * display modules on single course pages
437
+	 *
438
+	 * @since 1.8.0
439
+	 * @return void
440
+	 */
441
+	public function single_course_modules(){
442
+
443
+		_deprecated_function('Sensei_Modules->single_course_modules','Sensei 1.9.0', 'Sensei()->modules->load_course_module_content_template');
444
+		// only show modules on the course that has modules
445
+		if( is_singular( 'course' ) && has_term( '', 'module' )  )  {
446
+
447
+			$this->load_course_module_content_template();
448
+
449
+		}
450
+
451
+	} // end single_course_modules
452
+
453
+	public function sensei_course_preview_titles($title, $lesson_id)
454
+	{
455
+		global $post, $current_user;
456
+
457
+		$course_id = $post->ID;
458
+		$title_text = '';
459
+
460
+		if (method_exists('Sensei_Utils', 'is_preview_lesson') && Sensei_Utils::is_preview_lesson($lesson_id)) {
461
+			$is_user_taking_course = Sensei_Utils::sensei_check_for_activity(array('post_id' => $course_id, 'user_id' => $current_user->ID, 'type' => 'sensei_course_status'));
462
+			if (!$is_user_taking_course) {
463
+				if (method_exists('WooThemes_Sensei_Frontend', 'sensei_lesson_preview_title_text')) {
464
+					$title_text = Sensei()->frontend->sensei_lesson_preview_title_text($course_id);
465
+					// Remove brackets for display here
466
+					$title_text = str_replace('(', '', $title_text);
467
+					$title_text = str_replace(')', '', $title_text);
468
+					$title_text = '<span class="preview-label">' . $title_text . '</span>';
469
+				}
470
+				$title .= ' ' . $title_text;
471
+			}
472
+		}
473
+
474
+		return $title;
475
+	}
476
+
477
+	public function module_breadcrumb_link($html, $separator)
478
+	{
479
+		global $post;
480
+		// Lesson
481
+		if (is_singular('lesson')) {
482
+			if (has_term('', $this->taxonomy, $post->ID)) {
483
+				$module = $this->get_lesson_module($post->ID);
484
+				if( $module ) {
485
+					$html .= ' ' . $separator . ' <a href="' . esc_url($module->url) . '" title="' .  __('Back to the module', 'woothemes-sensei') . '">' . $module->name . '</a>';
486
+				}
487
+			}
488
+		}
489
+		// Module
490
+		if (is_tax($this->taxonomy)) {
491
+			if (isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) {
492
+				$course_id = intval($_GET['course_id']);
493
+				$html .= '<a href="' . esc_url(get_permalink($course_id)) . '" title="' .  __('Back to the course', 'woothemes-sensei') . '">' . get_the_title($course_id) . '</a>';
494
+			}
495
+		}
496
+		return $html;
497
+	}
498
+
499
+	/**
500
+	 * Set lesson archive template to display on module taxonomy archive page
501
+	 *
502
+	 * @since 1.8.0
503
+	 * @param  string $template Default template
504
+	 * @return string           Modified template
505
+	 */
506
+	public function module_archive_template($template) {
507
+
508
+		if ( ! is_tax($this->taxonomy) ) {
509
+			return $template;
510
+		}
511
+
512
+		$file = 'archive-lesson.php';
513
+		$find = array( $file, Sensei()->template_url . $file );
514
+
515
+		// locate the template file
516
+		$template = locate_template($find);
517
+		if (!$template) {
518
+
519
+			$template = Sensei()->plugin_path() . 'templates/' . $file;
520
+
521
+		}
522
+
523
+
524
+		return $template;
525
+	}
526
+
527
+	/**
528
+	 * Modify module taxonomy archive query
529
+	 *
530
+	 * @since 1.8.0
531
+	 * @param  object $query The query object passed by reference
532
+	 * @return void
533
+	 */
534
+	public function module_archive_filter($query)
535
+	{
536
+		if (is_tax($this->taxonomy) && $query->is_main_query()) {
537
+
538
+
539
+			// Limit to lessons only
540
+			$query->set('post_type', 'lesson');
541
+
542
+			// Set order of lessons
543
+			if (version_compare(Sensei()->version, '1.6.0', '>=')) {
544
+				$module_id = $query->queried_object_id;
545
+				$query->set('meta_key', '_order_module_' . $module_id);
546
+				$query->set('orderby', 'meta_value_num date');
547
+			} else {
548
+				$query->set('orderby', 'menu_order');
549
+			}
550
+			$query->set('order', 'ASC');
551
+
552
+			// Limit to specific course if specified
553
+			if (isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) {
554
+				$course_id = intval($_GET['course_id']);
555
+				$meta_query[] = array(
556
+					'key' => '_lesson_course',
557
+					'value' => intval($course_id)
558
+				);
559
+				$query->set('meta_query', $meta_query);
560
+			}
561
+
562
+		}
563
+	}
564
+
565
+	/**
566
+	 * Modify archive page title
567
+	 *
568
+	 * @since 1.8.0
569
+	 * @param  string $title Default title
570
+	 * @return string        Modified title
571
+	 */
572
+	public function module_archive_title($title)
573
+	{
574
+		if (is_tax($this->taxonomy)) {
575
+			$title = apply_filters('sensei_module_archive_title', get_queried_object()->name);
576
+		}
577
+		return $title;
578
+	}
579
+
580
+	/**
581
+	 * Display module description on taxonomy archive page
582
+	 *
583
+	 * @since 1.8.0
584
+	 * @return void
585
+	 */
586
+	public function module_archive_description()
587
+	{
588
+		if (is_tax($this->taxonomy)) {
589
+
590
+			$module = get_queried_object();
591
+
592
+			$module_progress = false;
593
+			if (is_user_logged_in() && isset($_GET['course_id']) && intval($_GET['course_id']) > 0) {
594
+				global $current_user;
595
+				wp_get_current_user();
596
+				$module_progress = $this->get_user_module_progress($module->term_id, $_GET['course_id'], $current_user->ID);
597
+			}
598
+
599
+			if ($module_progress && $module_progress > 0) {
600
+				$status = __('Completed', 'woothemes-sensei');
601
+				$class = 'completed';
602
+				if ($module_progress < 100) {
603
+					$status = __('In progress', 'woothemes-sensei');
604
+					$class = 'in-progress';
605
+				}
606
+				echo '<p class="status ' . esc_attr($class) . '">' . $status . '</p>';
607
+			}
608
+
609
+			echo '<p class="archive-description module-description">' . apply_filters('sensei_module_archive_description', nl2br($module->description), $module->term_id) . '</p>';
610
+		}
611
+	}
612
+
613
+	public function module_archive_body_class($classes)
614
+	{
615
+		if (is_tax($this->taxonomy)) {
616
+			$classes[] = 'module-archive';
617
+		}
618
+		return $classes;
619
+	}
620
+
621
+	/**
622
+	 * Display module navigation links on module taxonomy archive page
623
+	 *
624
+	 * @since 1.8.0
625
+	 * @return void
626
+	 */
627
+	public function module_navigation_links()
628
+	{
629
+		if (is_tax($this->taxonomy) && isset($_GET['course_id'])) {
630
+
631
+			$queried_module = get_queried_object();
632
+			$course_modules = $this->get_course_modules($_GET['course_id']);
633
+
634
+			$prev_module = false;
635
+			$next_module = false;
636
+			$on_current = false;
637
+			foreach ($course_modules as $module) {
638
+				$this_module = $module;
639
+				if ($on_current) {
640
+					$next_module = $this_module;
641
+					break;
642
+				}
643
+				if ($this_module == $queried_module) {
644
+					$on_current = true;
645
+				} else {
646
+					$prev_module = $module;
647
+				}
648
+			}
649
+
650
+			?>
651 651
             <div id="post-entries" class="post-entries module-navigation fix">
652 652
                 <?php if ($next_module) {
653
-                    $module_link = add_query_arg('course_id', intval($_GET['course_id']), get_term_link($next_module, $this->taxonomy));
654
-                    ?>
653
+					$module_link = add_query_arg('course_id', intval($_GET['course_id']), get_term_link($next_module, $this->taxonomy));
654
+					?>
655 655
                     <div class="nav-next fr"><a href="<?php echo esc_url($module_link); ?>"
656 656
                                                 title="<?php esc_attr_e('Next module', 'woothemes-sensei'); ?>"><?php echo $next_module->name; ?>
657 657
                             <span class="meta-nav"></span></a></div>
658 658
                 <?php } ?>
659 659
                 <?php if ($prev_module) {
660
-                    $module_link = add_query_arg('course_id', intval($_GET['course_id']), get_term_link($prev_module, $this->taxonomy));
661
-                    ?>
660
+					$module_link = add_query_arg('course_id', intval($_GET['course_id']), get_term_link($prev_module, $this->taxonomy));
661
+					?>
662 662
                     <div class="nav-prev fl"><a href="<?php echo esc_url($module_link); ?>"
663 663
                                                 title="<?php _e('Previous module', 'woothemes-sensei'); ?>"><span
664 664
                                 class="meta-nav"></span> <?php echo $prev_module->name; ?></a></div>
665 665
                 <?php } ?>
666 666
             </div>
667 667
         <?php
668
-        }
669
-    }
670
-
671
-    /**
672
-     * Trigger save_lesson_module_progress() when a lesson status is updated for a specific user
673
-     *
674
-     * @since 1.8.0
675
-     * @param  string $status Status of the lesson for the user
676
-     * @param  integer $user_id ID of user
677
-     * @param  integer $lesson_id ID of lesson
678
-     * @return void
679
-     */
680
-    public function update_lesson_status_module_progress($status = '', $user_id = 0, $lesson_id = 0)
681
-    {
682
-        $this->save_lesson_module_progress($user_id, $lesson_id);
683
-    }
684
-
685
-    /**
686
-     * Save lesson's module progress for a specific user
687
-     *
688
-     * @since 1.8.0
689
-     * @param  integer $user_id ID of user
690
-     * @param  integer $lesson_id ID of lesson
691
-     * @return void
692
-     */
693
-    public function save_lesson_module_progress($user_id = 0, $lesson_id = 0)
694
-    {
695
-        $module = $this->get_lesson_module($lesson_id);
696
-        $course_id = get_post_meta($lesson_id, '_lesson_course', true);
697
-        if ($module && $course_id) {
698
-            $this->save_user_module_progress(intval($module->term_id), intval($course_id), intval($user_id));
699
-        }
700
-    }
701
-
702
-    /**
703
-     * Save progress of module for user
704
-     *
705
-     * @since 1.8.0
706
-     * @return void
707
-     */
708
-    public function save_module_progress()
709
-    {
710
-        if (is_tax($this->taxonomy) && is_user_logged_in() && isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) {
711
-            global $current_user;
712
-            wp_get_current_user();
713
-            $user_id = $current_user->ID;
714
-
715
-            $module = get_queried_object();
716
-
717
-            $this->save_user_module_progress(intval($module->term_id), intval($_GET['course_id']), intval($user_id));
718
-        }
719
-    }
720
-
721
-    /**
722
-     * Save module progess for user
723
-     *
724
-     * @since 1.8.0
725
-     *
726
-     * @param  integer $module_id ID of module
727
-     * @param  integer $course_id ID of course
728
-     * @param  integer $user_id ID of user
729
-     * @return void
730
-     */
731
-    public function save_user_module_progress($module_id = 0, $course_id = 0, $user_id = 0)
732
-    {
733
-        $module_progress = $this->calculate_user_module_progress($user_id, $module_id, $course_id);
734
-        update_user_meta(intval($user_id), '_module_progress_' . intval($course_id) . '_' . intval($module_id), intval($module_progress));
735
-
736
-        do_action('sensei_module_save_user_progress', $course_id, $module_id, $user_id, $module_progress);
737
-    }
738
-
739
-    /**
740
-     * Get module progress for a user
741
-     *
742
-     * @since 1.8.0
743
-     *
744
-     * @param  integer $module_id ID of module
745
-     * @param  integer $course_id ID of course
746
-     * @param  integer $user_id ID of user
747
-     * @return mixed              Module progress percentage on success, false on failure
748
-     */
749
-    public function get_user_module_progress($module_id = 0, $course_id = 0, $user_id = 0)
750
-    {
751
-        $module_progress = get_user_meta(intval($user_id), '_module_progress_' . intval($course_id) . '_' . intval($module_id), true);
752
-        if ($module_progress) {
753
-            return (float)$module_progress;
754
-        }
755
-        return false;
756
-    }
757
-
758
-    /**
759
-     * Calculate module progess for user
760
-     *
761
-     * @since 1.8.0
762
-     *
763
-     * @param  integer $user_id ID of user
764
-     * @param  integer $module_id ID of module
765
-     * @param  integer $course_id ID of course
766
-     * @return integer            Module progress percentage
767
-     */
768
-    public function calculate_user_module_progress($user_id = 0, $module_id = 0, $course_id = 0)
769
-    {
770
-
771
-        $args = array(
772
-            'post_type' => 'lesson',
773
-            'post_status' => 'publish',
774
-            'posts_per_page' => -1,
775
-            'tax_query' => array(
776
-                array(
777
-                    'taxonomy' => $this->taxonomy,
778
-                    'field' => 'id',
779
-                    'terms' => $module_id
780
-                )
781
-            ),
782
-            'meta_query' => array(
783
-                array(
784
-                    'key' => '_lesson_course',
785
-                    'value' => $course_id
786
-                )
787
-            ),
788
-            'fields' => 'ids'
789
-        );
790
-        $lessons = get_posts($args);
791
-
792
-        if (is_wp_error($lessons) || 0 >= count($lessons)) return 0;
793
-
794
-        $completed = false;
795
-        $lesson_count = 0;
796
-        $completed_count = 0;
797
-        foreach ($lessons as $lesson_id) {
798
-            $completed = Sensei_Utils::user_completed_lesson($lesson_id, $user_id);
799
-            ++$lesson_count;
800
-            if ($completed) {
801
-                ++$completed_count;
802
-            }
803
-        }
804
-        $module_progress = ($completed_count / $lesson_count) * 100;
805
-
806
-        return (float)$module_progress;
807
-    }
808
-
809
-    /**
810
-     * Register admin screen for ordering modules
811
-     *
812
-     * @since 1.8.0
813
-     *
814
-     * @return void
815
-     */
816
-    public function register_modules_admin_menu_items()
817
-    {
818
-        //add the modules link under the Course main menu
819
-        add_submenu_page('edit.php?post_type=course', __('Modules', 'woothemes-sensei'), __('Modules', 'woothemes-sensei'), 'manage_categories', 'edit-tags.php?taxonomy=module','' );
820
-
821
-        // Regsiter new admin page for module ordering
822
-        $hook = add_submenu_page('edit.php?post_type=course', __('Order Modules', 'woothemes-sensei'), __('Order Modules', 'woothemes-sensei'), 'edit_lessons', $this->order_page_slug, array($this, 'module_order_screen'));
823
-
824
-    }
825
-
826
-    /**
827
-     * Display Module Order screen
828
-     *
829
-     * @since 1.8.0
830
-     *
831
-     * @return void
832
-     */
833
-    public function module_order_screen()
834
-    {
835
-        ?>
668
+		}
669
+	}
670
+
671
+	/**
672
+	 * Trigger save_lesson_module_progress() when a lesson status is updated for a specific user
673
+	 *
674
+	 * @since 1.8.0
675
+	 * @param  string $status Status of the lesson for the user
676
+	 * @param  integer $user_id ID of user
677
+	 * @param  integer $lesson_id ID of lesson
678
+	 * @return void
679
+	 */
680
+	public function update_lesson_status_module_progress($status = '', $user_id = 0, $lesson_id = 0)
681
+	{
682
+		$this->save_lesson_module_progress($user_id, $lesson_id);
683
+	}
684
+
685
+	/**
686
+	 * Save lesson's module progress for a specific user
687
+	 *
688
+	 * @since 1.8.0
689
+	 * @param  integer $user_id ID of user
690
+	 * @param  integer $lesson_id ID of lesson
691
+	 * @return void
692
+	 */
693
+	public function save_lesson_module_progress($user_id = 0, $lesson_id = 0)
694
+	{
695
+		$module = $this->get_lesson_module($lesson_id);
696
+		$course_id = get_post_meta($lesson_id, '_lesson_course', true);
697
+		if ($module && $course_id) {
698
+			$this->save_user_module_progress(intval($module->term_id), intval($course_id), intval($user_id));
699
+		}
700
+	}
701
+
702
+	/**
703
+	 * Save progress of module for user
704
+	 *
705
+	 * @since 1.8.0
706
+	 * @return void
707
+	 */
708
+	public function save_module_progress()
709
+	{
710
+		if (is_tax($this->taxonomy) && is_user_logged_in() && isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) {
711
+			global $current_user;
712
+			wp_get_current_user();
713
+			$user_id = $current_user->ID;
714
+
715
+			$module = get_queried_object();
716
+
717
+			$this->save_user_module_progress(intval($module->term_id), intval($_GET['course_id']), intval($user_id));
718
+		}
719
+	}
720
+
721
+	/**
722
+	 * Save module progess for user
723
+	 *
724
+	 * @since 1.8.0
725
+	 *
726
+	 * @param  integer $module_id ID of module
727
+	 * @param  integer $course_id ID of course
728
+	 * @param  integer $user_id ID of user
729
+	 * @return void
730
+	 */
731
+	public function save_user_module_progress($module_id = 0, $course_id = 0, $user_id = 0)
732
+	{
733
+		$module_progress = $this->calculate_user_module_progress($user_id, $module_id, $course_id);
734
+		update_user_meta(intval($user_id), '_module_progress_' . intval($course_id) . '_' . intval($module_id), intval($module_progress));
735
+
736
+		do_action('sensei_module_save_user_progress', $course_id, $module_id, $user_id, $module_progress);
737
+	}
738
+
739
+	/**
740
+	 * Get module progress for a user
741
+	 *
742
+	 * @since 1.8.0
743
+	 *
744
+	 * @param  integer $module_id ID of module
745
+	 * @param  integer $course_id ID of course
746
+	 * @param  integer $user_id ID of user
747
+	 * @return mixed              Module progress percentage on success, false on failure
748
+	 */
749
+	public function get_user_module_progress($module_id = 0, $course_id = 0, $user_id = 0)
750
+	{
751
+		$module_progress = get_user_meta(intval($user_id), '_module_progress_' . intval($course_id) . '_' . intval($module_id), true);
752
+		if ($module_progress) {
753
+			return (float)$module_progress;
754
+		}
755
+		return false;
756
+	}
757
+
758
+	/**
759
+	 * Calculate module progess for user
760
+	 *
761
+	 * @since 1.8.0
762
+	 *
763
+	 * @param  integer $user_id ID of user
764
+	 * @param  integer $module_id ID of module
765
+	 * @param  integer $course_id ID of course
766
+	 * @return integer            Module progress percentage
767
+	 */
768
+	public function calculate_user_module_progress($user_id = 0, $module_id = 0, $course_id = 0)
769
+	{
770
+
771
+		$args = array(
772
+			'post_type' => 'lesson',
773
+			'post_status' => 'publish',
774
+			'posts_per_page' => -1,
775
+			'tax_query' => array(
776
+				array(
777
+					'taxonomy' => $this->taxonomy,
778
+					'field' => 'id',
779
+					'terms' => $module_id
780
+				)
781
+			),
782
+			'meta_query' => array(
783
+				array(
784
+					'key' => '_lesson_course',
785
+					'value' => $course_id
786
+				)
787
+			),
788
+			'fields' => 'ids'
789
+		);
790
+		$lessons = get_posts($args);
791
+
792
+		if (is_wp_error($lessons) || 0 >= count($lessons)) return 0;
793
+
794
+		$completed = false;
795
+		$lesson_count = 0;
796
+		$completed_count = 0;
797
+		foreach ($lessons as $lesson_id) {
798
+			$completed = Sensei_Utils::user_completed_lesson($lesson_id, $user_id);
799
+			++$lesson_count;
800
+			if ($completed) {
801
+				++$completed_count;
802
+			}
803
+		}
804
+		$module_progress = ($completed_count / $lesson_count) * 100;
805
+
806
+		return (float)$module_progress;
807
+	}
808
+
809
+	/**
810
+	 * Register admin screen for ordering modules
811
+	 *
812
+	 * @since 1.8.0
813
+	 *
814
+	 * @return void
815
+	 */
816
+	public function register_modules_admin_menu_items()
817
+	{
818
+		//add the modules link under the Course main menu
819
+		add_submenu_page('edit.php?post_type=course', __('Modules', 'woothemes-sensei'), __('Modules', 'woothemes-sensei'), 'manage_categories', 'edit-tags.php?taxonomy=module','' );
820
+
821
+		// Regsiter new admin page for module ordering
822
+		$hook = add_submenu_page('edit.php?post_type=course', __('Order Modules', 'woothemes-sensei'), __('Order Modules', 'woothemes-sensei'), 'edit_lessons', $this->order_page_slug, array($this, 'module_order_screen'));
823
+
824
+	}
825
+
826
+	/**
827
+	 * Display Module Order screen
828
+	 *
829
+	 * @since 1.8.0
830
+	 *
831
+	 * @return void
832
+	 */
833
+	public function module_order_screen()
834
+	{
835
+		?>
836 836
         <div id="<?php echo esc_attr($this->order_page_slug); ?>"
837 837
              class="wrap <?php echo esc_attr($this->order_page_slug); ?>">
838 838
         <h2><?php _e('Order Modules', 'woothemes-sensei'); ?></h2><?php
839 839
 
840
-        $html = '';
841
-
842
-        if (isset($_POST['module-order']) && 0 < strlen($_POST['module-order'])) {
843
-            $ordered = $this->save_course_module_order(esc_attr($_POST['module-order']), esc_attr($_POST['course_id']));
844
-
845
-            if ($ordered) {
846
-                $html .= '<div class="updated fade">' . "\n";
847
-                $html .= '<p>' . __('The module order has been saved for this course.', 'woothemes-sensei') . '</p>' . "\n";
848
-                $html .= '</div>' . "\n";
849
-            }
850
-        }
851
-
852
-        $courses = Sensei()->course->get_all_courses();
853
-
854
-        $html .= '<form action="' . admin_url('edit.php') . '" method="get">' . "\n";
855
-        $html .= '<input type="hidden" name="post_type" value="course" />' . "\n";
856
-        $html .= '<input type="hidden" name="page" value="' . esc_attr($this->order_page_slug) . '" />' . "\n";
857
-        $html .= '<select id="module-order-course" name="course_id">' . "\n";
858
-        $html .= '<option value="">' . __('Select a course', 'woothemes-sensei') . '</option>' . "\n";
859
-
860
-        foreach ($courses as $course) {
861
-            if (has_term('', $this->taxonomy, $course->ID)) {
862
-                $course_id = '';
863
-                if (isset($_GET['course_id'])) {
864
-                    $course_id = intval($_GET['course_id']);
865
-                }
866
-                $html .= '<option value="' . esc_attr(intval($course->ID)) . '" ' . selected($course->ID, $course_id, false) . '>' . get_the_title($course->ID) . '</option>' . "\n";
867
-            }
868
-        }
869
-
870
-        $html .= '</select>' . "\n";
871
-        $html .= '<input type="submit" class="button-primary module-order-select-course-submit" value="' . __('Select', 'woothemes-sensei') . '" />' . "\n";
872
-        $html .= '</form>' . "\n";
873
-
874
-        if (isset($_GET['course_id'])) {
875
-            $course_id = intval($_GET['course_id']);
876
-            if ($course_id > 0) {
877
-                $modules = $this->get_course_modules($course_id);
878
-                $modules = $this->append_teacher_name_to_module( $modules, array( 'module' ), array() );
879
-                if ($modules) {
880
-
881
-                    $order = $this->get_course_module_order($course_id);
882
-
883
-                    $order_string='';
884
-                    if ($order) {
885
-                        $order_string = implode(',', $order);
886
-                    }
887
-
888
-                    $html .= '<form id="editgrouping" method="post" action="" class="validate">' . "\n";
889
-                    $html .= '<ul class="sortable-module-list">' . "\n";
890
-                    $count = 0;
891
-                    foreach ($modules as $module) {
892
-                        $count++;
893
-                        $class = $this->taxonomy;
894
-                        if ($count == 1) {
895
-                            $class .= ' first';
896
-                        }
897
-                        if ($count == count($module)) {
898
-                            $class .= ' last';
899
-                        }
900
-                        if ($count % 2 != 0) {
901
-                            $class .= ' alternate';
902
-                        }
903
-                        $html .= '<li class="' . esc_attr($class) . '"><span rel="' . esc_attr($module->term_id) . '" style="width: 100%;"> ' . $module->name . '</span></li>' . "\n";
904
-                    }
905
-                    $html .= '</ul>' . "\n";
906
-
907
-                    $html .= '<input type="hidden" name="module-order" value="' . $order_string . '" />' . "\n";
908
-                    $html .= '<input type="hidden" name="course_id" value="' . $course_id . '" />' . "\n";
909
-                    $html .= '<input type="submit" class="button-primary" value="' . __('Save module order', 'woothemes-sensei') . '" />' . "\n";
910
-                    $html .= '<a href="' . admin_url('post.php?post=' . $course_id . '&action=edit') . '" class="button-secondary">' . __('Edit course', 'woothemes-sensei') . '</a>' . "\n";
911
-                }
912
-            }
913
-        }
914
-
915
-        echo $html;
916
-
917
-        ?></div><?php
918
-    }
919
-
920
-    /**
921
-     * Add 'Module order' column to courses list table
922
-     *
923
-     * @since 1.8.0
924
-     *
925
-     * @param  array $columns Existing columns
926
-     * @return array           Modifed columns
927
-     */
928
-    public function course_columns($columns = array())
929
-    {
930
-        $columns['module_order'] = __('Module order', 'woothemes-sensei');
931
-        return $columns;
932
-    }
933
-
934
-    /**
935
-     * Load content in 'Module order' column
936
-     *
937
-     * @since 1.8.0
938
-     *
939
-     * @param  string $column Current column name
940
-     * @param  integer $course_id ID of course
941
-     * @return void
942
-     */
943
-    public function course_column_content($column = '', $course_id = 0)
944
-    {
945
-        if ($column == 'module_order') {
946
-            if (has_term('', $this->taxonomy, $course_id)) {
947
-                echo '<a class="button-secondary" href="' . admin_url('edit.php?post_type=course&page=module-order&course_id=' . urlencode(intval($course_id))) . '">' . __('Order modules', 'woothemes-sensei') . '</a>';
948
-            }
949
-        }
950
-    }
951
-
952
-    /**
953
-     * Save module order for course
954
-     *
955
-     * @since 1.8.0
956
-     *
957
-     * @param  string $order_string Comma-separated string of module IDs
958
-     * @param  integer $course_id ID of course
959
-     * @return boolean                 True on success, false on failure
960
-     */
961
-    private function save_course_module_order($order_string = '', $course_id = 0)
962
-    {
963
-        if ($order_string && $course_id) {
964
-            $order = explode(',', $order_string);
965
-            update_post_meta(intval($course_id), '_module_order', $order);
966
-            return true;
967
-        }
968
-        return false;
969
-    }
970
-
971
-    /**
972
-     * Get module order for course
973
-     *
974
-     * @since 1.8.0
975
-     *
976
-     * @param  integer $course_id ID of course
977
-     * @return mixed              Module order on success, false if no module order has been saved
978
-     */
979
-    public function get_course_module_order($course_id = 0)
980
-    {
981
-        if ($course_id) {
982
-            $order = get_post_meta(intval($course_id), '_module_order', true);
983
-            return $order;
984
-        }
985
-        return false;
986
-    }
987
-
988
-    /**
989
-     * Modify module taxonomy columns
990
-     *
991
-     * @since 1.8.0
992
-     *
993
-     * @param  array $columns Default columns
994
-     * @return array          Modified columns
995
-     */
996
-    public function taxonomy_column_headings($columns)
997
-    {
998
-
999
-        unset($columns['posts']);
1000
-
1001
-        $columns['lessons'] = __('Lessons', 'woothemes-sensei');
1002
-
1003
-        return $columns;
1004
-    }
1005
-
1006
-    /**
1007
-     * Manage content in custom module taxonomy columns
1008
-     *
1009
-     * @since 1.8.0
1010
-     *
1011
-     * @param  string $column_data Default data for column
1012
-     * @param  string $column_name Name of current column
1013
-     * @param  integer $term_id ID of current term
1014
-     * @return string               Modified column data
1015
-     */
1016
-    public function taxonomy_column_content($column_data, $column_name, $term_id)
1017
-    {
1018
-
1019
-        $args = array(
1020
-            'post_status' => 'publish',
1021
-            'posts_per_page' => -1,
1022
-            'tax_query' => array(
1023
-                array(
1024
-                    'taxonomy' => $this->taxonomy,
1025
-                    'field' => 'id',
1026
-                    'terms' => intval($term_id)
1027
-                )
1028
-            )
1029
-        );
1030
-
1031
-        $module = get_term($term_id, $this->taxonomy);
1032
-
1033
-        switch ($column_name) {
1034
-
1035
-            case 'lessons':
1036
-                $args['post_type'] = 'lesson';
1037
-                $lessons = get_posts($args);
1038
-                $total_lessons = count($lessons);
1039
-                $column_data = '<a href="' . admin_url('edit.php?module=' . urlencode($module->slug) . '&post_type=lesson') . '">' . intval($total_lessons) . '</a>';
1040
-                break;
1041
-        }
1042
-
1043
-        return $column_data;
1044
-    }
1045
-
1046
-    /**
1047
-     * Add 'Module' columns to Analysis Lesson Overview table
1048
-     *
1049
-     * @since 1.8.0
1050
-     *
1051
-     * @param  array $columns Default columns
1052
-     * @return array          Modified columns
1053
-     */
1054
-    public function analysis_overview_column_title($columns)
1055
-    {
1056
-
1057
-        if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) {
1058
-            $new_columns = array();
1059
-            if (is_array($columns) && 0 < count($columns)) {
1060
-                foreach ($columns as $column => $title) {
1061
-                    $new_columns[$column] = $title;
1062
-                    if ($column == 'title') {
1063
-                        $new_columns['lesson_module'] = __('Module', 'woothemes-sensei');
1064
-                    }
1065
-                }
1066
-            }
1067
-
1068
-            if (0 < count($new_columns)) {
1069
-                return $new_columns;
1070
-            }
1071
-        }
1072
-
1073
-        return $columns;
1074
-    }
1075
-
1076
-    /**
1077
-     * Data for 'Module' column Analysis Lesson Overview table
1078
-     *
1079
-     * @since 1.8.0
1080
-     *
1081
-     * @param  array $columns Table column data
1082
-     * @param  WP_Post $lesson
1083
-     * @return array              Updated column data
1084
-     */
1085
-    public function analysis_overview_column_data($columns, $lesson )
1086
-    {
1087
-
1088
-        if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) {
1089
-            $lesson_module = '';
1090
-            $lesson_module_list = wp_get_post_terms($lesson->ID, $this->taxonomy);
1091
-            if (is_array($lesson_module_list) && count($lesson_module_list) > 0) {
1092
-                foreach ($lesson_module_list as $single_module) {
1093
-                    $lesson_module = '<a href="' . esc_url(admin_url('edit-tags.php?action=edit&taxonomy=' . urlencode($this->taxonomy) . '&tag_ID=' . urlencode($single_module->term_id))) . '">' . $single_module->name . '</a>';
1094
-                    break;
1095
-                }
1096
-            }
1097
-
1098
-            $columns['lesson_module'] = $lesson_module;
1099
-        }
1100
-
1101
-        return $columns;
1102
-    }
1103
-
1104
-    /**
1105
-     * Add 'Module' columns to Analysis Course table
1106
-     *
1107
-     * @since 1.8.0
1108
-     *
1109
-     * @param  array $columns Default columns
1110
-     * @return array          Modified columns
1111
-     */
1112
-    public function analysis_course_column_title($columns)
1113
-    {
1114
-        if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) {
1115
-            $columns['lesson_module'] = __('Module', 'woothemes-sensei');
1116
-        }
1117
-        return $columns;
1118
-    }
1119
-
1120
-    /**
1121
-     * Data for 'Module' column in Analysis Course table
1122
-     *
1123
-     * @since 1.8.0
1124
-     *
1125
-     * @param  array $columns Table column data
1126
-     * @param  WP_Post $lesson
1127
-     * @return array              Updated columns data
1128
-     */
1129
-    public function analysis_course_column_data($columns, $lesson )
1130
-    {
1131
-
1132
-        if ( isset( $_GET['course_id'] ) ) {
1133
-            $lesson_module = '';
1134
-            $lesson_module_list = wp_get_post_terms($lesson->ID, $this->taxonomy);
1135
-            if (is_array($lesson_module_list) && count($lesson_module_list) > 0) {
1136
-                foreach ($lesson_module_list as $single_module) {
1137
-                    $lesson_module = '<a href="' . esc_url(admin_url('edit-tags.php?action=edit&taxonomy=' . urlencode($this->taxonomy) . '&tag_ID=' . urlencode($single_module->term_id))) . '">' . $single_module->name . '</a>';
1138
-                    break;
1139
-                }
1140
-            }
1141
-
1142
-            $columns['lesson_module'] = $lesson_module;
1143
-        }
1144
-
1145
-        return $columns;
1146
-    }
1147
-
1148
-    /**
1149
-     * Get module for lesson
1150
-     *
1151
-     * This function also checks if the module still
1152
-     * exists on the course before returning it. Although
1153
-     * the lesson has a module the same module must exist on the
1154
-     * course for it to be valid.
1155
-     *
1156
-     * @since 1.8.0
1157
-     *
1158
-     * @param  integer $lesson_id ID of lesson
1159
-     * @return object             Module taxonomy term object
1160
-     */
1161
-    public function get_lesson_module($lesson_id = 0)
1162
-    {
1163
-        $lesson_id = intval($lesson_id);
1164
-        if ( ! ( intval( $lesson_id > 0) ) ) {
1165
-            return false;
1166
-        }
1167
-
1168
-        // get taxonomy terms on this lesson
1169
-        $modules = wp_get_post_terms($lesson_id, $this->taxonomy);
1170
-
1171
-        //check if error returned
1172
-        if( empty( $modules ) || isset( $modules['errors']  ) ){
1173
-            return false;
1174
-        }
1175
-
1176
-       // get the last item in the array there should be only be 1 really.
1177
-       // this method works for all php versions.
1178
-       foreach( $modules as $module ){
1179
-           break;
1180
-       }
1181
-
1182
-        if ( ! isset($module) || ! is_object($module) || is_wp_error($module)) {
1183
-            return false;
1184
-        }
1185
-
1186
-        $module->url = get_term_link($module, $this->taxonomy);
1187
-        $course_id = intval(get_post_meta(intval($lesson_id), '_lesson_course', true));
1188
-        if (isset($course_id) && 0 < $course_id) {
1189
-
1190
-            // the course should contain the same module taxonomy term for this to be valid
1191
-            if( ! has_term( $module, $this->taxonomy, $course_id)){
1192
-                return false;
1193
-            }
1194
-
1195
-            $module->url = esc_url(add_query_arg('course_id', intval($course_id), $module->url));
1196
-        }
1197
-        return $module;
1198
-
1199
-    }
1200
-
1201
-    /**
1202
-     * Get ordered array of all modules in course
1203
-     *
1204
-     * @since 1.8.0
1205
-     *
1206
-     * @param  integer $course_id ID of course
1207
-     * @return array              Ordered array of module taxonomy term objects
1208
-     */
1209
-    public function get_course_modules($course_id = 0)
1210
-    {
1211
-        $course_id = intval($course_id);
1212
-        if (0 < $course_id) {
1213
-
1214
-            // Get modules for course
1215
-            $modules = wp_get_post_terms($course_id, $this->taxonomy);
1216
-
1217
-            // Get custom module order for course
1218
-            $order = $this->get_course_module_order($course_id);
1219
-
1220
-            // Sort by custom order if custom order exists
1221
-            if ($order) {
1222
-                $ordered_modules = array();
1223
-                $unordered_modules = array();
1224
-                foreach ($modules as $module) {
1225
-                    $order_key = array_search($module->term_id, $order);
1226
-                    if ($order_key !== false) {
1227
-                        $ordered_modules[$order_key] = $module;
1228
-                    } else {
1229
-                        $unordered_modules[] = $module;
1230
-                    }
1231
-                }
1232
-
1233
-                // Order modules correctly
1234
-                ksort($ordered_modules);
1235
-
1236
-                // Append modules that have not yet been ordered
1237
-                if (count($unordered_modules) > 0) {
1238
-                    $ordered_modules = array_merge($ordered_modules, $unordered_modules);
1239
-                }
1240
-
1241
-            } else {
1242
-
1243
-                $ordered_modules = $modules;
1244
-
1245
-            }
1246
-
1247
-            return $ordered_modules;
1248
-
1249
-        }
1250
-
1251
-        return false;
1252
-    }
1253
-
1254
-    /**
1255
-     * Load frontend CSS
1256
-     *
1257
-     * @since 1.8.0
1258
-     *
1259
-     * @return void
1260
-     */
1261
-    public function enqueue_styles()
1262
-    {
1263
-
1264
-
1265
-        wp_register_style($this->taxonomy . '-frontend', esc_url($this->assets_url) . 'css/modules-frontend.css', Sensei()->version );
1266
-        wp_enqueue_style($this->taxonomy . '-frontend');
1267
-    }
1268
-
1269
-    /**
1270
-     * Load admin Javascript
1271
-     *
1272
-     * @since 1.8.0
1273
-     *
1274
-     * @return void
1275
-     */
1276
-    public function admin_enqueue_scripts( $hook ) {
1277
-
1278
-        /**
1279
-         * Filter the page hooks where modules admin script can be loaded on.
1280
-         *
1281
-         * @param array $white_listed_pages
1282
-         */
1283
-        $script_on_pages_white_list = apply_filters( 'sensei_module_admin_script_page_white_lists', array(
1284
-            'edit-tags.php',
1285
-            'course_page_module-order',
1286
-            'post-new.php',
1287
-            'post.php'
1288
-        ) );
1289
-
1290
-        if ( ! in_array( $hook, $script_on_pages_white_list ) ) {
1291
-            return;
1292
-        }
1293
-
1294
-        $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
1295
-
1296
-        wp_enqueue_script( 'sensei-chosen', Sensei()->plugin_url . 'assets/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), Sensei()->version , true);
1297
-        wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery' . $suffix . '.js', array( 'jquery', 'sensei-chosen' ), Sensei()->version , true );
1298
-        wp_enqueue_script( $this->taxonomy . '-admin', esc_url( $this->assets_url ) . 'js/modules-admin' . $suffix . '.js', array( 'jquery', 'sensei-chosen', 'sensei-chosen-ajax', 'jquery-ui-sortable', 'select2' ), Sensei()->version, true );
1299
-
1300
-        // localized module data
1301
-        $localize_modulesAdmin = array(
1302
-            'search_courses_nonce' => wp_create_nonce( 'search-courses' ),
1303
-            'selectPlaceholder'    => __( 'Search for courses', 'woothemes-sensei' )
1304
-        );
1305
-
1306
-        wp_localize_script( $this->taxonomy . '-admin' ,'modulesAdmin', $localize_modulesAdmin );
1307
-    }
1308
-
1309
-    /**
1310
-     * Load admin CSS
1311
-     *
1312
-     * @since 1.8.0
1313
-     *
1314
-     * @return void
1315
-     */
1316
-    public function admin_enqueue_styles() {
1317
-
1318
-
1319
-        wp_register_style($this->taxonomy . '-sortable', esc_url($this->assets_url) . 'css/modules-admin.css','',Sensei()->version );
1320
-        wp_enqueue_style($this->taxonomy . '-sortable');
1321
-
1322
-    }
1323
-
1324
-    /**
1325
-     * Show the title modules on the single course template.
1326
-     *
1327
-     * Function is hooked into sensei_single_course_modules_before.
1328
-     *
1329
-     * @since 1.8.0
1330
-     * @return void
1331
-     */
1332
-    public function course_modules_title( ) {
1333
-
1334
-       if( sensei_module_has_lessons() ){
1335
-
1336
-            echo '<header><h2>' . __('Modules', 'woothemes-sensei') . '</h2></header>';
1337
-
1338
-        }
1339
-
1340
-    }
1341
-
1342
-    /**
1343
-     * Display the single course modules content this will only show
1344
-     * if the course has modules.
1345
-     *
1346
-     * @since 1.8.0
1347
-     * @return void
1348
-     */
1349
-    public function load_course_module_content_template(){
1350
-
1351
-        // load backwards compatible template name if it exists in the users theme
1352
-        $located_template= locate_template( Sensei()->template_url . 'single-course/course-modules.php' );
1353
-        if( $located_template ){
1354
-
1355
-            Sensei_Templates::get_template( 'single-course/course-modules.php' );
1356
-            return;
1357
-
1358
-        }
1359
-
1360
-        Sensei_Templates::get_template( 'single-course/modules.php' );
1361
-
1362
-    } // end course_module_content
1363
-
1364
-    /**
1365
-     * Returns all lessons for the given module ID
1366
-     *
1367
-     * @since 1.8.0
1368
-     *
1369
-     * @param $course_id
1370
-     * @param $term_id
1371
-     * @return array $lessons
1372
-     */
1373
-    public function get_lessons( $course_id , $term_id ){
1374
-
1375
-        $lesson_query = $this->get_lessons_query( $course_id, $term_id );
840
+		$html = '';
841
+
842
+		if (isset($_POST['module-order']) && 0 < strlen($_POST['module-order'])) {
843
+			$ordered = $this->save_course_module_order(esc_attr($_POST['module-order']), esc_attr($_POST['course_id']));
844
+
845
+			if ($ordered) {
846
+				$html .= '<div class="updated fade">' . "\n";
847
+				$html .= '<p>' . __('The module order has been saved for this course.', 'woothemes-sensei') . '</p>' . "\n";
848
+				$html .= '</div>' . "\n";
849
+			}
850
+		}
851
+
852
+		$courses = Sensei()->course->get_all_courses();
853
+
854
+		$html .= '<form action="' . admin_url('edit.php') . '" method="get">' . "\n";
855
+		$html .= '<input type="hidden" name="post_type" value="course" />' . "\n";
856
+		$html .= '<input type="hidden" name="page" value="' . esc_attr($this->order_page_slug) . '" />' . "\n";
857
+		$html .= '<select id="module-order-course" name="course_id">' . "\n";
858
+		$html .= '<option value="">' . __('Select a course', 'woothemes-sensei') . '</option>' . "\n";
859
+
860
+		foreach ($courses as $course) {
861
+			if (has_term('', $this->taxonomy, $course->ID)) {
862
+				$course_id = '';
863
+				if (isset($_GET['course_id'])) {
864
+					$course_id = intval($_GET['course_id']);
865
+				}
866
+				$html .= '<option value="' . esc_attr(intval($course->ID)) . '" ' . selected($course->ID, $course_id, false) . '>' . get_the_title($course->ID) . '</option>' . "\n";
867
+			}
868
+		}
869
+
870
+		$html .= '</select>' . "\n";
871
+		$html .= '<input type="submit" class="button-primary module-order-select-course-submit" value="' . __('Select', 'woothemes-sensei') . '" />' . "\n";
872
+		$html .= '</form>' . "\n";
873
+
874
+		if (isset($_GET['course_id'])) {
875
+			$course_id = intval($_GET['course_id']);
876
+			if ($course_id > 0) {
877
+				$modules = $this->get_course_modules($course_id);
878
+				$modules = $this->append_teacher_name_to_module( $modules, array( 'module' ), array() );
879
+				if ($modules) {
880
+
881
+					$order = $this->get_course_module_order($course_id);
882
+
883
+					$order_string='';
884
+					if ($order) {
885
+						$order_string = implode(',', $order);
886
+					}
887
+
888
+					$html .= '<form id="editgrouping" method="post" action="" class="validate">' . "\n";
889
+					$html .= '<ul class="sortable-module-list">' . "\n";
890
+					$count = 0;
891
+					foreach ($modules as $module) {
892
+						$count++;
893
+						$class = $this->taxonomy;
894
+						if ($count == 1) {
895
+							$class .= ' first';
896
+						}
897
+						if ($count == count($module)) {
898
+							$class .= ' last';
899
+						}
900
+						if ($count % 2 != 0) {
901
+							$class .= ' alternate';
902
+						}
903
+						$html .= '<li class="' . esc_attr($class) . '"><span rel="' . esc_attr($module->term_id) . '" style="width: 100%;"> ' . $module->name . '</span></li>' . "\n";
904
+					}
905
+					$html .= '</ul>' . "\n";
906
+
907
+					$html .= '<input type="hidden" name="module-order" value="' . $order_string . '" />' . "\n";
908
+					$html .= '<input type="hidden" name="course_id" value="' . $course_id . '" />' . "\n";
909
+					$html .= '<input type="submit" class="button-primary" value="' . __('Save module order', 'woothemes-sensei') . '" />' . "\n";
910
+					$html .= '<a href="' . admin_url('post.php?post=' . $course_id . '&action=edit') . '" class="button-secondary">' . __('Edit course', 'woothemes-sensei') . '</a>' . "\n";
911
+				}
912
+			}
913
+		}
914
+
915
+		echo $html;
916
+
917
+		?></div><?php
918
+	}
919
+
920
+	/**
921
+	 * Add 'Module order' column to courses list table
922
+	 *
923
+	 * @since 1.8.0
924
+	 *
925
+	 * @param  array $columns Existing columns
926
+	 * @return array           Modifed columns
927
+	 */
928
+	public function course_columns($columns = array())
929
+	{
930
+		$columns['module_order'] = __('Module order', 'woothemes-sensei');
931
+		return $columns;
932
+	}
933
+
934
+	/**
935
+	 * Load content in 'Module order' column
936
+	 *
937
+	 * @since 1.8.0
938
+	 *
939
+	 * @param  string $column Current column name
940
+	 * @param  integer $course_id ID of course
941
+	 * @return void
942
+	 */
943
+	public function course_column_content($column = '', $course_id = 0)
944
+	{
945
+		if ($column == 'module_order') {
946
+			if (has_term('', $this->taxonomy, $course_id)) {
947
+				echo '<a class="button-secondary" href="' . admin_url('edit.php?post_type=course&page=module-order&course_id=' . urlencode(intval($course_id))) . '">' . __('Order modules', 'woothemes-sensei') . '</a>';
948
+			}
949
+		}
950
+	}
951
+
952
+	/**
953
+	 * Save module order for course
954
+	 *
955
+	 * @since 1.8.0
956
+	 *
957
+	 * @param  string $order_string Comma-separated string of module IDs
958
+	 * @param  integer $course_id ID of course
959
+	 * @return boolean                 True on success, false on failure
960
+	 */
961
+	private function save_course_module_order($order_string = '', $course_id = 0)
962
+	{
963
+		if ($order_string && $course_id) {
964
+			$order = explode(',', $order_string);
965
+			update_post_meta(intval($course_id), '_module_order', $order);
966
+			return true;
967
+		}
968
+		return false;
969
+	}
970
+
971
+	/**
972
+	 * Get module order for course
973
+	 *
974
+	 * @since 1.8.0
975
+	 *
976
+	 * @param  integer $course_id ID of course
977
+	 * @return mixed              Module order on success, false if no module order has been saved
978
+	 */
979
+	public function get_course_module_order($course_id = 0)
980
+	{
981
+		if ($course_id) {
982
+			$order = get_post_meta(intval($course_id), '_module_order', true);
983
+			return $order;
984
+		}
985
+		return false;
986
+	}
987
+
988
+	/**
989
+	 * Modify module taxonomy columns
990
+	 *
991
+	 * @since 1.8.0
992
+	 *
993
+	 * @param  array $columns Default columns
994
+	 * @return array          Modified columns
995
+	 */
996
+	public function taxonomy_column_headings($columns)
997
+	{
998
+
999
+		unset($columns['posts']);
1000
+
1001
+		$columns['lessons'] = __('Lessons', 'woothemes-sensei');
1002
+
1003
+		return $columns;
1004
+	}
1005
+
1006
+	/**
1007
+	 * Manage content in custom module taxonomy columns
1008
+	 *
1009
+	 * @since 1.8.0
1010
+	 *
1011
+	 * @param  string $column_data Default data for column
1012
+	 * @param  string $column_name Name of current column
1013
+	 * @param  integer $term_id ID of current term
1014
+	 * @return string               Modified column data
1015
+	 */
1016
+	public function taxonomy_column_content($column_data, $column_name, $term_id)
1017
+	{
1018
+
1019
+		$args = array(
1020
+			'post_status' => 'publish',
1021
+			'posts_per_page' => -1,
1022
+			'tax_query' => array(
1023
+				array(
1024
+					'taxonomy' => $this->taxonomy,
1025
+					'field' => 'id',
1026
+					'terms' => intval($term_id)
1027
+				)
1028
+			)
1029
+		);
1030
+
1031
+		$module = get_term($term_id, $this->taxonomy);
1032
+
1033
+		switch ($column_name) {
1034
+
1035
+			case 'lessons':
1036
+				$args['post_type'] = 'lesson';
1037
+				$lessons = get_posts($args);
1038
+				$total_lessons = count($lessons);
1039
+				$column_data = '<a href="' . admin_url('edit.php?module=' . urlencode($module->slug) . '&post_type=lesson') . '">' . intval($total_lessons) . '</a>';
1040
+				break;
1041
+		}
1042
+
1043
+		return $column_data;
1044
+	}
1045
+
1046
+	/**
1047
+	 * Add 'Module' columns to Analysis Lesson Overview table
1048
+	 *
1049
+	 * @since 1.8.0
1050
+	 *
1051
+	 * @param  array $columns Default columns
1052
+	 * @return array          Modified columns
1053
+	 */
1054
+	public function analysis_overview_column_title($columns)
1055
+	{
1056
+
1057
+		if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) {
1058
+			$new_columns = array();
1059
+			if (is_array($columns) && 0 < count($columns)) {
1060
+				foreach ($columns as $column => $title) {
1061
+					$new_columns[$column] = $title;
1062
+					if ($column == 'title') {
1063
+						$new_columns['lesson_module'] = __('Module', 'woothemes-sensei');
1064
+					}
1065
+				}
1066
+			}
1067
+
1068
+			if (0 < count($new_columns)) {
1069
+				return $new_columns;
1070
+			}
1071
+		}
1072
+
1073
+		return $columns;
1074
+	}
1075
+
1076
+	/**
1077
+	 * Data for 'Module' column Analysis Lesson Overview table
1078
+	 *
1079
+	 * @since 1.8.0
1080
+	 *
1081
+	 * @param  array $columns Table column data
1082
+	 * @param  WP_Post $lesson
1083
+	 * @return array              Updated column data
1084
+	 */
1085
+	public function analysis_overview_column_data($columns, $lesson )
1086
+	{
1087
+
1088
+		if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) {
1089
+			$lesson_module = '';
1090
+			$lesson_module_list = wp_get_post_terms($lesson->ID, $this->taxonomy);
1091
+			if (is_array($lesson_module_list) && count($lesson_module_list) > 0) {
1092
+				foreach ($lesson_module_list as $single_module) {
1093
+					$lesson_module = '<a href="' . esc_url(admin_url('edit-tags.php?action=edit&taxonomy=' . urlencode($this->taxonomy) . '&tag_ID=' . urlencode($single_module->term_id))) . '">' . $single_module->name . '</a>';
1094
+					break;
1095
+				}
1096
+			}
1097
+
1098
+			$columns['lesson_module'] = $lesson_module;
1099
+		}
1100
+
1101
+		return $columns;
1102
+	}
1103
+
1104
+	/**
1105
+	 * Add 'Module' columns to Analysis Course table
1106
+	 *
1107
+	 * @since 1.8.0
1108
+	 *
1109
+	 * @param  array $columns Default columns
1110
+	 * @return array          Modified columns
1111
+	 */
1112
+	public function analysis_course_column_title($columns)
1113
+	{
1114
+		if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) {
1115
+			$columns['lesson_module'] = __('Module', 'woothemes-sensei');
1116
+		}
1117
+		return $columns;
1118
+	}
1119
+
1120
+	/**
1121
+	 * Data for 'Module' column in Analysis Course table
1122
+	 *
1123
+	 * @since 1.8.0
1124
+	 *
1125
+	 * @param  array $columns Table column data
1126
+	 * @param  WP_Post $lesson
1127
+	 * @return array              Updated columns data
1128
+	 */
1129
+	public function analysis_course_column_data($columns, $lesson )
1130
+	{
1131
+
1132
+		if ( isset( $_GET['course_id'] ) ) {
1133
+			$lesson_module = '';
1134
+			$lesson_module_list = wp_get_post_terms($lesson->ID, $this->taxonomy);
1135
+			if (is_array($lesson_module_list) && count($lesson_module_list) > 0) {
1136
+				foreach ($lesson_module_list as $single_module) {
1137
+					$lesson_module = '<a href="' . esc_url(admin_url('edit-tags.php?action=edit&taxonomy=' . urlencode($this->taxonomy) . '&tag_ID=' . urlencode($single_module->term_id))) . '">' . $single_module->name . '</a>';
1138
+					break;
1139
+				}
1140
+			}
1141
+
1142
+			$columns['lesson_module'] = $lesson_module;
1143
+		}
1144
+
1145
+		return $columns;
1146
+	}
1147
+
1148
+	/**
1149
+	 * Get module for lesson
1150
+	 *
1151
+	 * This function also checks if the module still
1152
+	 * exists on the course before returning it. Although
1153
+	 * the lesson has a module the same module must exist on the
1154
+	 * course for it to be valid.
1155
+	 *
1156
+	 * @since 1.8.0
1157
+	 *
1158
+	 * @param  integer $lesson_id ID of lesson
1159
+	 * @return object             Module taxonomy term object
1160
+	 */
1161
+	public function get_lesson_module($lesson_id = 0)
1162
+	{
1163
+		$lesson_id = intval($lesson_id);
1164
+		if ( ! ( intval( $lesson_id > 0) ) ) {
1165
+			return false;
1166
+		}
1167
+
1168
+		// get taxonomy terms on this lesson
1169
+		$modules = wp_get_post_terms($lesson_id, $this->taxonomy);
1170
+
1171
+		//check if error returned
1172
+		if( empty( $modules ) || isset( $modules['errors']  ) ){
1173
+			return false;
1174
+		}
1175
+
1176
+	   // get the last item in the array there should be only be 1 really.
1177
+	   // this method works for all php versions.
1178
+	   foreach( $modules as $module ){
1179
+		   break;
1180
+	   }
1181
+
1182
+		if ( ! isset($module) || ! is_object($module) || is_wp_error($module)) {
1183
+			return false;
1184
+		}
1185
+
1186
+		$module->url = get_term_link($module, $this->taxonomy);
1187
+		$course_id = intval(get_post_meta(intval($lesson_id), '_lesson_course', true));
1188
+		if (isset($course_id) && 0 < $course_id) {
1189
+
1190
+			// the course should contain the same module taxonomy term for this to be valid
1191
+			if( ! has_term( $module, $this->taxonomy, $course_id)){
1192
+				return false;
1193
+			}
1194
+
1195
+			$module->url = esc_url(add_query_arg('course_id', intval($course_id), $module->url));
1196
+		}
1197
+		return $module;
1198
+
1199
+	}
1200
+
1201
+	/**
1202
+	 * Get ordered array of all modules in course
1203
+	 *
1204
+	 * @since 1.8.0
1205
+	 *
1206
+	 * @param  integer $course_id ID of course
1207
+	 * @return array              Ordered array of module taxonomy term objects
1208
+	 */
1209
+	public function get_course_modules($course_id = 0)
1210
+	{
1211
+		$course_id = intval($course_id);
1212
+		if (0 < $course_id) {
1213
+
1214
+			// Get modules for course
1215
+			$modules = wp_get_post_terms($course_id, $this->taxonomy);
1216
+
1217
+			// Get custom module order for course
1218
+			$order = $this->get_course_module_order($course_id);
1219
+
1220
+			// Sort by custom order if custom order exists
1221
+			if ($order) {
1222
+				$ordered_modules = array();
1223
+				$unordered_modules = array();
1224
+				foreach ($modules as $module) {
1225
+					$order_key = array_search($module->term_id, $order);
1226
+					if ($order_key !== false) {
1227
+						$ordered_modules[$order_key] = $module;
1228
+					} else {
1229
+						$unordered_modules[] = $module;
1230
+					}
1231
+				}
1232
+
1233
+				// Order modules correctly
1234
+				ksort($ordered_modules);
1235
+
1236
+				// Append modules that have not yet been ordered
1237
+				if (count($unordered_modules) > 0) {
1238
+					$ordered_modules = array_merge($ordered_modules, $unordered_modules);
1239
+				}
1240
+
1241
+			} else {
1242
+
1243
+				$ordered_modules = $modules;
1244
+
1245
+			}
1246
+
1247
+			return $ordered_modules;
1248
+
1249
+		}
1250
+
1251
+		return false;
1252
+	}
1253
+
1254
+	/**
1255
+	 * Load frontend CSS
1256
+	 *
1257
+	 * @since 1.8.0
1258
+	 *
1259
+	 * @return void
1260
+	 */
1261
+	public function enqueue_styles()
1262
+	{
1263
+
1264
+
1265
+		wp_register_style($this->taxonomy . '-frontend', esc_url($this->assets_url) . 'css/modules-frontend.css', Sensei()->version );
1266
+		wp_enqueue_style($this->taxonomy . '-frontend');
1267
+	}
1268
+
1269
+	/**
1270
+	 * Load admin Javascript
1271
+	 *
1272
+	 * @since 1.8.0
1273
+	 *
1274
+	 * @return void
1275
+	 */
1276
+	public function admin_enqueue_scripts( $hook ) {
1277
+
1278
+		/**
1279
+		 * Filter the page hooks where modules admin script can be loaded on.
1280
+		 *
1281
+		 * @param array $white_listed_pages
1282
+		 */
1283
+		$script_on_pages_white_list = apply_filters( 'sensei_module_admin_script_page_white_lists', array(
1284
+			'edit-tags.php',
1285
+			'course_page_module-order',
1286
+			'post-new.php',
1287
+			'post.php'
1288
+		) );
1289
+
1290
+		if ( ! in_array( $hook, $script_on_pages_white_list ) ) {
1291
+			return;
1292
+		}
1293
+
1294
+		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
1295
+
1296
+		wp_enqueue_script( 'sensei-chosen', Sensei()->plugin_url . 'assets/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), Sensei()->version , true);
1297
+		wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery' . $suffix . '.js', array( 'jquery', 'sensei-chosen' ), Sensei()->version , true );
1298
+		wp_enqueue_script( $this->taxonomy . '-admin', esc_url( $this->assets_url ) . 'js/modules-admin' . $suffix . '.js', array( 'jquery', 'sensei-chosen', 'sensei-chosen-ajax', 'jquery-ui-sortable', 'select2' ), Sensei()->version, true );
1299
+
1300
+		// localized module data
1301
+		$localize_modulesAdmin = array(
1302
+			'search_courses_nonce' => wp_create_nonce( 'search-courses' ),
1303
+			'selectPlaceholder'    => __( 'Search for courses', 'woothemes-sensei' )
1304
+		);
1305
+
1306
+		wp_localize_script( $this->taxonomy . '-admin' ,'modulesAdmin', $localize_modulesAdmin );
1307
+	}
1308
+
1309
+	/**
1310
+	 * Load admin CSS
1311
+	 *
1312
+	 * @since 1.8.0
1313
+	 *
1314
+	 * @return void
1315
+	 */
1316
+	public function admin_enqueue_styles() {
1317
+
1318
+
1319
+		wp_register_style($this->taxonomy . '-sortable', esc_url($this->assets_url) . 'css/modules-admin.css','',Sensei()->version );
1320
+		wp_enqueue_style($this->taxonomy . '-sortable');
1321
+
1322
+	}
1323
+
1324
+	/**
1325
+	 * Show the title modules on the single course template.
1326
+	 *
1327
+	 * Function is hooked into sensei_single_course_modules_before.
1328
+	 *
1329
+	 * @since 1.8.0
1330
+	 * @return void
1331
+	 */
1332
+	public function course_modules_title( ) {
1333
+
1334
+	   if( sensei_module_has_lessons() ){
1335
+
1336
+			echo '<header><h2>' . __('Modules', 'woothemes-sensei') . '</h2></header>';
1337
+
1338
+		}
1339
+
1340
+	}
1341
+
1342
+	/**
1343
+	 * Display the single course modules content this will only show
1344
+	 * if the course has modules.
1345
+	 *
1346
+	 * @since 1.8.0
1347
+	 * @return void
1348
+	 */
1349
+	public function load_course_module_content_template(){
1350
+
1351
+		// load backwards compatible template name if it exists in the users theme
1352
+		$located_template= locate_template( Sensei()->template_url . 'single-course/course-modules.php' );
1353
+		if( $located_template ){
1354
+
1355
+			Sensei_Templates::get_template( 'single-course/course-modules.php' );
1356
+			return;
1357
+
1358
+		}
1359
+
1360
+		Sensei_Templates::get_template( 'single-course/modules.php' );
1361
+
1362
+	} // end course_module_content
1363
+
1364
+	/**
1365
+	 * Returns all lessons for the given module ID
1366
+	 *
1367
+	 * @since 1.8.0
1368
+	 *
1369
+	 * @param $course_id
1370
+	 * @param $term_id
1371
+	 * @return array $lessons
1372
+	 */
1373
+	public function get_lessons( $course_id , $term_id ){
1374
+
1375
+		$lesson_query = $this->get_lessons_query( $course_id, $term_id );
1376 1376
 
1377
-        if( isset( $lesson_query->posts ) ){
1377
+		if( isset( $lesson_query->posts ) ){
1378 1378
 
1379
-            return $lesson_query->posts;
1379
+			return $lesson_query->posts;
1380 1380
 
1381
-        }else{
1381
+		}else{
1382 1382
 
1383
-            return array();
1383
+			return array();
1384 1384
 
1385
-        }
1385
+		}
1386 1386
 
1387
-    } // end get lessons
1387
+	} // end get lessons
1388 1388
 
1389
-    /**
1390
-     * Returns all lessons for the given module ID
1391
-     *
1392
-     * @since 1.8.0
1393
-     *
1394
-     * @param $course_id
1395
-     * @param $term_id
1396
-     * @return WP_Query $lessons_query
1397
-     */
1398
-    public function get_lessons_query( $course_id , $term_id ){
1399
-
1400
-        if( empty( $term_id ) || empty( $course_id ) ){
1401
-
1402
-            return array();
1403
-
1404
-        }
1405
-
1406
-        $args = array(
1407
-            'post_type' => 'lesson',
1408
-            'post_status' => 'publish',
1409
-            'posts_per_page' => -1,
1410
-            'meta_query' => array(
1411
-                array(
1412
-                    'key' => '_lesson_course',
1413
-                    'value' => intval($course_id),
1414
-                    'compare' => '='
1415
-                )
1416
-            ),
1417
-            'tax_query' => array(
1418
-                array(
1419
-                    'taxonomy' => 'module',
1420
-                    'field' => 'id',
1421
-                    'terms' => intval( $term_id )
1422
-                )
1423
-            ),
1424
-            'orderby' => 'menu_order',
1425
-            'order' => 'ASC',
1426
-            'suppress_filters' => 0
1427
-        );
1428
-
1429
-        if (version_compare( Sensei()->version, '1.6.0', '>=')) {
1430
-            $args['meta_key'] = '_order_module_' . intval( $term_id );
1431
-            $args['orderby'] = 'meta_value_num date';
1432
-        }
1433
-
1434
-        $lessons_query = new WP_Query( $args );
1435
-
1436
-        return $lessons_query;
1437
-
1438
-    } // end get lessons
1439
-
1440
-    /**
1441
-     * Find the lesson in the given course that doesn't belong
1442
-     * to any of the courses modules
1443
-     *
1444
-     *
1445
-     * @param $course_id
1446
-     *
1447
-     * @return array $non_module_lessons
1448
-     */
1449
-    public function get_none_module_lessons( $course_id ){
1450
-
1451
-        $non_module_lessons = array();
1452
-
1453
-        //exit if there is no course id passed in
1454
-        if( empty( $course_id ) || 'course' != get_post_type( $course_id ) ) {
1455
-
1456
-            return $non_module_lessons;
1457
-        }
1458
-
1459
-        //save some time and check if we already have the saved
1460
-        if( get_transient( 'sensei_'. $course_id .'_none_module_lessons') ){
1461
-
1462
-            return get_transient( 'sensei_'. $course_id .'_none_module_lessons');
1463
-
1464
-        }
1465
-
1466
-        // create terms array which must be excluded from other arrays
1467
-        $course_modules = $this->get_course_modules( $course_id );
1468
-
1469
-        //exit if there are no module on this course
1470
-        if( empty( $course_modules ) || ! is_array( $course_modules ) ){
1471
-
1472
-            return  Sensei()->course->course_lessons( $course_id );
1473
-
1474
-        }
1475
-
1476
-        $terms = array();
1477
-        foreach( $course_modules as $module ){
1478
-
1479
-            array_push( $terms ,  $module->term_id );
1480
-
1481
-        }
1482
-
1483
-        $args = array(
1484
-            'post_type' => 'lesson',
1485
-            'post_status' => 'publish',
1486
-            'posts_per_page' => -1,
1487
-            'meta_query' => array(
1488
-                array(
1489
-                    'key' => '_lesson_course',
1490
-                    'value' => intval( $course_id ),
1491
-                    'compare' => '='
1492
-                )
1493
-            ),
1494
-            'tax_query' => array(
1495
-                array(
1496
-                    'taxonomy' => 'module',
1497
-                    'field' => 'id',
1498
-                    'terms' =>  $terms,
1499
-                    'operator' => 'NOT IN'
1500
-                )
1501
-            ),
1502
-            'orderby' => 'menu_order',
1503
-            'order' => 'ASC',
1504
-            'suppress_filters' => 0
1505
-        );
1506
-
1507
-        $wp_lessons_query = new WP_Query( $args );
1508
-
1509
-        if( isset( $wp_lessons_query->posts) && count( $wp_lessons_query->posts ) > 0  ){
1510
-            $non_module_lessons = $wp_lessons_query->get_posts();
1511
-            set_transient( 'sensei_'. $course_id .'_none_module_lessons', $non_module_lessons, 10 * DAY_IN_SECONDS );
1512
-        }
1513
-
1514
-        return $non_module_lessons;
1515
-    } // end get_none_module_lessons
1516
-
1517
-    /**
1518
-     * Register the modules taxonomy
1519
-     *
1520
-     * @since 1.8.0
1521
-     */
1522
-    public function setup_modules_taxonomy(){
1523
-
1524
-        $labels = array(
1525
-            'name' => __('Modules', 'woothemes-sensei'),
1526
-            'singular_name' => __('Module', 'woothemes-sensei'),
1527
-            'search_items' => __('Search Modules', 'woothemes-sensei'),
1528
-            'all_items' => __('All Modules', 'woothemes-sensei'),
1529
-            'parent_item' => __('Parent Module', 'woothemes-sensei'),
1530
-            'parent_item_colon' => __('Parent Module:', 'woothemes-sensei'),
1531
-            'edit_item' => __('Edit Module', 'woothemes-sensei'),
1532
-            'update_item' => __('Update Module', 'woothemes-sensei'),
1533
-            'add_new_item' => __('Add New Module', 'woothemes-sensei'),
1534
-            'new_item_name' => __('New Module Name', 'woothemes-sensei'),
1535
-            'menu_name' => __('Modules', 'woothemes-sensei'),
1536
-        );
1537
-
1538
-        /**
1539
-         * Filter to alter the Sensei Modules rewrite slug
1540
-         *
1541
-         * @since 1.8.0
1542
-         * @param string default 'modules'
1543
-         */
1544
-        $modules_rewrite_slug = apply_filters('sensei_module_slug', 'modules');
1545
-
1546
-        $args = array(
1547
-            'public' => true,
1548
-            'hierarchical' => true,
1549
-            'show_admin_column' => true,
1550
-            'capabilities' => array(
1551
-                'manage_terms' => 'manage_categories',
1552
-                'edit_terms'   => 'edit_courses',
1553
-                'delete_terms' => 'manage_categories',
1554
-                'assign_terms' => 'edit_courses'
1555
-            ),
1556
-            'show_in_nav_menus' => false,
1557
-            'show_in_quick_edit' => false,
1558
-            'show_ui' => true,
1559
-            'rewrite' => array('slug' => $modules_rewrite_slug ),
1560
-            'labels' => $labels
1561
-        );
1562
-
1563
-        register_taxonomy( 'module' , array('course', 'lesson'), $args);
1564
-
1565
-    }// end setup_modules_taxonomy
1566
-
1567
-    /**
1568
-     * When the wants to edit the lesson modules redirect them to the course modules.
1569
-     *
1570
-     * This function is hooked into the admin_menu
1571
-     *
1572
-     * @since 1.8.0
1573
-     * @return void
1574
-     */
1575
-    function redirect_to_lesson_module_taxonomy_to_course( ){
1576
-
1577
-        global $typenow , $taxnow;
1578
-
1579
-        if( 'lesson'== $typenow && 'module'==$taxnow ){
1580
-            wp_safe_redirect( esc_url_raw( 'edit-tags.php?taxonomy=module&post_type=course'  ) );
1581
-        }
1582
-
1583
-    }// end redirect to course taxonomy
1584
-
1585
-    /**
1586
-     * Completely remove the module menu item under lessons.
1587
-     *
1588
-     * This function is hooked into the admin_menu
1589
-     *
1590
-     * @since 1.8.0
1591
-     * @return void
1592
-     */
1593
-    public function remove_lessons_menu_model_taxonomy(){
1594
-        global $submenu;
1595
-
1596
-        if( ! isset( $submenu['edit.php?post_type=lesson'] ) || !is_array( $submenu['edit.php?post_type=lesson'] ) ){
1597
-            return; // exit
1598
-        }
1599
-
1600
-        $lesson_main_menu = $submenu['edit.php?post_type=lesson'];
1601
-        foreach( $lesson_main_menu as $index => $sub_item ){
1602
-
1603
-            if( 'edit-tags.php?taxonomy=module&amp;post_type=lesson' == $sub_item[2] ){
1604
-                unset( $submenu['edit.php?post_type=lesson'][ $index ]);
1605
-            }
1606
-        }
1607
-
1608
-    }// end remove lesson module tax
1609
-
1610
-    /**
1611
-     * Completely remove the second modules under courses
1612
-     *
1613
-     * This function is hooked into the admin_menu
1614
-     *
1615
-     * @since 1.8.0
1616
-     * @return void
1617
-     */
1618
-    public function remove_courses_menu_model_taxonomy(){
1619
-        global $submenu;
1620
-
1621
-        if( ! isset( $submenu['edit.php?post_type=course'] ) || !is_array( $submenu['edit.php?post_type=course'] ) ){
1622
-            return; // exit
1623
-        }
1624
-
1625
-        $course_main_menu = $submenu['edit.php?post_type=course'];
1626
-        foreach( $course_main_menu as $index => $sub_item ){
1627
-
1628
-            if( 'edit-tags.php?taxonomy=module&amp;post_type=course' == $sub_item[2] ){
1629
-                unset( $submenu['edit.php?post_type=course'][ $index ]);
1630
-            }
1631
-        }
1632
-
1633
-    }// end remove courses module tax
1634
-
1635
-    /**
1636
-     * Determine the author of a module term term by looking at
1637
-     * the prefixed author id. This function will query the full term object.
1638
-     * Will return the admin user author could not be determined.
1639
-     *
1640
-     * @since 1.8.0
1641
-     *
1642
-     * @param string $term_name
1643
-     * @return array $owners { type WP_User }. Empty array if none if found.
1644
-     */
1645
-    public static function get_term_authors( $term_name ){
1646
-
1647
-        $terms = get_terms( array( 'module') , array( 'name__like'=>$term_name, 'hide_empty' => false )  );
1648
-
1649
-        $owners = array();
1650
-        if( empty( $terms ) ){
1651
-
1652
-            return $owners;
1389
+	/**
1390
+	 * Returns all lessons for the given module ID
1391
+	 *
1392
+	 * @since 1.8.0
1393
+	 *
1394
+	 * @param $course_id
1395
+	 * @param $term_id
1396
+	 * @return WP_Query $lessons_query
1397
+	 */
1398
+	public function get_lessons_query( $course_id , $term_id ){
1399
+
1400
+		if( empty( $term_id ) || empty( $course_id ) ){
1401
+
1402
+			return array();
1403
+
1404
+		}
1405
+
1406
+		$args = array(
1407
+			'post_type' => 'lesson',
1408
+			'post_status' => 'publish',
1409
+			'posts_per_page' => -1,
1410
+			'meta_query' => array(
1411
+				array(
1412
+					'key' => '_lesson_course',
1413
+					'value' => intval($course_id),
1414
+					'compare' => '='
1415
+				)
1416
+			),
1417
+			'tax_query' => array(
1418
+				array(
1419
+					'taxonomy' => 'module',
1420
+					'field' => 'id',
1421
+					'terms' => intval( $term_id )
1422
+				)
1423
+			),
1424
+			'orderby' => 'menu_order',
1425
+			'order' => 'ASC',
1426
+			'suppress_filters' => 0
1427
+		);
1428
+
1429
+		if (version_compare( Sensei()->version, '1.6.0', '>=')) {
1430
+			$args['meta_key'] = '_order_module_' . intval( $term_id );
1431
+			$args['orderby'] = 'meta_value_num date';
1432
+		}
1433
+
1434
+		$lessons_query = new WP_Query( $args );
1435
+
1436
+		return $lessons_query;
1437
+
1438
+	} // end get lessons
1439
+
1440
+	/**
1441
+	 * Find the lesson in the given course that doesn't belong
1442
+	 * to any of the courses modules
1443
+	 *
1444
+	 *
1445
+	 * @param $course_id
1446
+	 *
1447
+	 * @return array $non_module_lessons
1448
+	 */
1449
+	public function get_none_module_lessons( $course_id ){
1450
+
1451
+		$non_module_lessons = array();
1452
+
1453
+		//exit if there is no course id passed in
1454
+		if( empty( $course_id ) || 'course' != get_post_type( $course_id ) ) {
1455
+
1456
+			return $non_module_lessons;
1457
+		}
1458
+
1459
+		//save some time and check if we already have the saved
1460
+		if( get_transient( 'sensei_'. $course_id .'_none_module_lessons') ){
1461
+
1462
+			return get_transient( 'sensei_'. $course_id .'_none_module_lessons');
1463
+
1464
+		}
1465
+
1466
+		// create terms array which must be excluded from other arrays
1467
+		$course_modules = $this->get_course_modules( $course_id );
1468
+
1469
+		//exit if there are no module on this course
1470
+		if( empty( $course_modules ) || ! is_array( $course_modules ) ){
1471
+
1472
+			return  Sensei()->course->course_lessons( $course_id );
1473
+
1474
+		}
1475
+
1476
+		$terms = array();
1477
+		foreach( $course_modules as $module ){
1478
+
1479
+			array_push( $terms ,  $module->term_id );
1480
+
1481
+		}
1482
+
1483
+		$args = array(
1484
+			'post_type' => 'lesson',
1485
+			'post_status' => 'publish',
1486
+			'posts_per_page' => -1,
1487
+			'meta_query' => array(
1488
+				array(
1489
+					'key' => '_lesson_course',
1490
+					'value' => intval( $course_id ),
1491
+					'compare' => '='
1492
+				)
1493
+			),
1494
+			'tax_query' => array(
1495
+				array(
1496
+					'taxonomy' => 'module',
1497
+					'field' => 'id',
1498
+					'terms' =>  $terms,
1499
+					'operator' => 'NOT IN'
1500
+				)
1501
+			),
1502
+			'orderby' => 'menu_order',
1503
+			'order' => 'ASC',
1504
+			'suppress_filters' => 0
1505
+		);
1506
+
1507
+		$wp_lessons_query = new WP_Query( $args );
1508
+
1509
+		if( isset( $wp_lessons_query->posts) && count( $wp_lessons_query->posts ) > 0  ){
1510
+			$non_module_lessons = $wp_lessons_query->get_posts();
1511
+			set_transient( 'sensei_'. $course_id .'_none_module_lessons', $non_module_lessons, 10 * DAY_IN_SECONDS );
1512
+		}
1513
+
1514
+		return $non_module_lessons;
1515
+	} // end get_none_module_lessons
1516
+
1517
+	/**
1518
+	 * Register the modules taxonomy
1519
+	 *
1520
+	 * @since 1.8.0
1521
+	 */
1522
+	public function setup_modules_taxonomy(){
1523
+
1524
+		$labels = array(
1525
+			'name' => __('Modules', 'woothemes-sensei'),
1526
+			'singular_name' => __('Module', 'woothemes-sensei'),
1527
+			'search_items' => __('Search Modules', 'woothemes-sensei'),
1528
+			'all_items' => __('All Modules', 'woothemes-sensei'),
1529
+			'parent_item' => __('Parent Module', 'woothemes-sensei'),
1530
+			'parent_item_colon' => __('Parent Module:', 'woothemes-sensei'),
1531
+			'edit_item' => __('Edit Module', 'woothemes-sensei'),
1532
+			'update_item' => __('Update Module', 'woothemes-sensei'),
1533
+			'add_new_item' => __('Add New Module', 'woothemes-sensei'),
1534
+			'new_item_name' => __('New Module Name', 'woothemes-sensei'),
1535
+			'menu_name' => __('Modules', 'woothemes-sensei'),
1536
+		);
1537
+
1538
+		/**
1539
+		 * Filter to alter the Sensei Modules rewrite slug
1540
+		 *
1541
+		 * @since 1.8.0
1542
+		 * @param string default 'modules'
1543
+		 */
1544
+		$modules_rewrite_slug = apply_filters('sensei_module_slug', 'modules');
1545
+
1546
+		$args = array(
1547
+			'public' => true,
1548
+			'hierarchical' => true,
1549
+			'show_admin_column' => true,
1550
+			'capabilities' => array(
1551
+				'manage_terms' => 'manage_categories',
1552
+				'edit_terms'   => 'edit_courses',
1553
+				'delete_terms' => 'manage_categories',
1554
+				'assign_terms' => 'edit_courses'
1555
+			),
1556
+			'show_in_nav_menus' => false,
1557
+			'show_in_quick_edit' => false,
1558
+			'show_ui' => true,
1559
+			'rewrite' => array('slug' => $modules_rewrite_slug ),
1560
+			'labels' => $labels
1561
+		);
1562
+
1563
+		register_taxonomy( 'module' , array('course', 'lesson'), $args);
1564
+
1565
+	}// end setup_modules_taxonomy
1566
+
1567
+	/**
1568
+	 * When the wants to edit the lesson modules redirect them to the course modules.
1569
+	 *
1570
+	 * This function is hooked into the admin_menu
1571
+	 *
1572
+	 * @since 1.8.0
1573
+	 * @return void
1574
+	 */
1575
+	function redirect_to_lesson_module_taxonomy_to_course( ){
1576
+
1577
+		global $typenow , $taxnow;
1578
+
1579
+		if( 'lesson'== $typenow && 'module'==$taxnow ){
1580
+			wp_safe_redirect( esc_url_raw( 'edit-tags.php?taxonomy=module&post_type=course'  ) );
1581
+		}
1582
+
1583
+	}// end redirect to course taxonomy
1584
+
1585
+	/**
1586
+	 * Completely remove the module menu item under lessons.
1587
+	 *
1588
+	 * This function is hooked into the admin_menu
1589
+	 *
1590
+	 * @since 1.8.0
1591
+	 * @return void
1592
+	 */
1593
+	public function remove_lessons_menu_model_taxonomy(){
1594
+		global $submenu;
1595
+
1596
+		if( ! isset( $submenu['edit.php?post_type=lesson'] ) || !is_array( $submenu['edit.php?post_type=lesson'] ) ){
1597
+			return; // exit
1598
+		}
1599
+
1600
+		$lesson_main_menu = $submenu['edit.php?post_type=lesson'];
1601
+		foreach( $lesson_main_menu as $index => $sub_item ){
1602
+
1603
+			if( 'edit-tags.php?taxonomy=module&amp;post_type=lesson' == $sub_item[2] ){
1604
+				unset( $submenu['edit.php?post_type=lesson'][ $index ]);
1605
+			}
1606
+		}
1607
+
1608
+	}// end remove lesson module tax
1609
+
1610
+	/**
1611
+	 * Completely remove the second modules under courses
1612
+	 *
1613
+	 * This function is hooked into the admin_menu
1614
+	 *
1615
+	 * @since 1.8.0
1616
+	 * @return void
1617
+	 */
1618
+	public function remove_courses_menu_model_taxonomy(){
1619
+		global $submenu;
1620
+
1621
+		if( ! isset( $submenu['edit.php?post_type=course'] ) || !is_array( $submenu['edit.php?post_type=course'] ) ){
1622
+			return; // exit
1623
+		}
1624
+
1625
+		$course_main_menu = $submenu['edit.php?post_type=course'];
1626
+		foreach( $course_main_menu as $index => $sub_item ){
1627
+
1628
+			if( 'edit-tags.php?taxonomy=module&amp;post_type=course' == $sub_item[2] ){
1629
+				unset( $submenu['edit.php?post_type=course'][ $index ]);
1630
+			}
1631
+		}
1632
+
1633
+	}// end remove courses module tax
1634
+
1635
+	/**
1636
+	 * Determine the author of a module term term by looking at
1637
+	 * the prefixed author id. This function will query the full term object.
1638
+	 * Will return the admin user author could not be determined.
1639
+	 *
1640
+	 * @since 1.8.0
1641
+	 *
1642
+	 * @param string $term_name
1643
+	 * @return array $owners { type WP_User }. Empty array if none if found.
1644
+	 */
1645
+	public static function get_term_authors( $term_name ){
1646
+
1647
+		$terms = get_terms( array( 'module') , array( 'name__like'=>$term_name, 'hide_empty' => false )  );
1648
+
1649
+		$owners = array();
1650
+		if( empty( $terms ) ){
1651
+
1652
+			return $owners;
1653 1653
 
1654
-        }
1654
+		}
1655 1655
 
1656
-        // setup the admin user
1656
+		// setup the admin user
1657 1657
 
1658 1658
 
1659
-        //if there are more handle them appropriately and get the ones we really need that matches the desired name exactly
1660
-        foreach( $terms as $term){
1661
-            if( $term->name == $term_name ){
1659
+		//if there are more handle them appropriately and get the ones we really need that matches the desired name exactly
1660
+		foreach( $terms as $term){
1661
+			if( $term->name == $term_name ){
1662 1662
 
1663
-                // look for the author in the slug
1664
-                $owners[] = Sensei_Core_Modules::get_term_author( $term->slug  );
1663
+				// look for the author in the slug
1664
+				$owners[] = Sensei_Core_Modules::get_term_author( $term->slug  );
1665 1665
 
1666
-            }// end if term name
1666
+			}// end if term name
1667 1667
 
1668
-        } // end for each
1668
+		} // end for each
1669 1669
 
1670
-        return $owners;
1670
+		return $owners;
1671 1671
 
1672
-    }// end get_term_author
1672
+	}// end get_term_author
1673 1673
 
1674
-    /**
1675
-     * Looks at a term slug and figures out
1676
-     * which author created the slug. The author was
1677
-     * appended when the user saved the module term in the course edit
1678
-     * screen.
1679
-     *
1680
-     * @since 1.8.0
1681
-     *
1682
-     * @param $slug
1683
-     * @return WP_User $author if no author is found or invalid term is passed the admin user will be returned.
1684
-     */
1685
-    public static function get_term_author( $slug='' ){
1674
+	/**
1675
+	 * Looks at a term slug and figures out
1676
+	 * which author created the slug. The author was
1677
+	 * appended when the user saved the module term in the course edit
1678
+	 * screen.
1679
+	 *
1680
+	 * @since 1.8.0
1681
+	 *
1682
+	 * @param $slug
1683
+	 * @return WP_User $author if no author is found or invalid term is passed the admin user will be returned.
1684
+	 */
1685
+	public static function get_term_author( $slug='' ){
1686 1686
 
1687
-        $term_owner = get_user_by( 'email', get_bloginfo( 'admin_email' ) );
1687
+		$term_owner = get_user_by( 'email', get_bloginfo( 'admin_email' ) );
1688 1688
 
1689
-        if( empty( $slug ) ){
1689
+		if( empty( $slug ) ){
1690 1690
 
1691
-            return $term_owner;
1691
+			return $term_owner;
1692 1692
 
1693
-        }
1693
+		}
1694 1694
 
1695
-        // look for the author in the slug
1696
-        $slug_parts = explode( '-', $slug );
1695
+		// look for the author in the slug
1696
+		$slug_parts = explode( '-', $slug );
1697 1697
 
1698
-        if( count( $slug_parts ) > 1 ){
1698
+		if( count( $slug_parts ) > 1 ){
1699 1699
 
1700
-            // get the user data
1701
-            $possible_user_id = $slug_parts[0];
1702
-            $author = get_userdata( $possible_user_id );
1700
+			// get the user data
1701
+			$possible_user_id = $slug_parts[0];
1702
+			$author = get_userdata( $possible_user_id );
1703 1703
 
1704
-            // if the user doesnt exist for the first part of the slug
1705
-            // then this slug was also created by admin
1706
-            if( is_a( $author, 'WP_User' ) ){
1704
+			// if the user doesnt exist for the first part of the slug
1705
+			// then this slug was also created by admin
1706
+			if( is_a( $author, 'WP_User' ) ){
1707 1707
 
1708
-                $term_owner =  $author;
1708
+				$term_owner =  $author;
1709 1709
 
1710
-            }
1711
-        }
1710
+			}
1711
+		}
1712 1712
 
1713
-        return $term_owner;
1714
-    }
1713
+		return $term_owner;
1714
+	}
1715 1715
 
1716
-    /**
1717
-     * Display the Sensei modules taxonomy terms metabox
1718
-     *
1719
-     * @since 1.8.0
1720
-     *
1721
-     * @hooked into add_meta_box
1722
-     *
1723
-     * @param WP_Post $post Post object.
1724
-     */
1725
-    public function course_module_metabox( $post ) {
1716
+	/**
1717
+	 * Display the Sensei modules taxonomy terms metabox
1718
+	 *
1719
+	 * @since 1.8.0
1720
+	 *
1721
+	 * @hooked into add_meta_box
1722
+	 *
1723
+	 * @param WP_Post $post Post object.
1724
+	 */
1725
+	public function course_module_metabox( $post ) {
1726 1726
 
1727
-        $tax_name = 'module';
1728
-        $taxonomy = get_taxonomy( 'module' );
1727
+		$tax_name = 'module';
1728
+		$taxonomy = get_taxonomy( 'module' );
1729 1729
 
1730
-        ?>
1730
+		?>
1731 1731
         <div id="taxonomy-<?php echo $tax_name; ?>" class="categorydiv">
1732 1732
             <ul id="<?php echo $tax_name; ?>-tabs" class="category-tabs">
1733 1733
                 <li class="tabs"><a href="#<?php echo $tax_name; ?>-all"><?php echo $taxonomy->labels->all_items; ?></a></li>
@@ -1742,9 +1742,9 @@  discard block
 block discarded – undo
1742 1742
 
1743 1743
             <div id="<?php echo $tax_name; ?>-all" class="tabs-panel">
1744 1744
                 <?php
1745
-                $name = ( $tax_name == 'category' ) ? 'post_category' : 'tax_input[' . $tax_name . ']';
1746
-                echo "<input type='hidden' name='{$name}[]' value='0' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks.
1747
-                ?>
1745
+				$name = ( $tax_name == 'category' ) ? 'post_category' : 'tax_input[' . $tax_name . ']';
1746
+				echo "<input type='hidden' name='{$name}[]' value='0' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks.
1747
+				?>
1748 1748
                 <ul id="<?php echo $tax_name; ?>checklist" data-wp-lists="list:<?php echo $tax_name; ?>" class="categorychecklist form-no-clear">
1749 1749
                     <?php wp_terms_checklist( $post->ID, array( 'taxonomy'=>$tax_name , 'popular_cats' => $popular_ids ) ); ?>
1750 1750
                 </ul>
@@ -1754,9 +1754,9 @@  discard block
 block discarded – undo
1754 1754
                     <h4>
1755 1755
                         <a id="sensei-<?php echo $tax_name; ?>-add-toggle" href="#<?php echo $tax_name; ?>-add" class="hide-if-no-js">
1756 1756
                             <?php
1757
-                            /* translators: %s: add new taxonomy label */
1758
-                            printf( __( '+ %s' ), $taxonomy->labels->add_new_item );
1759
-                            ?>
1757
+							/* translators: %s: add new taxonomy label */
1758
+							printf( __( '+ %s' ), $taxonomy->labels->add_new_item );
1759
+							?>
1760 1760
                         </a>
1761 1761
                     </h4>
1762 1762
                     <p id="sensei-<?php echo $tax_name; ?>-add" class="category-add wp-hidden-child">
@@ -1771,331 +1771,331 @@  discard block
 block discarded – undo
1771 1771
         </div>
1772 1772
     <?php
1773 1773
 
1774
-    } // end course_module_metabox
1774
+	} // end course_module_metabox
1775 1775
 
1776 1776
 
1777
-    /**
1778
-     * Submits a new module term prefixed with the
1779
-     * the current author id.
1780
-     *
1781
-     * @since 1.8.0
1782
-     */
1783
-    public static function add_new_module_term( ) {
1777
+	/**
1778
+	 * Submits a new module term prefixed with the
1779
+	 * the current author id.
1780
+	 *
1781
+	 * @since 1.8.0
1782
+	 */
1783
+	public static function add_new_module_term( ) {
1784 1784
 
1785 1785
 
1786
-        if( ! isset( $_POST[ 'security' ] ) || ! wp_verify_nonce( $_POST[ 'security' ], '_ajax_nonce-add-module'  ) ){
1787
-            wp_send_json_error( array('error'=> 'wrong security nonce') );
1788
-        }
1786
+		if( ! isset( $_POST[ 'security' ] ) || ! wp_verify_nonce( $_POST[ 'security' ], '_ajax_nonce-add-module'  ) ){
1787
+			wp_send_json_error( array('error'=> 'wrong security nonce') );
1788
+		}
1789 1789
 
1790
-        // get the term an create the new term storing infomration
1791
-        $term_name = sanitize_text_field( $_POST['newTerm'] );
1790
+		// get the term an create the new term storing infomration
1791
+		$term_name = sanitize_text_field( $_POST['newTerm'] );
1792 1792
 
1793
-        if( current_user_can('manage_options' ) ) {
1793
+		if( current_user_can('manage_options' ) ) {
1794 1794
 
1795
-            $term_slug = str_ireplace(' ', '-', trim( $term_name ) );
1795
+			$term_slug = str_ireplace(' ', '-', trim( $term_name ) );
1796 1796
 
1797
-        } else {
1797
+		} else {
1798 1798
 
1799
-            $term_slug =  get_current_user_id() . '-' . str_ireplace(' ', '-', trim( $term_name ) );
1799
+			$term_slug =  get_current_user_id() . '-' . str_ireplace(' ', '-', trim( $term_name ) );
1800 1800
 
1801
-        }
1801
+		}
1802 1802
 
1803
-        $course_id = sanitize_text_field( $_POST['course_id'] );
1803
+		$course_id = sanitize_text_field( $_POST['course_id'] );
1804 1804
 
1805
-        // save the term
1806
-        $slug = wp_insert_term( $term_name,'module', array('slug'=> $term_slug)  );
1805
+		// save the term
1806
+		$slug = wp_insert_term( $term_name,'module', array('slug'=> $term_slug)  );
1807 1807
 
1808
-        // send error for all errors except term exits
1809
-        if( is_wp_error( $slug ) ){
1808
+		// send error for all errors except term exits
1809
+		if( is_wp_error( $slug ) ){
1810 1810
 
1811
-            // prepare for possible term name and id to be passed down if term exists
1812
-            $term_data = array();
1811
+			// prepare for possible term name and id to be passed down if term exists
1812
+			$term_data = array();
1813 1813
 
1814
-            // if term exists also send back the term name and id
1815
-            if( isset( $slug->errors['term_exists'] ) ){
1814
+			// if term exists also send back the term name and id
1815
+			if( isset( $slug->errors['term_exists'] ) ){
1816 1816
 
1817
-                $term = get_term_by( 'slug', $term_slug, 'module');
1818
-                $term_data['name'] = $term_name;
1819
-                $term_data['id'] = $term->term_id;
1817
+				$term = get_term_by( 'slug', $term_slug, 'module');
1818
+				$term_data['name'] = $term_name;
1819
+				$term_data['id'] = $term->term_id;
1820 1820
 
1821
-                // set the object terms
1822
-                wp_set_object_terms( $course_id, $term->term_id, 'module', true );
1823
-            }
1821
+				// set the object terms
1822
+				wp_set_object_terms( $course_id, $term->term_id, 'module', true );
1823
+			}
1824 1824
 
1825
-            wp_send_json_error(array( 'errors'=>$slug->errors , 'term'=> $term_data ) );
1825
+			wp_send_json_error(array( 'errors'=>$slug->errors , 'term'=> $term_data ) );
1826 1826
 
1827
-        }
1827
+		}
1828 1828
 
1829
-        //make sure the new term is checked for this course
1829
+		//make sure the new term is checked for this course
1830 1830
 
1831
-        wp_set_object_terms( $course_id, $slug['term_id'], 'module', true );
1831
+		wp_set_object_terms( $course_id, $slug['term_id'], 'module', true );
1832 1832
 
1833
-        // Handle request then generate response using WP_Ajax_Response
1834
-        wp_send_json_success( array( 'termId' => $slug['term_id'], 'termName' => $term_name ) );
1833
+		// Handle request then generate response using WP_Ajax_Response
1834
+		wp_send_json_success( array( 'termId' => $slug['term_id'], 'termName' => $term_name ) );
1835 1835
 
1836
-    }
1836
+	}
1837 1837
 
1838
-    /**
1839
-     * Limit the course module metabox
1840
-     * term list to only those on courses belonging to current teacher.
1841
-     *
1842
-     * Hooked into 'get_terms'
1843
-     *
1844
-     * @since 1.8.0
1845
-     */
1846
-    public function filter_module_terms( $terms, $taxonomies, $args ){
1838
+	/**
1839
+	 * Limit the course module metabox
1840
+	 * term list to only those on courses belonging to current teacher.
1841
+	 *
1842
+	 * Hooked into 'get_terms'
1843
+	 *
1844
+	 * @since 1.8.0
1845
+	 */
1846
+	public function filter_module_terms( $terms, $taxonomies, $args ){
1847 1847
 
1848
-        //dont limit for admins and other taxonomies. This should also only apply to admin
1849
-        if( current_user_can( 'manage_options' ) || !in_array( 'module', $taxonomies ) || ! is_admin()  ){
1850
-            return $terms;
1851
-        }
1848
+		//dont limit for admins and other taxonomies. This should also only apply to admin
1849
+		if( current_user_can( 'manage_options' ) || !in_array( 'module', $taxonomies ) || ! is_admin()  ){
1850
+			return $terms;
1851
+		}
1852 1852
 
1853
-        // avoid infinite call loop
1854
-        remove_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
1853
+		// avoid infinite call loop
1854
+		remove_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
1855 1855
 
1856
-        // in certain cases the array is passed in as reference to the parent term_id => parent_id
1857
-        if( isset( $args['fields'] ) && 'id=>parent' == $args['fields'] ){
1858
-            // change only scrub the terms ids form the array keys
1859
-            $terms = array_keys( $terms );
1860
-        }
1856
+		// in certain cases the array is passed in as reference to the parent term_id => parent_id
1857
+		if( isset( $args['fields'] ) && 'id=>parent' == $args['fields'] ){
1858
+			// change only scrub the terms ids form the array keys
1859
+			$terms = array_keys( $terms );
1860
+		}
1861 1861
 
1862
-        $teachers_terms =  $this->filter_terms_by_owner( $terms, get_current_user_id() );
1862
+		$teachers_terms =  $this->filter_terms_by_owner( $terms, get_current_user_id() );
1863 1863
 
1864
-        // add filter again as removed above
1865
-        add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
1864
+		// add filter again as removed above
1865
+		add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
1866 1866
 
1867
-        return $teachers_terms;
1868
-    }// end filter_module_terms
1867
+		return $teachers_terms;
1868
+	}// end filter_module_terms
1869 1869
 
1870
-    /**
1871
-     * For the selected items on a course module only return those
1872
-     * for the current user. This does not apply to admin and super admin users.
1873
-     *
1874
-     * hooked into get_object_terms
1875
-     *
1876
-     * @since 1.8.0
1877
-     */
1878
-    public function filter_course_selected_terms( $terms, $course_ids_array, $taxonomies ){
1870
+	/**
1871
+	 * For the selected items on a course module only return those
1872
+	 * for the current user. This does not apply to admin and super admin users.
1873
+	 *
1874
+	 * hooked into get_object_terms
1875
+	 *
1876
+	 * @since 1.8.0
1877
+	 */
1878
+	public function filter_course_selected_terms( $terms, $course_ids_array, $taxonomies ){
1879 1879
 
1880
-        //dont limit for admins and other taxonomies. This should also only apply to admin
1881
-        if( current_user_can( 'manage_options' ) || ! is_admin() || empty( $terms )
1882
-            // only apply this to module only taxonomy queries so 1 taxonomy only:
1883
-            ||  count( $taxonomies ) > 1 || !in_array( 'module', $taxonomies )  ){
1884
-            return $terms;
1885
-        }
1880
+		//dont limit for admins and other taxonomies. This should also only apply to admin
1881
+		if( current_user_can( 'manage_options' ) || ! is_admin() || empty( $terms )
1882
+			// only apply this to module only taxonomy queries so 1 taxonomy only:
1883
+			||  count( $taxonomies ) > 1 || !in_array( 'module', $taxonomies )  ){
1884
+			return $terms;
1885
+		}
1886 1886
 
1887
-        $term_objects = $this->filter_terms_by_owner( $terms, get_current_user_id() );
1887
+		$term_objects = $this->filter_terms_by_owner( $terms, get_current_user_id() );
1888 1888
 
1889
-        // if term objects were passed in send back objects
1890
-        // if term id were passed in send that back
1891
-        if( is_object( $terms[0] ) ){
1892
-            return $term_objects;
1893
-        }
1889
+		// if term objects were passed in send back objects
1890
+		// if term id were passed in send that back
1891
+		if( is_object( $terms[0] ) ){
1892
+			return $term_objects;
1893
+		}
1894 1894
 
1895
-        $terms = array();
1896
-        foreach( $term_objects as $term_object ){
1897
-            $terms[] = $term_object->term_id;
1898
-        }
1895
+		$terms = array();
1896
+		foreach( $term_objects as $term_object ){
1897
+			$terms[] = $term_object->term_id;
1898
+		}
1899 1899
 
1900
-        return $terms;
1900
+		return $terms;
1901 1901
 
1902 1902
 
1903
-    }// end filter_course_selected_terms
1903
+	}// end filter_course_selected_terms
1904 1904
 
1905
-    /**
1906
-     * Filter the given terms and only return the
1907
-     * terms that belong to the given user id.
1908
-     *
1909
-     * @since 1.8.0
1910
-     * @param $terms
1911
-     * @param $user_id
1912
-     * @return array
1913
-     */
1914
-    public function filter_terms_by_owner( $terms, $user_id ){
1905
+	/**
1906
+	 * Filter the given terms and only return the
1907
+	 * terms that belong to the given user id.
1908
+	 *
1909
+	 * @since 1.8.0
1910
+	 * @param $terms
1911
+	 * @param $user_id
1912
+	 * @return array
1913
+	 */
1914
+	public function filter_terms_by_owner( $terms, $user_id ){
1915 1915
 
1916
-        $users_terms = array();
1916
+		$users_terms = array();
1917 1917
 
1918
-        foreach( $terms as $index => $term ){
1918
+		foreach( $terms as $index => $term ){
1919 1919
 
1920
-            if( is_numeric( $term ) ){
1921
-                // the term id was given, get the term object
1922
-                $term = get_term( $term, 'module' );
1923
-            }
1920
+			if( is_numeric( $term ) ){
1921
+				// the term id was given, get the term object
1922
+				$term = get_term( $term, 'module' );
1923
+			}
1924 1924
 
1925
-            $author = Sensei_Core_Modules::get_term_author( $term->slug );
1925
+			$author = Sensei_Core_Modules::get_term_author( $term->slug );
1926 1926
 
1927
-            if ( $user_id == $author->ID ) {
1928
-                // add the term to the teachers terms
1929
-                $users_terms[] = $term;
1930
-            }
1927
+			if ( $user_id == $author->ID ) {
1928
+				// add the term to the teachers terms
1929
+				$users_terms[] = $term;
1930
+			}
1931 1931
 
1932
-        }
1932
+		}
1933 1933
 
1934
-        return $users_terms;
1934
+		return $users_terms;
1935 1935
 
1936
-    } // end filter terms by owner
1936
+	} // end filter terms by owner
1937 1937
 
1938
-    /**
1939
-     * Add the teacher name next to modules. Only works in Admin for Admin users.
1940
-     * This will not add name to terms belonging to admin user.
1941
-     *
1942
-     * Hooked into 'get_terms'
1943
-     *
1944
-     * @since 1.8.0
1945
-     */
1946
-    public function append_teacher_name_to_module( $terms, $taxonomies, $args )
1947
-    {
1938
+	/**
1939
+	 * Add the teacher name next to modules. Only works in Admin for Admin users.
1940
+	 * This will not add name to terms belonging to admin user.
1941
+	 *
1942
+	 * Hooked into 'get_terms'
1943
+	 *
1944
+	 * @since 1.8.0
1945
+	 */
1946
+	public function append_teacher_name_to_module( $terms, $taxonomies, $args )
1947
+	{
1948 1948
 
1949
-        // only for admin users ont he module taxonomy
1950
-        if ( empty( $terms ) || !current_user_can('manage_options') || !in_array('module', $taxonomies) || !is_admin()) {
1951
-            return $terms;
1952
-        }
1949
+		// only for admin users ont he module taxonomy
1950
+		if ( empty( $terms ) || !current_user_can('manage_options') || !in_array('module', $taxonomies) || !is_admin()) {
1951
+			return $terms;
1952
+		}
1953 1953
 
1954
-        // in certain cases the array is passed in as reference to the parent term_id => parent_id
1955
-        // simply return this as wp doesn't need an array of stdObject Term
1956
-        if (isset( $args['fields'] ) && 'id=>parent' == $args['fields']) {
1954
+		// in certain cases the array is passed in as reference to the parent term_id => parent_id
1955
+		// simply return this as wp doesn't need an array of stdObject Term
1956
+		if (isset( $args['fields'] ) && 'id=>parent' == $args['fields']) {
1957 1957
 
1958
-            return $terms;
1958
+			return $terms;
1959 1959
 
1960
-        }
1960
+		}
1961 1961
 
1962
-        // loop through and update all terms adding the author name
1963
-        foreach( $terms as $index => $term ){
1962
+		// loop through and update all terms adding the author name
1963
+		foreach( $terms as $index => $term ){
1964 1964
 
1965
-            if( is_numeric( $term ) ){
1966
-                // the term id was given, get the term object
1967
-                $term = get_term( $term, 'module' );
1968
-            }
1965
+			if( is_numeric( $term ) ){
1966
+				// the term id was given, get the term object
1967
+				$term = get_term( $term, 'module' );
1968
+			}
1969 1969
 
1970
-            $author = Sensei_Core_Modules::get_term_author( $term->slug );
1970
+			$author = Sensei_Core_Modules::get_term_author( $term->slug );
1971 1971
 
1972
-            if( ! user_can( $author, 'manage_options' ) && isset( $term->name ) ) {
1973
-                $term->name = $term->name . ' (' . $author->display_name . ') ';
1974
-            }
1972
+			if( ! user_can( $author, 'manage_options' ) && isset( $term->name ) ) {
1973
+				$term->name = $term->name . ' (' . $author->display_name . ') ';
1974
+			}
1975 1975
 
1976
-            // add the term to the teachers terms
1977
-            $users_terms[] = $term;
1976
+			// add the term to the teachers terms
1977
+			$users_terms[] = $term;
1978 1978
 
1979
-        }
1979
+		}
1980 1980
 
1981
-        return $users_terms;
1982
-    }
1981
+		return $users_terms;
1982
+	}
1983 1983
 
1984
-    /**
1985
-     * Remove modules metabox that come by default
1986
-     * with the modules taxonomy. We are removing this as
1987
-     * we have created our own custom meta box.
1988
-     */
1989
-    public static function remove_default_modules_box() {
1984
+	/**
1985
+	 * Remove modules metabox that come by default
1986
+	 * with the modules taxonomy. We are removing this as
1987
+	 * we have created our own custom meta box.
1988
+	 */
1989
+	public static function remove_default_modules_box() {
1990 1990
 
1991
-        remove_meta_box('modulediv', 'course', 'side');
1991
+		remove_meta_box('modulediv', 'course', 'side');
1992 1992
 
1993
-    }
1993
+	}
1994 1994
 
1995
-    /**
1996
-     * When a course is save make sure to reset the transient set
1997
-     * for it when determining the none module lessons.
1998
-     *
1999
-     * @sine 1.9.0
2000
-     * @param $post_id
2001
-     */
2002
-    public static function reset_none_modules_transient ( $post_id ){
1995
+	/**
1996
+	 * When a course is save make sure to reset the transient set
1997
+	 * for it when determining the none module lessons.
1998
+	 *
1999
+	 * @sine 1.9.0
2000
+	 * @param $post_id
2001
+	 */
2002
+	public static function reset_none_modules_transient ( $post_id ){
2003 2003
 
2004
-        // this should only apply to course and lesson post types
2005
-        if( in_array( get_post_type( $post_id ), array( 'course', 'lesson' ) ) ){
2004
+		// this should only apply to course and lesson post types
2005
+		if( in_array( get_post_type( $post_id ), array( 'course', 'lesson' ) ) ){
2006 2006
 
2007
-            $course_id = '';
2007
+			$course_id = '';
2008 2008
 
2009
-            if( 'lesson' == get_post_type( $post_id ) ){
2009
+			if( 'lesson' == get_post_type( $post_id ) ){
2010 2010
 
2011
-                $course_id = Sensei()->lesson->get_course_id( $post_id );
2011
+				$course_id = Sensei()->lesson->get_course_id( $post_id );
2012 2012
 
2013
-            }
2013
+			}
2014 2014
 
2015 2015
 
2016
-            if( !empty( $course_id ) ){
2016
+			if( !empty( $course_id ) ){
2017 2017
 
2018
-                delete_transient( 'sensei_'. $course_id .'_none_module_lessons' );
2018
+				delete_transient( 'sensei_'. $course_id .'_none_module_lessons' );
2019 2019
 
2020
-            }
2020
+			}
2021 2021
 
2022
-        } // end if is a course or a lesson
2022
+		} // end if is a course or a lesson
2023 2023
 
2024
-    } // end reset_none_modules_transient
2024
+	} // end reset_none_modules_transient
2025 2025
 
2026
-    /**
2027
-     * This function calls the deprecated hook 'sensei_single_course_modules_content' to fire
2028
-     *
2029
-     * @since 1.9.0
2030
-     * @deprecated since 1.9.0
2031
-     *
2032
-     */
2033
-    public static function deprecate_sensei_single_course_modules_content(){
2026
+	/**
2027
+	 * This function calls the deprecated hook 'sensei_single_course_modules_content' to fire
2028
+	 *
2029
+	 * @since 1.9.0
2030
+	 * @deprecated since 1.9.0
2031
+	 *
2032
+	 */
2033
+	public static function deprecate_sensei_single_course_modules_content(){
2034 2034
 
2035
-        sensei_do_deprecated_action( 'sensei_single_course_modules_content','1.9.0','sensei_single_course_modules_before or sensei_single_course_modules_after' );
2035
+		sensei_do_deprecated_action( 'sensei_single_course_modules_content','1.9.0','sensei_single_course_modules_before or sensei_single_course_modules_after' );
2036 2036
 
2037
-    }
2037
+	}
2038 2038
 
2039
-    /**
2040
-     * Setup the single course module loop.
2041
-     *
2042
-     * Setup the global $sensei_modules_loop
2043
-     *
2044
-     * @since 1.9.0
2045
-     */
2046
-    public static function setup_single_course_module_loop(){
2039
+	/**
2040
+	 * Setup the single course module loop.
2041
+	 *
2042
+	 * Setup the global $sensei_modules_loop
2043
+	 *
2044
+	 * @since 1.9.0
2045
+	 */
2046
+	public static function setup_single_course_module_loop(){
2047 2047
 
2048
-        global $sensei_modules_loop, $post;
2049
-        $course_id = $post->ID;
2048
+		global $sensei_modules_loop, $post;
2049
+		$course_id = $post->ID;
2050 2050
 
2051
-        $modules = Sensei()->modules->get_course_modules( $course_id );
2051
+		$modules = Sensei()->modules->get_course_modules( $course_id );
2052 2052
 
2053
-        //initial setup
2054
-        $sensei_modules_loop['total'] = 0;
2055
-        $sensei_modules_loop['modules'] = array();
2056
-        $sensei_modules_loop['current'] = -1;
2053
+		//initial setup
2054
+		$sensei_modules_loop['total'] = 0;
2055
+		$sensei_modules_loop['modules'] = array();
2056
+		$sensei_modules_loop['current'] = -1;
2057 2057
 
2058
-        // exit if this course doesn't have modules
2059
-        if( !$modules || empty( $modules )  ){
2060
-            return;
2061
-        }
2058
+		// exit if this course doesn't have modules
2059
+		if( !$modules || empty( $modules )  ){
2060
+			return;
2061
+		}
2062 2062
 
2063 2063
 
2064
-        $lessons_in_all_modules = array();
2065
-        foreach( $modules as $term ){
2064
+		$lessons_in_all_modules = array();
2065
+		foreach( $modules as $term ){
2066 2066
 
2067
-            $lessons_in_this_module = Sensei()->modules->get_lessons( $course_id , $term->term_id);
2068
-            $lessons_in_all_modules = array_merge(  $lessons_in_all_modules, $lessons_in_this_module  );
2067
+			$lessons_in_this_module = Sensei()->modules->get_lessons( $course_id , $term->term_id);
2068
+			$lessons_in_all_modules = array_merge(  $lessons_in_all_modules, $lessons_in_this_module  );
2069 2069
 
2070
-        }
2070
+		}
2071 2071
 
2072 2072
 
2073
-        //setup all of the modules loop variables
2074
-        $sensei_modules_loop['total'] = count( $modules );
2075
-        $sensei_modules_loop['modules'] = $modules;
2076
-        $sensei_modules_loop['current'] = -1;
2077
-        $sensei_modules_loop['course_id'] = $course_id;
2073
+		//setup all of the modules loop variables
2074
+		$sensei_modules_loop['total'] = count( $modules );
2075
+		$sensei_modules_loop['modules'] = $modules;
2076
+		$sensei_modules_loop['current'] = -1;
2077
+		$sensei_modules_loop['course_id'] = $course_id;
2078 2078
 
2079
-    }// end setup_single_course_module_loop
2079
+	}// end setup_single_course_module_loop
2080 2080
 
2081
-    /**
2082
-     * Tear down the course module loop.
2083
-     *
2084
-     * @since 1.9.0
2085
-     *
2086
-     */
2087
-    public static function teardown_single_course_module_loop(){
2081
+	/**
2082
+	 * Tear down the course module loop.
2083
+	 *
2084
+	 * @since 1.9.0
2085
+	 *
2086
+	 */
2087
+	public static function teardown_single_course_module_loop(){
2088 2088
 
2089
-        global $sensei_modules_loop, $wp_query, $post;
2089
+		global $sensei_modules_loop, $wp_query, $post;
2090 2090
 
2091
-        //reset all of the modules loop variables
2092
-        $sensei_modules_loop['total'] = 0;
2093
-        $sensei_modules_loop['modules'] = array();
2094
-        $sensei_modules_loop['current'] = -1;
2091
+		//reset all of the modules loop variables
2092
+		$sensei_modules_loop['total'] = 0;
2093
+		$sensei_modules_loop['modules'] = array();
2094
+		$sensei_modules_loop['current'] = -1;
2095 2095
 
2096
-        // set the current course to be the global post again
2097
-        wp_reset_query();
2098
-        $post = $wp_query->post;
2099
-    }// end teardown_single_course_module_loop
2096
+		// set the current course to be the global post again
2097
+		wp_reset_query();
2098
+		$post = $wp_query->post;
2099
+	}// end teardown_single_course_module_loop
2100 2100
 
2101 2101
 } // end modules class
Please login to merge, or discard this patch.
Spacing   +259 added lines, -259 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if ( ! defined('ABSPATH')) exit;
4 4
 
5 5
 /**
6 6
  * Sensei Modules Class
@@ -21,33 +21,33 @@  discard block
 block discarded – undo
21 21
     private $order_page_slug;
22 22
     public $taxonomy;
23 23
 
24
-    public function __construct( $file )
24
+    public function __construct($file)
25 25
     {
26 26
         $this->file = $file;
27 27
         $this->dir = dirname($this->file);
28
-        $this->assets_dir = trailingslashit($this->dir) . 'assets';
28
+        $this->assets_dir = trailingslashit($this->dir).'assets';
29 29
         $this->assets_url = esc_url(trailingslashit(plugins_url('/assets/', $this->file)));
30 30
         $this->taxonomy = 'module';
31 31
         $this->order_page_slug = 'module-order';
32 32
 
33 33
         // setup taxonomy
34
-        add_action( 'init', array( $this, 'setup_modules_taxonomy' ), 10 );
34
+        add_action('init', array($this, 'setup_modules_taxonomy'), 10);
35 35
 
36 36
         // Manage lesson meta boxes for taxonomy
37
-        add_action('add_meta_boxes', array($this, 'modules_metaboxes'), 20, 2 );
37
+        add_action('add_meta_boxes', array($this, 'modules_metaboxes'), 20, 2);
38 38
 
39 39
         // Save lesson meta box
40 40
         add_action('save_post', array($this, 'save_lesson_module'), 10, 1);
41 41
 
42 42
         //Reset the none modules lessons transient
43
-        add_action( 'save_post', array( 'Sensei_Core_Modules', 'reset_none_modules_transient' ) );
43
+        add_action('save_post', array('Sensei_Core_Modules', 'reset_none_modules_transient'));
44 44
 
45 45
         // Frontend styling
46 46
         add_action('wp_enqueue_scripts', array($this, 'enqueue_styles'));
47 47
 
48 48
         // Admin styling
49 49
         add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_styles'));
50
-        add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'),  20 , 2 );
50
+        add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'), 20, 2);
51 51
 
52 52
         // Handle module completion record
53 53
         add_action('sensei_lesson_status_updated', array($this, 'update_lesson_status_module_progress'), 10, 3);
@@ -55,20 +55,20 @@  discard block
 block discarded – undo
55 55
         add_action('wp', array($this, 'save_module_progress'), 10);
56 56
 
57 57
         // Handle module ordering
58
-        add_action('admin_menu', array($this, 'register_modules_admin_menu_items'), 30 );
58
+        add_action('admin_menu', array($this, 'register_modules_admin_menu_items'), 30);
59 59
         add_filter('manage_edit-course_columns', array($this, 'course_columns'), 11, 1);
60 60
         add_action('manage_posts_custom_column', array($this, 'course_column_content'), 11, 2);
61 61
 
62 62
         // Ensure modules always show under courses
63
-        add_action( 'admin_menu', array( $this, 'remove_lessons_menu_model_taxonomy' ) , 10 );
64
-        add_action( 'admin_menu', array( $this, 'remove_courses_menu_model_taxonomy' ) , 10 );
65
-        add_action( 'admin_menu', array( $this, 'redirect_to_lesson_module_taxonomy_to_course' ) , 20 );
63
+        add_action('admin_menu', array($this, 'remove_lessons_menu_model_taxonomy'), 10);
64
+        add_action('admin_menu', array($this, 'remove_courses_menu_model_taxonomy'), 10);
65
+        add_action('admin_menu', array($this, 'redirect_to_lesson_module_taxonomy_to_course'), 20);
66 66
 
67 67
         // Add course field to taxonomy
68
-        add_action($this->taxonomy . '_add_form_fields', array($this, 'add_module_fields'), 50, 1);
69
-        add_action($this->taxonomy . '_edit_form_fields', array($this, 'edit_module_fields'), 1, 1);
70
-        add_action('edited_' . $this->taxonomy, array($this, 'save_module_course'), 10, 2);
71
-        add_action('created_' . $this->taxonomy, array($this, 'save_module_course'), 10, 2);
68
+        add_action($this->taxonomy.'_add_form_fields', array($this, 'add_module_fields'), 50, 1);
69
+        add_action($this->taxonomy.'_edit_form_fields', array($this, 'edit_module_fields'), 1, 1);
70
+        add_action('edited_'.$this->taxonomy, array($this, 'save_module_course'), 10, 2);
71
+        add_action('created_'.$this->taxonomy, array($this, 'save_module_course'), 10, 2);
72 72
         add_action('wp_ajax_sensei_json_search_courses', array($this, 'search_courses_json'));
73 73
 
74 74
         // Manage module taxonomy archive page
@@ -80,10 +80,10 @@  discard block
 block discarded – undo
80 80
         add_filter('body_class', array($this, 'module_archive_body_class'));
81 81
 
82 82
         // add modules to the single course template
83
-        add_action( 'sensei_single_course_content_inside_after', array($this, 'load_course_module_content_template') , 8 );
83
+        add_action('sensei_single_course_content_inside_after', array($this, 'load_course_module_content_template'), 8);
84 84
 
85 85
         //Single Course modules actions. Add to single-course/course-modules.php
86
-        add_action('sensei_single_course_modules_before',array( $this,'course_modules_title' ), 20);
86
+        add_action('sensei_single_course_modules_before', array($this, 'course_modules_title'), 20);
87 87
 
88 88
         // Set up display on single lesson page
89 89
         add_filter('sensei_breadcrumb_output', array($this, 'module_breadcrumb_link'), 10, 2);
@@ -95,22 +95,22 @@  discard block
 block discarded – undo
95 95
         add_filter('sensei_analysis_course_column_data', array($this, 'analysis_course_column_data'), 10, 3);
96 96
 
97 97
         // Manage module taxonomy columns
98
-        add_filter('manage_edit-' . $this->taxonomy . '_columns', array($this, 'taxonomy_column_headings'), 1, 1);
99
-        add_filter('manage_' . $this->taxonomy . '_custom_column', array($this, 'taxonomy_column_content'), 1, 3);
98
+        add_filter('manage_edit-'.$this->taxonomy.'_columns', array($this, 'taxonomy_column_headings'), 1, 1);
99
+        add_filter('manage_'.$this->taxonomy.'_custom_column', array($this, 'taxonomy_column_content'), 1, 3);
100 100
         add_filter('sensei_module_lesson_list_title', array($this, 'sensei_course_preview_titles'), 10, 2);
101 101
 
102 102
         //store new modules created on the course edit screen
103
-        add_action( 'wp_ajax_sensei_add_new_module_term', array( 'Sensei_Core_Modules','add_new_module_term' ) );
103
+        add_action('wp_ajax_sensei_add_new_module_term', array('Sensei_Core_Modules', 'add_new_module_term'));
104 104
 
105 105
         // for non admin users, only show taxonomies that belong to them
106
-        add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
107
-        add_filter('get_object_terms', array( $this, 'filter_course_selected_terms' ), 20, 3 );
106
+        add_filter('get_terms', array($this, 'filter_module_terms'), 20, 3);
107
+        add_filter('get_object_terms', array($this, 'filter_course_selected_terms'), 20, 3);
108 108
 
109 109
         // add the teacher name next to the module term in for admin users
110
-        add_filter('get_terms', array( $this, 'append_teacher_name_to_module' ), 70, 3 );
110
+        add_filter('get_terms', array($this, 'append_teacher_name_to_module'), 70, 3);
111 111
 
112 112
         // remove the default modules  metabox
113
-        add_action('admin_init',array( 'Sensei_Core_Modules' , 'remove_default_modules_box' ));
113
+        add_action('admin_init', array('Sensei_Core_Modules', 'remove_default_modules_box'));
114 114
 
115 115
     } // end constructor
116 116
 
@@ -127,9 +127,9 @@  discard block
 block discarded – undo
127 127
      * @return void
128 128
      * @deprecated since 1.9.0
129 129
      */
130
-    public function change_module_term_slug( $term_id, $tt_id, $taxonomy ){
130
+    public function change_module_term_slug($term_id, $tt_id, $taxonomy) {
131 131
 
132
-        _deprecated_function('change_module_term_slug', '1.9.0' );
132
+        _deprecated_function('change_module_term_slug', '1.9.0');
133 133
 
134 134
     }// end add_module_term_group
135 135
 
@@ -143,20 +143,20 @@  discard block
 block discarded – undo
143 143
      *
144 144
      * @return void
145 145
      */
146
-    public function modules_metaboxes( $post_type, $post )
146
+    public function modules_metaboxes($post_type, $post)
147 147
     {
148
-        if ('lesson' == $post_type ) {
148
+        if ('lesson' == $post_type) {
149 149
 
150 150
             // Remove default taxonomy meta box from Lesson edit screen
151
-            remove_meta_box($this->taxonomy . 'div', 'lesson', 'side');
151
+            remove_meta_box($this->taxonomy.'div', 'lesson', 'side');
152 152
 
153 153
             // Add custom meta box to limit module selection to one per lesson
154
-            add_meta_box($this->taxonomy . '_select', __('Lesson Module', 'woothemes-sensei'), array($this, 'lesson_module_metabox'), 'lesson', 'side', 'default');
154
+            add_meta_box($this->taxonomy.'_select', __('Lesson Module', 'woothemes-sensei'), array($this, 'lesson_module_metabox'), 'lesson', 'side', 'default');
155 155
         }
156 156
 
157
-        if( 'course' == $post_type ){
157
+        if ('course' == $post_type) {
158 158
             // Course modules selection metabox
159
-            add_meta_box( $this->taxonomy . '_course_mb', __('Course Modules', 'woothemes-sensei'), array( $this, 'course_module_metabox'), 'course', 'side', 'core');
159
+            add_meta_box($this->taxonomy.'_course_mb', __('Course Modules', 'woothemes-sensei'), array($this, 'course_module_metabox'), 'course', 'side', 'core');
160 160
         }
161 161
     }
162 162
 
@@ -192,21 +192,21 @@  discard block
 block discarded – undo
192 192
             $modules = $this->get_course_modules($lesson_course);
193 193
 
194 194
             // Build the HTML to output
195
-            $html .= '<input type="hidden" name="' . esc_attr('woo_lesson_' . $this->taxonomy . '_nonce') . '" id="' . esc_attr('woo_lesson_' . $this->taxonomy . '_nonce') . '" value="' . esc_attr(wp_create_nonce(plugin_basename($this->file))) . '" />';
195
+            $html .= '<input type="hidden" name="'.esc_attr('woo_lesson_'.$this->taxonomy.'_nonce').'" id="'.esc_attr('woo_lesson_'.$this->taxonomy.'_nonce').'" value="'.esc_attr(wp_create_nonce(plugin_basename($this->file))).'" />';
196 196
             if (is_array($modules) && count($modules) > 0) {
197
-                $html .= '<select id="lesson-module-options" name="lesson_module" class="widefat">' . "\n";
198
-                $html .= '<option value="">' . __('None', 'woothemes-sensei') . '</option>';
197
+                $html .= '<select id="lesson-module-options" name="lesson_module" class="widefat">'."\n";
198
+                $html .= '<option value="">'.__('None', 'woothemes-sensei').'</option>';
199 199
                 foreach ($modules as $module) {
200
-                    $html .= '<option value="' . esc_attr(absint($module->term_id)) . '"' . selected($module->term_id, $lesson_module, false) . '>' . esc_html($module->name) . '</option>' . "\n";
200
+                    $html .= '<option value="'.esc_attr(absint($module->term_id)).'"'.selected($module->term_id, $lesson_module, false).'>'.esc_html($module->name).'</option>'."\n";
201 201
                 }
202
-                $html .= '</select>' . "\n";
202
+                $html .= '</select>'."\n";
203 203
             } else {
204
-                $course_url = admin_url('post.php?post=' . urlencode($lesson_course) . '&action=edit');
205
-                $html .= '<p>' . sprintf(__('No modules are available for this lesson yet. %1$sPlease add some to %3$sthe course%4$s.%2$s', 'woothemes-sensei'), '<em>', '</em>', '<a href="' . esc_url($course_url) . '">', '</a>') . '</p>';
204
+                $course_url = admin_url('post.php?post='.urlencode($lesson_course).'&action=edit');
205
+                $html .= '<p>'.sprintf(__('No modules are available for this lesson yet. %1$sPlease add some to %3$sthe course%4$s.%2$s', 'woothemes-sensei'), '<em>', '</em>', '<a href="'.esc_url($course_url).'">', '</a>').'</p>';
206 206
             } // End If Statement
207 207
 
208 208
         } else {
209
-            $html .= '<p>' . sprintf(__('No modules are available for this lesson yet. %1$sPlease select a course first.%2$s', 'woothemes-sensei'), '<em>', '</em>') . '</p>';
209
+            $html .= '<p>'.sprintf(__('No modules are available for this lesson yet. %1$sPlease select a course first.%2$s', 'woothemes-sensei'), '<em>', '</em>').'</p>';
210 210
         } // End If Statement
211 211
 
212 212
         // Output the HTML
@@ -225,38 +225,38 @@  discard block
 block discarded – undo
225 225
         global $post;
226 226
 
227 227
         // Verify post type and nonce
228
-        if ((get_post_type() != 'lesson') || !isset($_POST['woo_lesson_' . $this->taxonomy . '_nonce'] )
229
-            ||!wp_verify_nonce($_POST['woo_lesson_' . $this->taxonomy . '_nonce'], plugin_basename($this->file))) {
228
+        if ((get_post_type() != 'lesson') || ! isset($_POST['woo_lesson_'.$this->taxonomy.'_nonce'])
229
+            ||! wp_verify_nonce($_POST['woo_lesson_'.$this->taxonomy.'_nonce'], plugin_basename($this->file))) {
230 230
             return $post_id;
231 231
         }
232 232
 
233 233
         // Check if user has permissions to edit lessons
234 234
         $post_type = get_post_type_object($post->post_type);
235
-        if (!current_user_can($post_type->cap->edit_post, $post_id)) {
235
+        if ( ! current_user_can($post_type->cap->edit_post, $post_id)) {
236 236
             return $post_id;
237 237
         }
238 238
 
239 239
         // Check if user has permissions to edit this specific post
240
-        if (!current_user_can('edit_post', $post_id)) {
240
+        if ( ! current_user_can('edit_post', $post_id)) {
241 241
             return $post_id;
242 242
         }
243 243
 
244 244
         // Cast module ID as an integer if selected, otherwise leave as empty string
245
-        if ( isset( $_POST['lesson_module'] ) ) {
245
+        if (isset($_POST['lesson_module'])) {
246 246
 
247
-            if( empty ( $_POST['lesson_module'] ) ){
248
-                wp_delete_object_term_relationships($post_id, $this->taxonomy  );
247
+            if (empty ($_POST['lesson_module'])) {
248
+                wp_delete_object_term_relationships($post_id, $this->taxonomy);
249 249
                 return true;
250 250
             }
251 251
 
252
-            $module_id = intval( $_POST['lesson_module'] );
252
+            $module_id = intval($_POST['lesson_module']);
253 253
 
254 254
             // Assign lesson to selected module
255 255
             wp_set_object_terms($post_id, $module_id, $this->taxonomy, false);
256 256
 
257 257
             // Set default order for lesson inside module
258
-            if (!get_post_meta($post_id, '_order_module_' . $module_id, true)) {
259
-                update_post_meta($post_id, '_order_module_' . $module_id, 0);
258
+            if ( ! get_post_meta($post_id, '_order_module_'.$module_id, true)) {
259
+                update_post_meta($post_id, '_order_module_'.$module_id, 0);
260 260
             }
261 261
         }
262 262
 
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
         $module_courses = array();
315 315
         if (isset($courses) && is_array($courses)) {
316 316
             foreach ($courses as $course) {
317
-                $module_courses[] =   array( 'id' =>$course->ID, 'details'=>$course->post_title );
317
+                $module_courses[] = array('id' =>$course->ID, 'details'=>$course->post_title);
318 318
             }
319 319
         }
320 320
 
@@ -324,8 +324,8 @@  discard block
 block discarded – undo
324 324
                     for="module_courses"><?php _e('Course(s)', 'woothemes-sensei'); ?></label></th>
325 325
             <td>
326 326
                 <input type="hidden"
327
-                       data-defaults="<?php echo esc_attr( json_encode($module_courses)); ?>"
328
-                       value="<?php echo esc_attr( json_encode($module_courses) ); ?>"
327
+                       data-defaults="<?php echo esc_attr(json_encode($module_courses)); ?>"
328
+                       value="<?php echo esc_attr(json_encode($module_courses)); ?>"
329 329
                        id="module_courses" name="module_courses"
330 330
                        class="ajax_chosen_select_courses"
331 331
                        placeholder="<?php esc_attr_e('Search for courses...', 'woothemes-sensei'); ?>"
@@ -370,11 +370,11 @@  discard block
 block discarded – undo
370 370
         }
371 371
 
372 372
         // Add module to selected courses
373
-        if ( isset( $_POST['module_courses'] ) && ! empty( $_POST['module_courses'] ) ) {
373
+        if (isset($_POST['module_courses']) && ! empty($_POST['module_courses'])) {
374 374
 
375
-            $course_ids = explode( ",", $_POST['module_courses'] );
375
+            $course_ids = explode(",", $_POST['module_courses']);
376 376
 
377
-            foreach ( $course_ids as $course_id ) {
377
+            foreach ($course_ids as $course_id) {
378 378
 
379 379
                 wp_set_object_terms($course_id, $module_id, $this->taxonomy, true);
380 380
 
@@ -438,11 +438,11 @@  discard block
 block discarded – undo
438 438
      * @since 1.8.0
439 439
      * @return void
440 440
      */
441
-    public function single_course_modules(){
441
+    public function single_course_modules() {
442 442
 
443
-        _deprecated_function('Sensei_Modules->single_course_modules','Sensei 1.9.0', 'Sensei()->modules->load_course_module_content_template');
443
+        _deprecated_function('Sensei_Modules->single_course_modules', 'Sensei 1.9.0', 'Sensei()->modules->load_course_module_content_template');
444 444
         // only show modules on the course that has modules
445
-        if( is_singular( 'course' ) && has_term( '', 'module' )  )  {
445
+        if (is_singular('course') && has_term('', 'module')) {
446 446
 
447 447
             $this->load_course_module_content_template();
448 448
 
@@ -459,15 +459,15 @@  discard block
 block discarded – undo
459 459
 
460 460
         if (method_exists('Sensei_Utils', 'is_preview_lesson') && Sensei_Utils::is_preview_lesson($lesson_id)) {
461 461
             $is_user_taking_course = Sensei_Utils::sensei_check_for_activity(array('post_id' => $course_id, 'user_id' => $current_user->ID, 'type' => 'sensei_course_status'));
462
-            if (!$is_user_taking_course) {
462
+            if ( ! $is_user_taking_course) {
463 463
                 if (method_exists('WooThemes_Sensei_Frontend', 'sensei_lesson_preview_title_text')) {
464 464
                     $title_text = Sensei()->frontend->sensei_lesson_preview_title_text($course_id);
465 465
                     // Remove brackets for display here
466 466
                     $title_text = str_replace('(', '', $title_text);
467 467
                     $title_text = str_replace(')', '', $title_text);
468
-                    $title_text = '<span class="preview-label">' . $title_text . '</span>';
468
+                    $title_text = '<span class="preview-label">'.$title_text.'</span>';
469 469
                 }
470
-                $title .= ' ' . $title_text;
470
+                $title .= ' '.$title_text;
471 471
             }
472 472
         }
473 473
 
@@ -481,8 +481,8 @@  discard block
 block discarded – undo
481 481
         if (is_singular('lesson')) {
482 482
             if (has_term('', $this->taxonomy, $post->ID)) {
483 483
                 $module = $this->get_lesson_module($post->ID);
484
-                if( $module ) {
485
-                    $html .= ' ' . $separator . ' <a href="' . esc_url($module->url) . '" title="' .  __('Back to the module', 'woothemes-sensei') . '">' . $module->name . '</a>';
484
+                if ($module) {
485
+                    $html .= ' '.$separator.' <a href="'.esc_url($module->url).'" title="'.__('Back to the module', 'woothemes-sensei').'">'.$module->name.'</a>';
486 486
                 }
487 487
             }
488 488
         }
@@ -490,7 +490,7 @@  discard block
 block discarded – undo
490 490
         if (is_tax($this->taxonomy)) {
491 491
             if (isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) {
492 492
                 $course_id = intval($_GET['course_id']);
493
-                $html .= '<a href="' . esc_url(get_permalink($course_id)) . '" title="' .  __('Back to the course', 'woothemes-sensei') . '">' . get_the_title($course_id) . '</a>';
493
+                $html .= '<a href="'.esc_url(get_permalink($course_id)).'" title="'.__('Back to the course', 'woothemes-sensei').'">'.get_the_title($course_id).'</a>';
494 494
             }
495 495
         }
496 496
         return $html;
@@ -505,18 +505,18 @@  discard block
 block discarded – undo
505 505
      */
506 506
     public function module_archive_template($template) {
507 507
 
508
-        if ( ! is_tax($this->taxonomy) ) {
508
+        if ( ! is_tax($this->taxonomy)) {
509 509
             return $template;
510 510
         }
511 511
 
512 512
         $file = 'archive-lesson.php';
513
-        $find = array( $file, Sensei()->template_url . $file );
513
+        $find = array($file, Sensei()->template_url.$file);
514 514
 
515 515
         // locate the template file
516 516
         $template = locate_template($find);
517
-        if (!$template) {
517
+        if ( ! $template) {
518 518
 
519
-            $template = Sensei()->plugin_path() . 'templates/' . $file;
519
+            $template = Sensei()->plugin_path().'templates/'.$file;
520 520
 
521 521
         }
522 522
 
@@ -542,7 +542,7 @@  discard block
 block discarded – undo
542 542
             // Set order of lessons
543 543
             if (version_compare(Sensei()->version, '1.6.0', '>=')) {
544 544
                 $module_id = $query->queried_object_id;
545
-                $query->set('meta_key', '_order_module_' . $module_id);
545
+                $query->set('meta_key', '_order_module_'.$module_id);
546 546
                 $query->set('orderby', 'meta_value_num date');
547 547
             } else {
548 548
                 $query->set('orderby', 'menu_order');
@@ -603,10 +603,10 @@  discard block
 block discarded – undo
603 603
                     $status = __('In progress', 'woothemes-sensei');
604 604
                     $class = 'in-progress';
605 605
                 }
606
-                echo '<p class="status ' . esc_attr($class) . '">' . $status . '</p>';
606
+                echo '<p class="status '.esc_attr($class).'">'.$status.'</p>';
607 607
             }
608 608
 
609
-            echo '<p class="archive-description module-description">' . apply_filters('sensei_module_archive_description', nl2br($module->description), $module->term_id) . '</p>';
609
+            echo '<p class="archive-description module-description">'.apply_filters('sensei_module_archive_description', nl2br($module->description), $module->term_id).'</p>';
610 610
         }
611 611
     }
612 612
 
@@ -731,7 +731,7 @@  discard block
 block discarded – undo
731 731
     public function save_user_module_progress($module_id = 0, $course_id = 0, $user_id = 0)
732 732
     {
733 733
         $module_progress = $this->calculate_user_module_progress($user_id, $module_id, $course_id);
734
-        update_user_meta(intval($user_id), '_module_progress_' . intval($course_id) . '_' . intval($module_id), intval($module_progress));
734
+        update_user_meta(intval($user_id), '_module_progress_'.intval($course_id).'_'.intval($module_id), intval($module_progress));
735 735
 
736 736
         do_action('sensei_module_save_user_progress', $course_id, $module_id, $user_id, $module_progress);
737 737
     }
@@ -748,9 +748,9 @@  discard block
 block discarded – undo
748 748
      */
749 749
     public function get_user_module_progress($module_id = 0, $course_id = 0, $user_id = 0)
750 750
     {
751
-        $module_progress = get_user_meta(intval($user_id), '_module_progress_' . intval($course_id) . '_' . intval($module_id), true);
751
+        $module_progress = get_user_meta(intval($user_id), '_module_progress_'.intval($course_id).'_'.intval($module_id), true);
752 752
         if ($module_progress) {
753
-            return (float)$module_progress;
753
+            return (float) $module_progress;
754 754
         }
755 755
         return false;
756 756
     }
@@ -803,7 +803,7 @@  discard block
 block discarded – undo
803 803
         }
804 804
         $module_progress = ($completed_count / $lesson_count) * 100;
805 805
 
806
-        return (float)$module_progress;
806
+        return (float) $module_progress;
807 807
     }
808 808
 
809 809
     /**
@@ -816,7 +816,7 @@  discard block
 block discarded – undo
816 816
     public function register_modules_admin_menu_items()
817 817
     {
818 818
         //add the modules link under the Course main menu
819
-        add_submenu_page('edit.php?post_type=course', __('Modules', 'woothemes-sensei'), __('Modules', 'woothemes-sensei'), 'manage_categories', 'edit-tags.php?taxonomy=module','' );
819
+        add_submenu_page('edit.php?post_type=course', __('Modules', 'woothemes-sensei'), __('Modules', 'woothemes-sensei'), 'manage_categories', 'edit-tags.php?taxonomy=module', '');
820 820
 
821 821
         // Regsiter new admin page for module ordering
822 822
         $hook = add_submenu_page('edit.php?post_type=course', __('Order Modules', 'woothemes-sensei'), __('Order Modules', 'woothemes-sensei'), 'edit_lessons', $this->order_page_slug, array($this, 'module_order_screen'));
@@ -843,19 +843,19 @@  discard block
 block discarded – undo
843 843
             $ordered = $this->save_course_module_order(esc_attr($_POST['module-order']), esc_attr($_POST['course_id']));
844 844
 
845 845
             if ($ordered) {
846
-                $html .= '<div class="updated fade">' . "\n";
847
-                $html .= '<p>' . __('The module order has been saved for this course.', 'woothemes-sensei') . '</p>' . "\n";
848
-                $html .= '</div>' . "\n";
846
+                $html .= '<div class="updated fade">'."\n";
847
+                $html .= '<p>'.__('The module order has been saved for this course.', 'woothemes-sensei').'</p>'."\n";
848
+                $html .= '</div>'."\n";
849 849
             }
850 850
         }
851 851
 
852 852
         $courses = Sensei()->course->get_all_courses();
853 853
 
854
-        $html .= '<form action="' . admin_url('edit.php') . '" method="get">' . "\n";
855
-        $html .= '<input type="hidden" name="post_type" value="course" />' . "\n";
856
-        $html .= '<input type="hidden" name="page" value="' . esc_attr($this->order_page_slug) . '" />' . "\n";
857
-        $html .= '<select id="module-order-course" name="course_id">' . "\n";
858
-        $html .= '<option value="">' . __('Select a course', 'woothemes-sensei') . '</option>' . "\n";
854
+        $html .= '<form action="'.admin_url('edit.php').'" method="get">'."\n";
855
+        $html .= '<input type="hidden" name="post_type" value="course" />'."\n";
856
+        $html .= '<input type="hidden" name="page" value="'.esc_attr($this->order_page_slug).'" />'."\n";
857
+        $html .= '<select id="module-order-course" name="course_id">'."\n";
858
+        $html .= '<option value="">'.__('Select a course', 'woothemes-sensei').'</option>'."\n";
859 859
 
860 860
         foreach ($courses as $course) {
861 861
             if (has_term('', $this->taxonomy, $course->ID)) {
@@ -863,30 +863,30 @@  discard block
 block discarded – undo
863 863
                 if (isset($_GET['course_id'])) {
864 864
                     $course_id = intval($_GET['course_id']);
865 865
                 }
866
-                $html .= '<option value="' . esc_attr(intval($course->ID)) . '" ' . selected($course->ID, $course_id, false) . '>' . get_the_title($course->ID) . '</option>' . "\n";
866
+                $html .= '<option value="'.esc_attr(intval($course->ID)).'" '.selected($course->ID, $course_id, false).'>'.get_the_title($course->ID).'</option>'."\n";
867 867
             }
868 868
         }
869 869
 
870
-        $html .= '</select>' . "\n";
871
-        $html .= '<input type="submit" class="button-primary module-order-select-course-submit" value="' . __('Select', 'woothemes-sensei') . '" />' . "\n";
872
-        $html .= '</form>' . "\n";
870
+        $html .= '</select>'."\n";
871
+        $html .= '<input type="submit" class="button-primary module-order-select-course-submit" value="'.__('Select', 'woothemes-sensei').'" />'."\n";
872
+        $html .= '</form>'."\n";
873 873
 
874 874
         if (isset($_GET['course_id'])) {
875 875
             $course_id = intval($_GET['course_id']);
876 876
             if ($course_id > 0) {
877 877
                 $modules = $this->get_course_modules($course_id);
878
-                $modules = $this->append_teacher_name_to_module( $modules, array( 'module' ), array() );
878
+                $modules = $this->append_teacher_name_to_module($modules, array('module'), array());
879 879
                 if ($modules) {
880 880
 
881 881
                     $order = $this->get_course_module_order($course_id);
882 882
 
883
-                    $order_string='';
883
+                    $order_string = '';
884 884
                     if ($order) {
885 885
                         $order_string = implode(',', $order);
886 886
                     }
887 887
 
888
-                    $html .= '<form id="editgrouping" method="post" action="" class="validate">' . "\n";
889
-                    $html .= '<ul class="sortable-module-list">' . "\n";
888
+                    $html .= '<form id="editgrouping" method="post" action="" class="validate">'."\n";
889
+                    $html .= '<ul class="sortable-module-list">'."\n";
890 890
                     $count = 0;
891 891
                     foreach ($modules as $module) {
892 892
                         $count++;
@@ -900,14 +900,14 @@  discard block
 block discarded – undo
900 900
                         if ($count % 2 != 0) {
901 901
                             $class .= ' alternate';
902 902
                         }
903
-                        $html .= '<li class="' . esc_attr($class) . '"><span rel="' . esc_attr($module->term_id) . '" style="width: 100%;"> ' . $module->name . '</span></li>' . "\n";
903
+                        $html .= '<li class="'.esc_attr($class).'"><span rel="'.esc_attr($module->term_id).'" style="width: 100%;"> '.$module->name.'</span></li>'."\n";
904 904
                     }
905
-                    $html .= '</ul>' . "\n";
905
+                    $html .= '</ul>'."\n";
906 906
 
907
-                    $html .= '<input type="hidden" name="module-order" value="' . $order_string . '" />' . "\n";
908
-                    $html .= '<input type="hidden" name="course_id" value="' . $course_id . '" />' . "\n";
909
-                    $html .= '<input type="submit" class="button-primary" value="' . __('Save module order', 'woothemes-sensei') . '" />' . "\n";
910
-                    $html .= '<a href="' . admin_url('post.php?post=' . $course_id . '&action=edit') . '" class="button-secondary">' . __('Edit course', 'woothemes-sensei') . '</a>' . "\n";
907
+                    $html .= '<input type="hidden" name="module-order" value="'.$order_string.'" />'."\n";
908
+                    $html .= '<input type="hidden" name="course_id" value="'.$course_id.'" />'."\n";
909
+                    $html .= '<input type="submit" class="button-primary" value="'.__('Save module order', 'woothemes-sensei').'" />'."\n";
910
+                    $html .= '<a href="'.admin_url('post.php?post='.$course_id.'&action=edit').'" class="button-secondary">'.__('Edit course', 'woothemes-sensei').'</a>'."\n";
911 911
                 }
912 912
             }
913 913
         }
@@ -944,7 +944,7 @@  discard block
 block discarded – undo
944 944
     {
945 945
         if ($column == 'module_order') {
946 946
             if (has_term('', $this->taxonomy, $course_id)) {
947
-                echo '<a class="button-secondary" href="' . admin_url('edit.php?post_type=course&page=module-order&course_id=' . urlencode(intval($course_id))) . '">' . __('Order modules', 'woothemes-sensei') . '</a>';
947
+                echo '<a class="button-secondary" href="'.admin_url('edit.php?post_type=course&page=module-order&course_id='.urlencode(intval($course_id))).'">'.__('Order modules', 'woothemes-sensei').'</a>';
948 948
             }
949 949
         }
950 950
     }
@@ -1036,7 +1036,7 @@  discard block
 block discarded – undo
1036 1036
                 $args['post_type'] = 'lesson';
1037 1037
                 $lessons = get_posts($args);
1038 1038
                 $total_lessons = count($lessons);
1039
-                $column_data = '<a href="' . admin_url('edit.php?module=' . urlencode($module->slug) . '&post_type=lesson') . '">' . intval($total_lessons) . '</a>';
1039
+                $column_data = '<a href="'.admin_url('edit.php?module='.urlencode($module->slug).'&post_type=lesson').'">'.intval($total_lessons).'</a>';
1040 1040
                 break;
1041 1041
         }
1042 1042
 
@@ -1054,7 +1054,7 @@  discard block
 block discarded – undo
1054 1054
     public function analysis_overview_column_title($columns)
1055 1055
     {
1056 1056
 
1057
-        if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) {
1057
+        if (isset($_GET['view']) && 'lessons' == $_GET['view']) {
1058 1058
             $new_columns = array();
1059 1059
             if (is_array($columns) && 0 < count($columns)) {
1060 1060
                 foreach ($columns as $column => $title) {
@@ -1082,15 +1082,15 @@  discard block
 block discarded – undo
1082 1082
      * @param  WP_Post $lesson
1083 1083
      * @return array              Updated column data
1084 1084
      */
1085
-    public function analysis_overview_column_data($columns, $lesson )
1085
+    public function analysis_overview_column_data($columns, $lesson)
1086 1086
     {
1087 1087
 
1088
-        if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) {
1088
+        if (isset($_GET['view']) && 'lessons' == $_GET['view']) {
1089 1089
             $lesson_module = '';
1090 1090
             $lesson_module_list = wp_get_post_terms($lesson->ID, $this->taxonomy);
1091 1091
             if (is_array($lesson_module_list) && count($lesson_module_list) > 0) {
1092 1092
                 foreach ($lesson_module_list as $single_module) {
1093
-                    $lesson_module = '<a href="' . esc_url(admin_url('edit-tags.php?action=edit&taxonomy=' . urlencode($this->taxonomy) . '&tag_ID=' . urlencode($single_module->term_id))) . '">' . $single_module->name . '</a>';
1093
+                    $lesson_module = '<a href="'.esc_url(admin_url('edit-tags.php?action=edit&taxonomy='.urlencode($this->taxonomy).'&tag_ID='.urlencode($single_module->term_id))).'">'.$single_module->name.'</a>';
1094 1094
                     break;
1095 1095
                 }
1096 1096
             }
@@ -1111,7 +1111,7 @@  discard block
 block discarded – undo
1111 1111
      */
1112 1112
     public function analysis_course_column_title($columns)
1113 1113
     {
1114
-        if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) {
1114
+        if (isset($_GET['view']) && 'lessons' == $_GET['view']) {
1115 1115
             $columns['lesson_module'] = __('Module', 'woothemes-sensei');
1116 1116
         }
1117 1117
         return $columns;
@@ -1126,15 +1126,15 @@  discard block
 block discarded – undo
1126 1126
      * @param  WP_Post $lesson
1127 1127
      * @return array              Updated columns data
1128 1128
      */
1129
-    public function analysis_course_column_data($columns, $lesson )
1129
+    public function analysis_course_column_data($columns, $lesson)
1130 1130
     {
1131 1131
 
1132
-        if ( isset( $_GET['course_id'] ) ) {
1132
+        if (isset($_GET['course_id'])) {
1133 1133
             $lesson_module = '';
1134 1134
             $lesson_module_list = wp_get_post_terms($lesson->ID, $this->taxonomy);
1135 1135
             if (is_array($lesson_module_list) && count($lesson_module_list) > 0) {
1136 1136
                 foreach ($lesson_module_list as $single_module) {
1137
-                    $lesson_module = '<a href="' . esc_url(admin_url('edit-tags.php?action=edit&taxonomy=' . urlencode($this->taxonomy) . '&tag_ID=' . urlencode($single_module->term_id))) . '">' . $single_module->name . '</a>';
1137
+                    $lesson_module = '<a href="'.esc_url(admin_url('edit-tags.php?action=edit&taxonomy='.urlencode($this->taxonomy).'&tag_ID='.urlencode($single_module->term_id))).'">'.$single_module->name.'</a>';
1138 1138
                     break;
1139 1139
                 }
1140 1140
             }
@@ -1161,7 +1161,7 @@  discard block
 block discarded – undo
1161 1161
     public function get_lesson_module($lesson_id = 0)
1162 1162
     {
1163 1163
         $lesson_id = intval($lesson_id);
1164
-        if ( ! ( intval( $lesson_id > 0) ) ) {
1164
+        if ( ! (intval($lesson_id > 0))) {
1165 1165
             return false;
1166 1166
         }
1167 1167
 
@@ -1169,13 +1169,13 @@  discard block
 block discarded – undo
1169 1169
         $modules = wp_get_post_terms($lesson_id, $this->taxonomy);
1170 1170
 
1171 1171
         //check if error returned
1172
-        if( empty( $modules ) || isset( $modules['errors']  ) ){
1172
+        if (empty($modules) || isset($modules['errors'])) {
1173 1173
             return false;
1174 1174
         }
1175 1175
 
1176 1176
        // get the last item in the array there should be only be 1 really.
1177 1177
        // this method works for all php versions.
1178
-       foreach( $modules as $module ){
1178
+       foreach ($modules as $module) {
1179 1179
            break;
1180 1180
        }
1181 1181
 
@@ -1188,7 +1188,7 @@  discard block
 block discarded – undo
1188 1188
         if (isset($course_id) && 0 < $course_id) {
1189 1189
 
1190 1190
             // the course should contain the same module taxonomy term for this to be valid
1191
-            if( ! has_term( $module, $this->taxonomy, $course_id)){
1191
+            if ( ! has_term($module, $this->taxonomy, $course_id)) {
1192 1192
                 return false;
1193 1193
             }
1194 1194
 
@@ -1262,8 +1262,8 @@  discard block
 block discarded – undo
1262 1262
     {
1263 1263
 
1264 1264
 
1265
-        wp_register_style($this->taxonomy . '-frontend', esc_url($this->assets_url) . 'css/modules-frontend.css', Sensei()->version );
1266
-        wp_enqueue_style($this->taxonomy . '-frontend');
1265
+        wp_register_style($this->taxonomy.'-frontend', esc_url($this->assets_url).'css/modules-frontend.css', Sensei()->version);
1266
+        wp_enqueue_style($this->taxonomy.'-frontend');
1267 1267
     }
1268 1268
 
1269 1269
     /**
@@ -1273,37 +1273,37 @@  discard block
 block discarded – undo
1273 1273
      *
1274 1274
      * @return void
1275 1275
      */
1276
-    public function admin_enqueue_scripts( $hook ) {
1276
+    public function admin_enqueue_scripts($hook) {
1277 1277
 
1278 1278
         /**
1279 1279
          * Filter the page hooks where modules admin script can be loaded on.
1280 1280
          *
1281 1281
          * @param array $white_listed_pages
1282 1282
          */
1283
-        $script_on_pages_white_list = apply_filters( 'sensei_module_admin_script_page_white_lists', array(
1283
+        $script_on_pages_white_list = apply_filters('sensei_module_admin_script_page_white_lists', array(
1284 1284
             'edit-tags.php',
1285 1285
             'course_page_module-order',
1286 1286
             'post-new.php',
1287 1287
             'post.php'
1288
-        ) );
1288
+        ));
1289 1289
 
1290
-        if ( ! in_array( $hook, $script_on_pages_white_list ) ) {
1290
+        if ( ! in_array($hook, $script_on_pages_white_list)) {
1291 1291
             return;
1292 1292
         }
1293 1293
 
1294
-        $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
1294
+        $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
1295 1295
 
1296
-        wp_enqueue_script( 'sensei-chosen', Sensei()->plugin_url . 'assets/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), Sensei()->version , true);
1297
-        wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery' . $suffix . '.js', array( 'jquery', 'sensei-chosen' ), Sensei()->version , true );
1298
-        wp_enqueue_script( $this->taxonomy . '-admin', esc_url( $this->assets_url ) . 'js/modules-admin' . $suffix . '.js', array( 'jquery', 'sensei-chosen', 'sensei-chosen-ajax', 'jquery-ui-sortable', 'select2' ), Sensei()->version, true );
1296
+        wp_enqueue_script('sensei-chosen', Sensei()->plugin_url.'assets/chosen/chosen.jquery'.$suffix.'.js', array('jquery'), Sensei()->version, true);
1297
+        wp_enqueue_script('sensei-chosen-ajax', Sensei()->plugin_url.'assets/chosen/ajax-chosen.jquery'.$suffix.'.js', array('jquery', 'sensei-chosen'), Sensei()->version, true);
1298
+        wp_enqueue_script($this->taxonomy.'-admin', esc_url($this->assets_url).'js/modules-admin'.$suffix.'.js', array('jquery', 'sensei-chosen', 'sensei-chosen-ajax', 'jquery-ui-sortable', 'select2'), Sensei()->version, true);
1299 1299
 
1300 1300
         // localized module data
1301 1301
         $localize_modulesAdmin = array(
1302
-            'search_courses_nonce' => wp_create_nonce( 'search-courses' ),
1303
-            'selectPlaceholder'    => __( 'Search for courses', 'woothemes-sensei' )
1302
+            'search_courses_nonce' => wp_create_nonce('search-courses'),
1303
+            'selectPlaceholder'    => __('Search for courses', 'woothemes-sensei')
1304 1304
         );
1305 1305
 
1306
-        wp_localize_script( $this->taxonomy . '-admin' ,'modulesAdmin', $localize_modulesAdmin );
1306
+        wp_localize_script($this->taxonomy.'-admin', 'modulesAdmin', $localize_modulesAdmin);
1307 1307
     }
1308 1308
 
1309 1309
     /**
@@ -1316,8 +1316,8 @@  discard block
 block discarded – undo
1316 1316
     public function admin_enqueue_styles() {
1317 1317
 
1318 1318
 
1319
-        wp_register_style($this->taxonomy . '-sortable', esc_url($this->assets_url) . 'css/modules-admin.css','',Sensei()->version );
1320
-        wp_enqueue_style($this->taxonomy . '-sortable');
1319
+        wp_register_style($this->taxonomy.'-sortable', esc_url($this->assets_url).'css/modules-admin.css', '', Sensei()->version);
1320
+        wp_enqueue_style($this->taxonomy.'-sortable');
1321 1321
 
1322 1322
     }
1323 1323
 
@@ -1331,9 +1331,9 @@  discard block
 block discarded – undo
1331 1331
      */
1332 1332
     public function course_modules_title( ) {
1333 1333
 
1334
-       if( sensei_module_has_lessons() ){
1334
+       if (sensei_module_has_lessons()) {
1335 1335
 
1336
-            echo '<header><h2>' . __('Modules', 'woothemes-sensei') . '</h2></header>';
1336
+            echo '<header><h2>'.__('Modules', 'woothemes-sensei').'</h2></header>';
1337 1337
 
1338 1338
         }
1339 1339
 
@@ -1346,18 +1346,18 @@  discard block
 block discarded – undo
1346 1346
      * @since 1.8.0
1347 1347
      * @return void
1348 1348
      */
1349
-    public function load_course_module_content_template(){
1349
+    public function load_course_module_content_template() {
1350 1350
 
1351 1351
         // load backwards compatible template name if it exists in the users theme
1352
-        $located_template= locate_template( Sensei()->template_url . 'single-course/course-modules.php' );
1353
-        if( $located_template ){
1352
+        $located_template = locate_template(Sensei()->template_url.'single-course/course-modules.php');
1353
+        if ($located_template) {
1354 1354
 
1355
-            Sensei_Templates::get_template( 'single-course/course-modules.php' );
1355
+            Sensei_Templates::get_template('single-course/course-modules.php');
1356 1356
             return;
1357 1357
 
1358 1358
         }
1359 1359
 
1360
-        Sensei_Templates::get_template( 'single-course/modules.php' );
1360
+        Sensei_Templates::get_template('single-course/modules.php');
1361 1361
 
1362 1362
     } // end course_module_content
1363 1363
 
@@ -1370,15 +1370,15 @@  discard block
 block discarded – undo
1370 1370
      * @param $term_id
1371 1371
      * @return array $lessons
1372 1372
      */
1373
-    public function get_lessons( $course_id , $term_id ){
1373
+    public function get_lessons($course_id, $term_id) {
1374 1374
 
1375
-        $lesson_query = $this->get_lessons_query( $course_id, $term_id );
1375
+        $lesson_query = $this->get_lessons_query($course_id, $term_id);
1376 1376
 
1377
-        if( isset( $lesson_query->posts ) ){
1377
+        if (isset($lesson_query->posts)) {
1378 1378
 
1379 1379
             return $lesson_query->posts;
1380 1380
 
1381
-        }else{
1381
+        } else {
1382 1382
 
1383 1383
             return array();
1384 1384
 
@@ -1395,9 +1395,9 @@  discard block
 block discarded – undo
1395 1395
      * @param $term_id
1396 1396
      * @return WP_Query $lessons_query
1397 1397
      */
1398
-    public function get_lessons_query( $course_id , $term_id ){
1398
+    public function get_lessons_query($course_id, $term_id) {
1399 1399
 
1400
-        if( empty( $term_id ) || empty( $course_id ) ){
1400
+        if (empty($term_id) || empty($course_id)) {
1401 1401
 
1402 1402
             return array();
1403 1403
 
@@ -1418,7 +1418,7 @@  discard block
 block discarded – undo
1418 1418
                 array(
1419 1419
                     'taxonomy' => 'module',
1420 1420
                     'field' => 'id',
1421
-                    'terms' => intval( $term_id )
1421
+                    'terms' => intval($term_id)
1422 1422
                 )
1423 1423
             ),
1424 1424
             'orderby' => 'menu_order',
@@ -1426,12 +1426,12 @@  discard block
 block discarded – undo
1426 1426
             'suppress_filters' => 0
1427 1427
         );
1428 1428
 
1429
-        if (version_compare( Sensei()->version, '1.6.0', '>=')) {
1430
-            $args['meta_key'] = '_order_module_' . intval( $term_id );
1429
+        if (version_compare(Sensei()->version, '1.6.0', '>=')) {
1430
+            $args['meta_key'] = '_order_module_'.intval($term_id);
1431 1431
             $args['orderby'] = 'meta_value_num date';
1432 1432
         }
1433 1433
 
1434
-        $lessons_query = new WP_Query( $args );
1434
+        $lessons_query = new WP_Query($args);
1435 1435
 
1436 1436
         return $lessons_query;
1437 1437
 
@@ -1446,37 +1446,37 @@  discard block
 block discarded – undo
1446 1446
      *
1447 1447
      * @return array $non_module_lessons
1448 1448
      */
1449
-    public function get_none_module_lessons( $course_id ){
1449
+    public function get_none_module_lessons($course_id) {
1450 1450
 
1451 1451
         $non_module_lessons = array();
1452 1452
 
1453 1453
         //exit if there is no course id passed in
1454
-        if( empty( $course_id ) || 'course' != get_post_type( $course_id ) ) {
1454
+        if (empty($course_id) || 'course' != get_post_type($course_id)) {
1455 1455
 
1456 1456
             return $non_module_lessons;
1457 1457
         }
1458 1458
 
1459 1459
         //save some time and check if we already have the saved
1460
-        if( get_transient( 'sensei_'. $course_id .'_none_module_lessons') ){
1460
+        if (get_transient('sensei_'.$course_id.'_none_module_lessons')) {
1461 1461
 
1462
-            return get_transient( 'sensei_'. $course_id .'_none_module_lessons');
1462
+            return get_transient('sensei_'.$course_id.'_none_module_lessons');
1463 1463
 
1464 1464
         }
1465 1465
 
1466 1466
         // create terms array which must be excluded from other arrays
1467
-        $course_modules = $this->get_course_modules( $course_id );
1467
+        $course_modules = $this->get_course_modules($course_id);
1468 1468
 
1469 1469
         //exit if there are no module on this course
1470
-        if( empty( $course_modules ) || ! is_array( $course_modules ) ){
1470
+        if (empty($course_modules) || ! is_array($course_modules)) {
1471 1471
 
1472
-            return  Sensei()->course->course_lessons( $course_id );
1472
+            return  Sensei()->course->course_lessons($course_id);
1473 1473
 
1474 1474
         }
1475 1475
 
1476 1476
         $terms = array();
1477
-        foreach( $course_modules as $module ){
1477
+        foreach ($course_modules as $module) {
1478 1478
 
1479
-            array_push( $terms ,  $module->term_id );
1479
+            array_push($terms, $module->term_id);
1480 1480
 
1481 1481
         }
1482 1482
 
@@ -1487,7 +1487,7 @@  discard block
 block discarded – undo
1487 1487
             'meta_query' => array(
1488 1488
                 array(
1489 1489
                     'key' => '_lesson_course',
1490
-                    'value' => intval( $course_id ),
1490
+                    'value' => intval($course_id),
1491 1491
                     'compare' => '='
1492 1492
                 )
1493 1493
             ),
@@ -1504,11 +1504,11 @@  discard block
 block discarded – undo
1504 1504
             'suppress_filters' => 0
1505 1505
         );
1506 1506
 
1507
-        $wp_lessons_query = new WP_Query( $args );
1507
+        $wp_lessons_query = new WP_Query($args);
1508 1508
 
1509
-        if( isset( $wp_lessons_query->posts) && count( $wp_lessons_query->posts ) > 0  ){
1509
+        if (isset($wp_lessons_query->posts) && count($wp_lessons_query->posts) > 0) {
1510 1510
             $non_module_lessons = $wp_lessons_query->get_posts();
1511
-            set_transient( 'sensei_'. $course_id .'_none_module_lessons', $non_module_lessons, 10 * DAY_IN_SECONDS );
1511
+            set_transient('sensei_'.$course_id.'_none_module_lessons', $non_module_lessons, 10 * DAY_IN_SECONDS);
1512 1512
         }
1513 1513
 
1514 1514
         return $non_module_lessons;
@@ -1519,7 +1519,7 @@  discard block
 block discarded – undo
1519 1519
      *
1520 1520
      * @since 1.8.0
1521 1521
      */
1522
-    public function setup_modules_taxonomy(){
1522
+    public function setup_modules_taxonomy() {
1523 1523
 
1524 1524
         $labels = array(
1525 1525
             'name' => __('Modules', 'woothemes-sensei'),
@@ -1556,11 +1556,11 @@  discard block
 block discarded – undo
1556 1556
             'show_in_nav_menus' => false,
1557 1557
             'show_in_quick_edit' => false,
1558 1558
             'show_ui' => true,
1559
-            'rewrite' => array('slug' => $modules_rewrite_slug ),
1559
+            'rewrite' => array('slug' => $modules_rewrite_slug),
1560 1560
             'labels' => $labels
1561 1561
         );
1562 1562
 
1563
-        register_taxonomy( 'module' , array('course', 'lesson'), $args);
1563
+        register_taxonomy('module', array('course', 'lesson'), $args);
1564 1564
 
1565 1565
     }// end setup_modules_taxonomy
1566 1566
 
@@ -1572,12 +1572,12 @@  discard block
 block discarded – undo
1572 1572
      * @since 1.8.0
1573 1573
      * @return void
1574 1574
      */
1575
-    function redirect_to_lesson_module_taxonomy_to_course( ){
1575
+    function redirect_to_lesson_module_taxonomy_to_course( ) {
1576 1576
 
1577
-        global $typenow , $taxnow;
1577
+        global $typenow, $taxnow;
1578 1578
 
1579
-        if( 'lesson'== $typenow && 'module'==$taxnow ){
1580
-            wp_safe_redirect( esc_url_raw( 'edit-tags.php?taxonomy=module&post_type=course'  ) );
1579
+        if ('lesson' == $typenow && 'module' == $taxnow) {
1580
+            wp_safe_redirect(esc_url_raw('edit-tags.php?taxonomy=module&post_type=course'));
1581 1581
         }
1582 1582
 
1583 1583
     }// end redirect to course taxonomy
@@ -1590,18 +1590,18 @@  discard block
 block discarded – undo
1590 1590
      * @since 1.8.0
1591 1591
      * @return void
1592 1592
      */
1593
-    public function remove_lessons_menu_model_taxonomy(){
1593
+    public function remove_lessons_menu_model_taxonomy() {
1594 1594
         global $submenu;
1595 1595
 
1596
-        if( ! isset( $submenu['edit.php?post_type=lesson'] ) || !is_array( $submenu['edit.php?post_type=lesson'] ) ){
1596
+        if ( ! isset($submenu['edit.php?post_type=lesson']) || ! is_array($submenu['edit.php?post_type=lesson'])) {
1597 1597
             return; // exit
1598 1598
         }
1599 1599
 
1600 1600
         $lesson_main_menu = $submenu['edit.php?post_type=lesson'];
1601
-        foreach( $lesson_main_menu as $index => $sub_item ){
1601
+        foreach ($lesson_main_menu as $index => $sub_item) {
1602 1602
 
1603
-            if( 'edit-tags.php?taxonomy=module&amp;post_type=lesson' == $sub_item[2] ){
1604
-                unset( $submenu['edit.php?post_type=lesson'][ $index ]);
1603
+            if ('edit-tags.php?taxonomy=module&amp;post_type=lesson' == $sub_item[2]) {
1604
+                unset($submenu['edit.php?post_type=lesson'][$index]);
1605 1605
             }
1606 1606
         }
1607 1607
 
@@ -1615,18 +1615,18 @@  discard block
 block discarded – undo
1615 1615
      * @since 1.8.0
1616 1616
      * @return void
1617 1617
      */
1618
-    public function remove_courses_menu_model_taxonomy(){
1618
+    public function remove_courses_menu_model_taxonomy() {
1619 1619
         global $submenu;
1620 1620
 
1621
-        if( ! isset( $submenu['edit.php?post_type=course'] ) || !is_array( $submenu['edit.php?post_type=course'] ) ){
1621
+        if ( ! isset($submenu['edit.php?post_type=course']) || ! is_array($submenu['edit.php?post_type=course'])) {
1622 1622
             return; // exit
1623 1623
         }
1624 1624
 
1625 1625
         $course_main_menu = $submenu['edit.php?post_type=course'];
1626
-        foreach( $course_main_menu as $index => $sub_item ){
1626
+        foreach ($course_main_menu as $index => $sub_item) {
1627 1627
 
1628
-            if( 'edit-tags.php?taxonomy=module&amp;post_type=course' == $sub_item[2] ){
1629
-                unset( $submenu['edit.php?post_type=course'][ $index ]);
1628
+            if ('edit-tags.php?taxonomy=module&amp;post_type=course' == $sub_item[2]) {
1629
+                unset($submenu['edit.php?post_type=course'][$index]);
1630 1630
             }
1631 1631
         }
1632 1632
 
@@ -1642,12 +1642,12 @@  discard block
 block discarded – undo
1642 1642
      * @param string $term_name
1643 1643
      * @return array $owners { type WP_User }. Empty array if none if found.
1644 1644
      */
1645
-    public static function get_term_authors( $term_name ){
1645
+    public static function get_term_authors($term_name) {
1646 1646
 
1647
-        $terms = get_terms( array( 'module') , array( 'name__like'=>$term_name, 'hide_empty' => false )  );
1647
+        $terms = get_terms(array('module'), array('name__like'=>$term_name, 'hide_empty' => false));
1648 1648
 
1649 1649
         $owners = array();
1650
-        if( empty( $terms ) ){
1650
+        if (empty($terms)) {
1651 1651
 
1652 1652
             return $owners;
1653 1653
 
@@ -1657,11 +1657,11 @@  discard block
 block discarded – undo
1657 1657
 
1658 1658
 
1659 1659
         //if there are more handle them appropriately and get the ones we really need that matches the desired name exactly
1660
-        foreach( $terms as $term){
1661
-            if( $term->name == $term_name ){
1660
+        foreach ($terms as $term) {
1661
+            if ($term->name == $term_name) {
1662 1662
 
1663 1663
                 // look for the author in the slug
1664
-                $owners[] = Sensei_Core_Modules::get_term_author( $term->slug  );
1664
+                $owners[] = Sensei_Core_Modules::get_term_author($term->slug);
1665 1665
 
1666 1666
             }// end if term name
1667 1667
 
@@ -1682,30 +1682,30 @@  discard block
 block discarded – undo
1682 1682
      * @param $slug
1683 1683
      * @return WP_User $author if no author is found or invalid term is passed the admin user will be returned.
1684 1684
      */
1685
-    public static function get_term_author( $slug='' ){
1685
+    public static function get_term_author($slug = '') {
1686 1686
 
1687
-        $term_owner = get_user_by( 'email', get_bloginfo( 'admin_email' ) );
1687
+        $term_owner = get_user_by('email', get_bloginfo('admin_email'));
1688 1688
 
1689
-        if( empty( $slug ) ){
1689
+        if (empty($slug)) {
1690 1690
 
1691 1691
             return $term_owner;
1692 1692
 
1693 1693
         }
1694 1694
 
1695 1695
         // look for the author in the slug
1696
-        $slug_parts = explode( '-', $slug );
1696
+        $slug_parts = explode('-', $slug);
1697 1697
 
1698
-        if( count( $slug_parts ) > 1 ){
1698
+        if (count($slug_parts) > 1) {
1699 1699
 
1700 1700
             // get the user data
1701 1701
             $possible_user_id = $slug_parts[0];
1702
-            $author = get_userdata( $possible_user_id );
1702
+            $author = get_userdata($possible_user_id);
1703 1703
 
1704 1704
             // if the user doesnt exist for the first part of the slug
1705 1705
             // then this slug was also created by admin
1706
-            if( is_a( $author, 'WP_User' ) ){
1706
+            if (is_a($author, 'WP_User')) {
1707 1707
 
1708
-                $term_owner =  $author;
1708
+                $term_owner = $author;
1709 1709
 
1710 1710
             }
1711 1711
         }
@@ -1722,48 +1722,48 @@  discard block
 block discarded – undo
1722 1722
      *
1723 1723
      * @param WP_Post $post Post object.
1724 1724
      */
1725
-    public function course_module_metabox( $post ) {
1725
+    public function course_module_metabox($post) {
1726 1726
 
1727 1727
         $tax_name = 'module';
1728
-        $taxonomy = get_taxonomy( 'module' );
1728
+        $taxonomy = get_taxonomy('module');
1729 1729
 
1730 1730
         ?>
1731 1731
         <div id="taxonomy-<?php echo $tax_name; ?>" class="categorydiv">
1732 1732
             <ul id="<?php echo $tax_name; ?>-tabs" class="category-tabs">
1733 1733
                 <li class="tabs"><a href="#<?php echo $tax_name; ?>-all"><?php echo $taxonomy->labels->all_items; ?></a></li>
1734
-                <li class="hide-if-no-js"><a href="#<?php echo $tax_name; ?>-pop"><?php _e( 'Most Used' ); ?></a></li>
1734
+                <li class="hide-if-no-js"><a href="#<?php echo $tax_name; ?>-pop"><?php _e('Most Used'); ?></a></li>
1735 1735
             </ul>
1736 1736
 
1737 1737
             <div id="<?php echo $tax_name; ?>-pop" class="tabs-panel" style="display: none;">
1738 1738
                 <ul id="<?php echo $tax_name; ?>checklist-pop" class="categorychecklist form-no-clear" >
1739
-                    <?php $popular_ids = wp_popular_terms_checklist( $tax_name ); ?>
1739
+                    <?php $popular_ids = wp_popular_terms_checklist($tax_name); ?>
1740 1740
                 </ul>
1741 1741
             </div>
1742 1742
 
1743 1743
             <div id="<?php echo $tax_name; ?>-all" class="tabs-panel">
1744 1744
                 <?php
1745
-                $name = ( $tax_name == 'category' ) ? 'post_category' : 'tax_input[' . $tax_name . ']';
1745
+                $name = ($tax_name == 'category') ? 'post_category' : 'tax_input['.$tax_name.']';
1746 1746
                 echo "<input type='hidden' name='{$name}[]' value='0' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks.
1747 1747
                 ?>
1748 1748
                 <ul id="<?php echo $tax_name; ?>checklist" data-wp-lists="list:<?php echo $tax_name; ?>" class="categorychecklist form-no-clear">
1749
-                    <?php wp_terms_checklist( $post->ID, array( 'taxonomy'=>$tax_name , 'popular_cats' => $popular_ids ) ); ?>
1749
+                    <?php wp_terms_checklist($post->ID, array('taxonomy'=>$tax_name, 'popular_cats' => $popular_ids)); ?>
1750 1750
                 </ul>
1751 1751
             </div>
1752
-            <?php if ( current_user_can( $taxonomy->cap->edit_terms ) ) : ?>
1752
+            <?php if (current_user_can($taxonomy->cap->edit_terms)) : ?>
1753 1753
                 <div id="<?php echo $tax_name; ?>-adder" class="wp-hidden-children">
1754 1754
                     <h4>
1755 1755
                         <a id="sensei-<?php echo $tax_name; ?>-add-toggle" href="#<?php echo $tax_name; ?>-add" class="hide-if-no-js">
1756 1756
                             <?php
1757 1757
                             /* translators: %s: add new taxonomy label */
1758
-                            printf( __( '+ %s' ), $taxonomy->labels->add_new_item );
1758
+                            printf(__('+ %s'), $taxonomy->labels->add_new_item);
1759 1759
                             ?>
1760 1760
                         </a>
1761 1761
                     </h4>
1762 1762
                     <p id="sensei-<?php echo $tax_name; ?>-add" class="category-add wp-hidden-child">
1763 1763
                         <label class="screen-reader-text" for="new<?php echo $tax_name; ?>"><?php echo $taxonomy->labels->add_new_item; ?></label>
1764
-                        <input type="text" name="new<?php echo $tax_name; ?>" id="new<?php echo $tax_name; ?>" class="form-required form-input-tip" value="<?php echo esc_attr( $taxonomy->labels->new_item_name ); ?>" aria-required="true"/>
1765
-                        <a class="button" id="sensei-<?php echo $tax_name; ?>-add-submit" class="button category-add-submit"><?php echo esc_attr( $taxonomy->labels->add_new_item ); ?></a>
1766
-                        <?php wp_nonce_field( '_ajax_nonce-add-' . $tax_name, 'add_module_nonce' ); ?>
1764
+                        <input type="text" name="new<?php echo $tax_name; ?>" id="new<?php echo $tax_name; ?>" class="form-required form-input-tip" value="<?php echo esc_attr($taxonomy->labels->new_item_name); ?>" aria-required="true"/>
1765
+                        <a class="button" id="sensei-<?php echo $tax_name; ?>-add-submit" class="button category-add-submit"><?php echo esc_attr($taxonomy->labels->add_new_item); ?></a>
1766
+                        <?php wp_nonce_field('_ajax_nonce-add-'.$tax_name, 'add_module_nonce'); ?>
1767 1767
                         <span id="<?php echo $tax_name; ?>-ajax-response"></span>
1768 1768
                     </p>
1769 1769
                 </div>
@@ -1783,55 +1783,55 @@  discard block
 block discarded – undo
1783 1783
     public static function add_new_module_term( ) {
1784 1784
 
1785 1785
 
1786
-        if( ! isset( $_POST[ 'security' ] ) || ! wp_verify_nonce( $_POST[ 'security' ], '_ajax_nonce-add-module'  ) ){
1787
-            wp_send_json_error( array('error'=> 'wrong security nonce') );
1786
+        if ( ! isset($_POST['security']) || ! wp_verify_nonce($_POST['security'], '_ajax_nonce-add-module')) {
1787
+            wp_send_json_error(array('error'=> 'wrong security nonce'));
1788 1788
         }
1789 1789
 
1790 1790
         // get the term an create the new term storing infomration
1791
-        $term_name = sanitize_text_field( $_POST['newTerm'] );
1791
+        $term_name = sanitize_text_field($_POST['newTerm']);
1792 1792
 
1793
-        if( current_user_can('manage_options' ) ) {
1793
+        if (current_user_can('manage_options')) {
1794 1794
 
1795
-            $term_slug = str_ireplace(' ', '-', trim( $term_name ) );
1795
+            $term_slug = str_ireplace(' ', '-', trim($term_name));
1796 1796
 
1797 1797
         } else {
1798 1798
 
1799
-            $term_slug =  get_current_user_id() . '-' . str_ireplace(' ', '-', trim( $term_name ) );
1799
+            $term_slug = get_current_user_id().'-'.str_ireplace(' ', '-', trim($term_name));
1800 1800
 
1801 1801
         }
1802 1802
 
1803
-        $course_id = sanitize_text_field( $_POST['course_id'] );
1803
+        $course_id = sanitize_text_field($_POST['course_id']);
1804 1804
 
1805 1805
         // save the term
1806
-        $slug = wp_insert_term( $term_name,'module', array('slug'=> $term_slug)  );
1806
+        $slug = wp_insert_term($term_name, 'module', array('slug'=> $term_slug));
1807 1807
 
1808 1808
         // send error for all errors except term exits
1809
-        if( is_wp_error( $slug ) ){
1809
+        if (is_wp_error($slug)) {
1810 1810
 
1811 1811
             // prepare for possible term name and id to be passed down if term exists
1812 1812
             $term_data = array();
1813 1813
 
1814 1814
             // if term exists also send back the term name and id
1815
-            if( isset( $slug->errors['term_exists'] ) ){
1815
+            if (isset($slug->errors['term_exists'])) {
1816 1816
 
1817
-                $term = get_term_by( 'slug', $term_slug, 'module');
1817
+                $term = get_term_by('slug', $term_slug, 'module');
1818 1818
                 $term_data['name'] = $term_name;
1819 1819
                 $term_data['id'] = $term->term_id;
1820 1820
 
1821 1821
                 // set the object terms
1822
-                wp_set_object_terms( $course_id, $term->term_id, 'module', true );
1822
+                wp_set_object_terms($course_id, $term->term_id, 'module', true);
1823 1823
             }
1824 1824
 
1825
-            wp_send_json_error(array( 'errors'=>$slug->errors , 'term'=> $term_data ) );
1825
+            wp_send_json_error(array('errors'=>$slug->errors, 'term'=> $term_data));
1826 1826
 
1827 1827
         }
1828 1828
 
1829 1829
         //make sure the new term is checked for this course
1830 1830
 
1831
-        wp_set_object_terms( $course_id, $slug['term_id'], 'module', true );
1831
+        wp_set_object_terms($course_id, $slug['term_id'], 'module', true);
1832 1832
 
1833 1833
         // Handle request then generate response using WP_Ajax_Response
1834
-        wp_send_json_success( array( 'termId' => $slug['term_id'], 'termName' => $term_name ) );
1834
+        wp_send_json_success(array('termId' => $slug['term_id'], 'termName' => $term_name));
1835 1835
 
1836 1836
     }
1837 1837
 
@@ -1843,26 +1843,26 @@  discard block
 block discarded – undo
1843 1843
      *
1844 1844
      * @since 1.8.0
1845 1845
      */
1846
-    public function filter_module_terms( $terms, $taxonomies, $args ){
1846
+    public function filter_module_terms($terms, $taxonomies, $args) {
1847 1847
 
1848 1848
         //dont limit for admins and other taxonomies. This should also only apply to admin
1849
-        if( current_user_can( 'manage_options' ) || !in_array( 'module', $taxonomies ) || ! is_admin()  ){
1849
+        if (current_user_can('manage_options') || ! in_array('module', $taxonomies) || ! is_admin()) {
1850 1850
             return $terms;
1851 1851
         }
1852 1852
 
1853 1853
         // avoid infinite call loop
1854
-        remove_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
1854
+        remove_filter('get_terms', array($this, 'filter_module_terms'), 20, 3);
1855 1855
 
1856 1856
         // in certain cases the array is passed in as reference to the parent term_id => parent_id
1857
-        if( isset( $args['fields'] ) && 'id=>parent' == $args['fields'] ){
1857
+        if (isset($args['fields']) && 'id=>parent' == $args['fields']) {
1858 1858
             // change only scrub the terms ids form the array keys
1859
-            $terms = array_keys( $terms );
1859
+            $terms = array_keys($terms);
1860 1860
         }
1861 1861
 
1862
-        $teachers_terms =  $this->filter_terms_by_owner( $terms, get_current_user_id() );
1862
+        $teachers_terms = $this->filter_terms_by_owner($terms, get_current_user_id());
1863 1863
 
1864 1864
         // add filter again as removed above
1865
-        add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
1865
+        add_filter('get_terms', array($this, 'filter_module_terms'), 20, 3);
1866 1866
 
1867 1867
         return $teachers_terms;
1868 1868
     }// end filter_module_terms
@@ -1875,25 +1875,25 @@  discard block
 block discarded – undo
1875 1875
      *
1876 1876
      * @since 1.8.0
1877 1877
      */
1878
-    public function filter_course_selected_terms( $terms, $course_ids_array, $taxonomies ){
1878
+    public function filter_course_selected_terms($terms, $course_ids_array, $taxonomies) {
1879 1879
 
1880 1880
         //dont limit for admins and other taxonomies. This should also only apply to admin
1881
-        if( current_user_can( 'manage_options' ) || ! is_admin() || empty( $terms )
1881
+        if (current_user_can('manage_options') || ! is_admin() || empty($terms)
1882 1882
             // only apply this to module only taxonomy queries so 1 taxonomy only:
1883
-            ||  count( $taxonomies ) > 1 || !in_array( 'module', $taxonomies )  ){
1883
+            ||  count($taxonomies) > 1 || ! in_array('module', $taxonomies)) {
1884 1884
             return $terms;
1885 1885
         }
1886 1886
 
1887
-        $term_objects = $this->filter_terms_by_owner( $terms, get_current_user_id() );
1887
+        $term_objects = $this->filter_terms_by_owner($terms, get_current_user_id());
1888 1888
 
1889 1889
         // if term objects were passed in send back objects
1890 1890
         // if term id were passed in send that back
1891
-        if( is_object( $terms[0] ) ){
1891
+        if (is_object($terms[0])) {
1892 1892
             return $term_objects;
1893 1893
         }
1894 1894
 
1895 1895
         $terms = array();
1896
-        foreach( $term_objects as $term_object ){
1896
+        foreach ($term_objects as $term_object) {
1897 1897
             $terms[] = $term_object->term_id;
1898 1898
         }
1899 1899
 
@@ -1911,20 +1911,20 @@  discard block
 block discarded – undo
1911 1911
      * @param $user_id
1912 1912
      * @return array
1913 1913
      */
1914
-    public function filter_terms_by_owner( $terms, $user_id ){
1914
+    public function filter_terms_by_owner($terms, $user_id) {
1915 1915
 
1916 1916
         $users_terms = array();
1917 1917
 
1918
-        foreach( $terms as $index => $term ){
1918
+        foreach ($terms as $index => $term) {
1919 1919
 
1920
-            if( is_numeric( $term ) ){
1920
+            if (is_numeric($term)) {
1921 1921
                 // the term id was given, get the term object
1922
-                $term = get_term( $term, 'module' );
1922
+                $term = get_term($term, 'module');
1923 1923
             }
1924 1924
 
1925
-            $author = Sensei_Core_Modules::get_term_author( $term->slug );
1925
+            $author = Sensei_Core_Modules::get_term_author($term->slug);
1926 1926
 
1927
-            if ( $user_id == $author->ID ) {
1927
+            if ($user_id == $author->ID) {
1928 1928
                 // add the term to the teachers terms
1929 1929
                 $users_terms[] = $term;
1930 1930
             }
@@ -1943,34 +1943,34 @@  discard block
 block discarded – undo
1943 1943
      *
1944 1944
      * @since 1.8.0
1945 1945
      */
1946
-    public function append_teacher_name_to_module( $terms, $taxonomies, $args )
1946
+    public function append_teacher_name_to_module($terms, $taxonomies, $args)
1947 1947
     {
1948 1948
 
1949 1949
         // only for admin users ont he module taxonomy
1950
-        if ( empty( $terms ) || !current_user_can('manage_options') || !in_array('module', $taxonomies) || !is_admin()) {
1950
+        if (empty($terms) || ! current_user_can('manage_options') || ! in_array('module', $taxonomies) || ! is_admin()) {
1951 1951
             return $terms;
1952 1952
         }
1953 1953
 
1954 1954
         // in certain cases the array is passed in as reference to the parent term_id => parent_id
1955 1955
         // simply return this as wp doesn't need an array of stdObject Term
1956
-        if (isset( $args['fields'] ) && 'id=>parent' == $args['fields']) {
1956
+        if (isset($args['fields']) && 'id=>parent' == $args['fields']) {
1957 1957
 
1958 1958
             return $terms;
1959 1959
 
1960 1960
         }
1961 1961
 
1962 1962
         // loop through and update all terms adding the author name
1963
-        foreach( $terms as $index => $term ){
1963
+        foreach ($terms as $index => $term) {
1964 1964
 
1965
-            if( is_numeric( $term ) ){
1965
+            if (is_numeric($term)) {
1966 1966
                 // the term id was given, get the term object
1967
-                $term = get_term( $term, 'module' );
1967
+                $term = get_term($term, 'module');
1968 1968
             }
1969 1969
 
1970
-            $author = Sensei_Core_Modules::get_term_author( $term->slug );
1970
+            $author = Sensei_Core_Modules::get_term_author($term->slug);
1971 1971
 
1972
-            if( ! user_can( $author, 'manage_options' ) && isset( $term->name ) ) {
1973
-                $term->name = $term->name . ' (' . $author->display_name . ') ';
1972
+            if ( ! user_can($author, 'manage_options') && isset($term->name)) {
1973
+                $term->name = $term->name.' ('.$author->display_name.') ';
1974 1974
             }
1975 1975
 
1976 1976
             // add the term to the teachers terms
@@ -1999,23 +1999,23 @@  discard block
 block discarded – undo
1999 1999
      * @sine 1.9.0
2000 2000
      * @param $post_id
2001 2001
      */
2002
-    public static function reset_none_modules_transient ( $post_id ){
2002
+    public static function reset_none_modules_transient($post_id) {
2003 2003
 
2004 2004
         // this should only apply to course and lesson post types
2005
-        if( in_array( get_post_type( $post_id ), array( 'course', 'lesson' ) ) ){
2005
+        if (in_array(get_post_type($post_id), array('course', 'lesson'))) {
2006 2006
 
2007 2007
             $course_id = '';
2008 2008
 
2009
-            if( 'lesson' == get_post_type( $post_id ) ){
2009
+            if ('lesson' == get_post_type($post_id)) {
2010 2010
 
2011
-                $course_id = Sensei()->lesson->get_course_id( $post_id );
2011
+                $course_id = Sensei()->lesson->get_course_id($post_id);
2012 2012
 
2013 2013
             }
2014 2014
 
2015 2015
 
2016
-            if( !empty( $course_id ) ){
2016
+            if ( ! empty($course_id)) {
2017 2017
 
2018
-                delete_transient( 'sensei_'. $course_id .'_none_module_lessons' );
2018
+                delete_transient('sensei_'.$course_id.'_none_module_lessons');
2019 2019
 
2020 2020
             }
2021 2021
 
@@ -2030,9 +2030,9 @@  discard block
 block discarded – undo
2030 2030
      * @deprecated since 1.9.0
2031 2031
      *
2032 2032
      */
2033
-    public static function deprecate_sensei_single_course_modules_content(){
2033
+    public static function deprecate_sensei_single_course_modules_content() {
2034 2034
 
2035
-        sensei_do_deprecated_action( 'sensei_single_course_modules_content','1.9.0','sensei_single_course_modules_before or sensei_single_course_modules_after' );
2035
+        sensei_do_deprecated_action('sensei_single_course_modules_content', '1.9.0', 'sensei_single_course_modules_before or sensei_single_course_modules_after');
2036 2036
 
2037 2037
     }
2038 2038
 
@@ -2043,12 +2043,12 @@  discard block
 block discarded – undo
2043 2043
      *
2044 2044
      * @since 1.9.0
2045 2045
      */
2046
-    public static function setup_single_course_module_loop(){
2046
+    public static function setup_single_course_module_loop() {
2047 2047
 
2048 2048
         global $sensei_modules_loop, $post;
2049 2049
         $course_id = $post->ID;
2050 2050
 
2051
-        $modules = Sensei()->modules->get_course_modules( $course_id );
2051
+        $modules = Sensei()->modules->get_course_modules($course_id);
2052 2052
 
2053 2053
         //initial setup
2054 2054
         $sensei_modules_loop['total'] = 0;
@@ -2056,22 +2056,22 @@  discard block
 block discarded – undo
2056 2056
         $sensei_modules_loop['current'] = -1;
2057 2057
 
2058 2058
         // exit if this course doesn't have modules
2059
-        if( !$modules || empty( $modules )  ){
2059
+        if ( ! $modules || empty($modules)) {
2060 2060
             return;
2061 2061
         }
2062 2062
 
2063 2063
 
2064 2064
         $lessons_in_all_modules = array();
2065
-        foreach( $modules as $term ){
2065
+        foreach ($modules as $term) {
2066 2066
 
2067
-            $lessons_in_this_module = Sensei()->modules->get_lessons( $course_id , $term->term_id);
2068
-            $lessons_in_all_modules = array_merge(  $lessons_in_all_modules, $lessons_in_this_module  );
2067
+            $lessons_in_this_module = Sensei()->modules->get_lessons($course_id, $term->term_id);
2068
+            $lessons_in_all_modules = array_merge($lessons_in_all_modules, $lessons_in_this_module);
2069 2069
 
2070 2070
         }
2071 2071
 
2072 2072
 
2073 2073
         //setup all of the modules loop variables
2074
-        $sensei_modules_loop['total'] = count( $modules );
2074
+        $sensei_modules_loop['total'] = count($modules);
2075 2075
         $sensei_modules_loop['modules'] = $modules;
2076 2076
         $sensei_modules_loop['current'] = -1;
2077 2077
         $sensei_modules_loop['course_id'] = $course_id;
@@ -2084,7 +2084,7 @@  discard block
 block discarded – undo
2084 2084
      * @since 1.9.0
2085 2085
      *
2086 2086
      */
2087
-    public static function teardown_single_course_module_loop(){
2087
+    public static function teardown_single_course_module_loop() {
2088 2088
 
2089 2089
         global $sensei_modules_loop, $wp_query, $post;
2090 2090
 
Please login to merge, or discard this patch.