Completed
Push — master ( 6960d5...c5ae6e )
by Dwain
07:46
created
includes/class-sensei.php 4 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -403,7 +403,7 @@  discard block
 block discarded – undo
403 403
     /**
404 404
      * Disable guest checkout if a course product is in the cart
405 405
      * @param  boolean $guest_checkout Current guest checkout setting
406
-     * @return boolean                 Modified guest checkout setting
406
+     * @return string|boolean                 Modified guest checkout setting
407 407
      */
408 408
     public function disable_guest_checkout( $guest_checkout ) {
409 409
         global $woocommerce;
@@ -642,7 +642,7 @@  discard block
 block discarded – undo
642 642
      * @since  1.0.0
643 643
      * @param  int 			$course_id  (default: 0)
644 644
      * @param  array/Object $order_user (default: array()) Specific user's data.
645
-     * @return bool|int
645
+     * @return boolean|string
646 646
      */
647 647
     public function woocommerce_course_update ( $course_id = 0, $order_user = array()  ) {
648 648
         global $current_user;
@@ -1241,7 +1241,7 @@  discard block
 block discarded – undo
1241 1241
      *
1242 1242
      * @since 1.4.5
1243 1243
      * @access public
1244
-     * @param mixed $image_size
1244
+     * @param string $image_size
1245 1245
      * @return string
1246 1246
      */
1247 1247
     public function get_image_size( $image_size ) {
Please login to merge, or discard this patch.
Braces   +35 added lines, -20 removed lines patch added patch discarded remove patch
@@ -1,5 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined( 'ABSPATH' ) ) {
3
+	exit;
4
+}
5
+// Exit if accessed directly
3 6
 
4 7
 /**
5 8
  * Sensei_Main
@@ -159,7 +162,9 @@  discard block
 block discarded – undo
159 162
         $this->init();
160 163
 
161 164
         // Installation
162
-        if ( is_admin() && ! defined( 'DOING_AJAX' ) ) $this->install();
165
+        if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
166
+        	$this->install();
167
+        }
163 168
 
164 169
         // Run this on activation.
165 170
         register_activation_hook( $this->file, array( $this, 'activation' ) );
@@ -447,7 +452,9 @@  discard block
 block discarded – undo
447 452
      **/
448 453
     public function virtual_order_payment_complete( $order_status, $order_id ) {
449 454
         $order = new WC_Order( $order_id );
450
-        if ( ! isset ( $order ) ) return '';
455
+        if ( ! isset ( $order ) ) {
456
+        	return '';
457
+        }
451 458
         if ( $order_status == 'wc-processing' && ( $order->post_status == 'wc-on-hold' || $order->post_status == 'wc-pending' || $order->post_status == 'wc-failed' ) ) {
452 459
             $virtual_order = true;
453 460
 
@@ -612,7 +619,7 @@  discard block
 block discarded – undo
612 619
 
613 620
             $sensei_plugin_path =  $this->plugin_path;
614 621
 
615
-        }else{
622
+        } else{
616 623
 
617 624
             $sensei_plugin_path = plugin_dir_path( __FILE__ );
618 625
 
@@ -647,7 +654,9 @@  discard block
 block discarded – undo
647 654
     public function woocommerce_course_update ( $course_id = 0, $order_user = array()  ) {
648 655
         global $current_user;
649 656
 
650
-        if ( ! isset( $current_user ) || !$current_user->ID > 0 ) return false;
657
+        if ( ! isset( $current_user ) || !$current_user->ID > 0 ) {
658
+        	return false;
659
+        }
651 660
 
652 661
         $data_update = false;
653 662
 
@@ -731,8 +740,7 @@  discard block
 block discarded – undo
731 740
 
732 741
                     $prerequisite_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, $current_user->ID );
733 742
 
734
-                }
735
-                else {
743
+                } else {
736 744
                     $prerequisite_complete = true;
737 745
                 } // End If Statement
738 746
                 // Handles restrictions
@@ -859,7 +867,9 @@  discard block
 block discarded – undo
859 867
      */
860 868
     public function access_settings () {
861 869
 
862
-        if( sensei_all_access() ) return true;
870
+        if( sensei_all_access() ) {
871
+        	return true;
872
+        }
863 873
 
864 874
         if ( isset( $this->settings->settings['access_permission'] ) && ( true == $this->settings->settings['access_permission'] ) ) {
865 875
             if ( is_user_logged_in() ) {
@@ -1188,8 +1198,9 @@  discard block
 block discarded – undo
1188 1198
         }
1189 1199
         $where = "WHERE comment_type IN ('" . join("', '", array_unique( $statuses ) ) . "')";
1190 1200
 
1191
-        if ( $post_id > 0 )
1192
-            $where .= $wpdb->prepare( " AND comment_post_ID = %d", $post_id );
1201
+        if ( $post_id > 0 ) {
1202
+                    $where .= $wpdb->prepare( " AND comment_post_ID = %d", $post_id );
1203
+        }
1193 1204
 
1194 1205
         $count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A );
1195 1206
 
@@ -1197,16 +1208,19 @@  discard block
 block discarded – undo
1197 1208
         $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash', 'post-trashed' => 'post-trashed');
1198 1209
         foreach ( (array) $count as $row ) {
1199 1210
             // Don't count post-trashed toward totals
1200
-            if ( 'post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'] )
1201
-                $total += $row['num_comments'];
1202
-            if ( isset( $approved[$row['comment_approved']] ) )
1203
-                $stats[$approved[$row['comment_approved']]] = $row['num_comments'];
1211
+            if ( 'post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'] ) {
1212
+                            $total += $row['num_comments'];
1213
+            }
1214
+            if ( isset( $approved[$row['comment_approved']] ) ) {
1215
+                            $stats[$approved[$row['comment_approved']]] = $row['num_comments'];
1216
+            }
1204 1217
         }
1205 1218
 
1206 1219
         $stats['total_comments'] = $total;
1207 1220
         foreach ( $approved as $key ) {
1208
-            if ( empty($stats[$key]) )
1209
-                $stats[$key] = 0;
1221
+            if ( empty($stats[$key]) ) {
1222
+                            $stats[$key] = 0;
1223
+            }
1210 1224
         }
1211 1225
 
1212 1226
         $stats = (object) $stats;
@@ -1247,8 +1261,9 @@  discard block
 block discarded – undo
1247 1261
     public function get_image_size( $image_size ) {
1248 1262
 
1249 1263
         // Only return sizes we define in settings
1250
-        if ( ! in_array( $image_size, array( 'course_archive_image', 'course_single_image', 'lesson_archive_image', 'lesson_single_image' ) ) )
1251
-            return apply_filters( 'sensei_get_image_size_' . $image_size, '' );
1264
+        if ( ! in_array( $image_size, array( 'course_archive_image', 'course_single_image', 'lesson_archive_image', 'lesson_single_image' ) ) ) {
1265
+                    return apply_filters( 'sensei_get_image_size_' . $image_size, '' );
1266
+        }
1252 1267
 
1253 1268
         if( ! isset( $this->settings->settings[ $image_size . '_width' ] ) ) {
1254 1269
             $this->settings->settings[ $image_size . '_width' ] = false;
@@ -1311,7 +1326,7 @@  discard block
 block discarded – undo
1311 1326
             require_once( 'class-sensei-modules.php');
1312 1327
             Sensei()->modules = new Sensei_Core_Modules( $this->file );
1313 1328
 
1314
-        }else{
1329
+        } else{
1315 1330
             // fallback for people still using the modules extension.
1316 1331
             global $sensei_modules;
1317 1332
             Sensei()->modules = $sensei_modules;
@@ -1358,7 +1373,7 @@  discard block
 block discarded – undo
1358 1373
 
1359 1374
             update_option('sensei_flush_rewrite_rules', '2');
1360 1375
 
1361
-        }elseif( '2' == $option ) {
1376
+        } elseif( '2' == $option ) {
1362 1377
 
1363 1378
             flush_rewrite_rules();
1364 1379
             update_option('sensei_flush_rewrite_rules', '0');
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.
Indentation   +1324 added lines, -1324 removed lines patch added patch discarded remove patch
@@ -10,1343 +10,1343 @@  discard block
 block discarded – undo
10 10
  */
11 11
 class Sensei_Main {
12 12
 
13
-    /**
14
-     * @var string
15
-     * Reference to the main plugin file
16
-     */
17
-    private $file;
18
-
19
-    /**
20
-     * @var Sensei_Main $_instance to the the main and only instance of the Sensei class.
21
-     * @since 1.8.0
22
-     */
23
-    protected static $_instance = null;
24
-
25
-    /**
26
-     * Main reference to the plugins current version
27
-     */
28
-    public $version;
29
-
30
-    /**
31
-     * Public token, referencing for the text domain.
32
-     */
33
-    public $token = 'woothemes-sensei';
34
-
35
-    /**
36
-     * Plugin url and path for use when access resources.
37
-     */
38
-    public $plugin_url;
39
-    public $plugin_path;
40
-    public $template_url;
41
-
42
-    /**
43
-     * @var Sensei_PostTypes
44
-     * All Sensei sub classes. Currently used to access functionality contained within
45
-     * within Sensei sub classes e.g. Sensei()->course->all_courses()
46
-     */
47
-    public $post_types;
48
-
49
-    /**
50
-     * @var WooThemes_Sensei_Settings
51
-     */
52
-    public $settings;
53
-
54
-    /**
55
-     * @var WooThemes_Sensei_Course_Results
56
-     */
57
-    public $course_results;
58
-
59
-    /**
60
-     * @var Sensei_Updates
61
-     */
62
-    public $updates;
63
-    /**
64
-     * @var WooThemes_Sensei_Course
65
-     */
66
-    public $course;
67
-
68
-    /**
69
-     * @var WooThemes_Sensei_Lesson
70
-     */
71
-    public $lesson;
72
-
73
-    /**
74
-     * @var WooThemes_Sensei_Quiz
75
-     */
76
-    public $quiz;
77
-
78
-    /**
79
-     * @var WooThemes_Sensei_Question
80
-     */
81
-    public $question;
82
-
83
-    /**
84
-     * @var WooThemes_Sensei_Admin
85
-     */
86
-    public $admin;
87
-
88
-    /**
89
-     * @var WooThemes_Sensei_Frontend
90
-     */
91
-    public $frontend;
92
-
93
-    /**
94
-     * @var Sensei_Notices
95
-     */
96
-    public $notices;
97
-
98
-    /**
99
-     * @var WooThemes_Sensei_Grading
100
-     */
101
-    public $grading;
102
-
103
-    /**
104
-     * @var WooThemes_Sensei_Emails
105
-     */
106
-    public $emails;
107
-
108
-    /**
109
-     * @var WooThemes_Sensei_Learner_Profiles
110
-     */
111
-    public $learner_profiles;
112
-
113
-    /**
114
-     * @var Sensei_Teacher
115
-     */
116
-    public $teacher;
117
-
118
-    /**
119
-     * @var WooThemes_Sensei_Learners
120
-     */
121
-    public $learners;
122
-
123
-    /**
124
-     * @var array
125
-     * Global instance for access to the permissions message shown
126
-     * when users do not have the right privileges to access resources.
127
-     */
128
-    public $permissions_message;
129
-
130
-    /**
131
-     * @var Sensei_Core_Modules Sensei Modules functionality
132
-     */
133
-    public $modules;
134
-
135
-    /**
136
-     * @var Sensei_Analysis
137
-     */
138
-    public $analysis;
139
-
140
-    /**
141
-     * Constructor method.
142
-     * @param  string $file The base file of the plugin.
143
-     * @since  1.0.0
144
-     */
145
-    public function __construct ( $file ) {
146
-
147
-        // Setup object data
148
-        $this->file = $file;
149
-        $this->plugin_url = trailingslashit( plugins_url( '', $plugin = $file ) );
150
-        $this->plugin_path = trailingslashit( dirname( $file ) );
151
-        $this->template_url	= apply_filters( 'sensei_template_url', 'sensei/' );
152
-        $this->permissions_message = array( 'title' => __( 'Permission Denied', 'woothemes-sensei' ), 'message' => __( 'Unfortunately you do not have permissions to access this page.', 'woothemes-sensei' ) );
153
-
154
-        // Initialize the core Sensei functionality
155
-        $this->init();
156
-
157
-        // Installation
158
-        if ( is_admin() && ! defined( 'DOING_AJAX' ) ) $this->install();
159
-
160
-        // Run this on activation.
161
-        register_activation_hook( $this->file, array( $this, 'activation' ) );
162
-
163
-        // Image Sizes
164
-        $this->init_image_sizes();
165
-
166
-        // Force WooCommerce Required Settings
167
-        $this->set_woocommerce_functionality();
168
-
169
-        // load all hooks
170
-        $this->load_hooks();
171
-
172
-    } // End __construct()
173
-
174
-    /**
175
-     * Load the foundations of Sensei.
176
-     * @since 1.9.0
177
-     */
178
-    protected function init(){
179
-
180
-        // Localisation
181
-        $this->load_plugin_textdomain();
182
-        add_action( 'init', array( $this, 'load_localisation' ), 0 );
183
-
184
-        // load the shortcode loader into memory, so as to listen to all for
185
-        // all shortcodes on the front end
186
-        new Sensei_Shortcode_Loader();
187
-
188
-    }
189
-
190
-    /**
191
-     * Global Sensei Instance
192
-     *
193
-     * Ensure that only one instance of the main Sensei class can be loaded.
194
-     *
195
-     * @since 1.8.0
196
-     * @static
197
-     * @see WC()
198
-     * @return WooThemes_Sensei Instance.
199
-     */
200
-    public static function instance() {
13
+	/**
14
+	 * @var string
15
+	 * Reference to the main plugin file
16
+	 */
17
+	private $file;
18
+
19
+	/**
20
+	 * @var Sensei_Main $_instance to the the main and only instance of the Sensei class.
21
+	 * @since 1.8.0
22
+	 */
23
+	protected static $_instance = null;
24
+
25
+	/**
26
+	 * Main reference to the plugins current version
27
+	 */
28
+	public $version;
29
+
30
+	/**
31
+	 * Public token, referencing for the text domain.
32
+	 */
33
+	public $token = 'woothemes-sensei';
34
+
35
+	/**
36
+	 * Plugin url and path for use when access resources.
37
+	 */
38
+	public $plugin_url;
39
+	public $plugin_path;
40
+	public $template_url;
41
+
42
+	/**
43
+	 * @var Sensei_PostTypes
44
+	 * All Sensei sub classes. Currently used to access functionality contained within
45
+	 * within Sensei sub classes e.g. Sensei()->course->all_courses()
46
+	 */
47
+	public $post_types;
48
+
49
+	/**
50
+	 * @var WooThemes_Sensei_Settings
51
+	 */
52
+	public $settings;
53
+
54
+	/**
55
+	 * @var WooThemes_Sensei_Course_Results
56
+	 */
57
+	public $course_results;
58
+
59
+	/**
60
+	 * @var Sensei_Updates
61
+	 */
62
+	public $updates;
63
+	/**
64
+	 * @var WooThemes_Sensei_Course
65
+	 */
66
+	public $course;
67
+
68
+	/**
69
+	 * @var WooThemes_Sensei_Lesson
70
+	 */
71
+	public $lesson;
72
+
73
+	/**
74
+	 * @var WooThemes_Sensei_Quiz
75
+	 */
76
+	public $quiz;
77
+
78
+	/**
79
+	 * @var WooThemes_Sensei_Question
80
+	 */
81
+	public $question;
82
+
83
+	/**
84
+	 * @var WooThemes_Sensei_Admin
85
+	 */
86
+	public $admin;
87
+
88
+	/**
89
+	 * @var WooThemes_Sensei_Frontend
90
+	 */
91
+	public $frontend;
92
+
93
+	/**
94
+	 * @var Sensei_Notices
95
+	 */
96
+	public $notices;
97
+
98
+	/**
99
+	 * @var WooThemes_Sensei_Grading
100
+	 */
101
+	public $grading;
102
+
103
+	/**
104
+	 * @var WooThemes_Sensei_Emails
105
+	 */
106
+	public $emails;
107
+
108
+	/**
109
+	 * @var WooThemes_Sensei_Learner_Profiles
110
+	 */
111
+	public $learner_profiles;
112
+
113
+	/**
114
+	 * @var Sensei_Teacher
115
+	 */
116
+	public $teacher;
117
+
118
+	/**
119
+	 * @var WooThemes_Sensei_Learners
120
+	 */
121
+	public $learners;
122
+
123
+	/**
124
+	 * @var array
125
+	 * Global instance for access to the permissions message shown
126
+	 * when users do not have the right privileges to access resources.
127
+	 */
128
+	public $permissions_message;
129
+
130
+	/**
131
+	 * @var Sensei_Core_Modules Sensei Modules functionality
132
+	 */
133
+	public $modules;
134
+
135
+	/**
136
+	 * @var Sensei_Analysis
137
+	 */
138
+	public $analysis;
139
+
140
+	/**
141
+	 * Constructor method.
142
+	 * @param  string $file The base file of the plugin.
143
+	 * @since  1.0.0
144
+	 */
145
+	public function __construct ( $file ) {
146
+
147
+		// Setup object data
148
+		$this->file = $file;
149
+		$this->plugin_url = trailingslashit( plugins_url( '', $plugin = $file ) );
150
+		$this->plugin_path = trailingslashit( dirname( $file ) );
151
+		$this->template_url	= apply_filters( 'sensei_template_url', 'sensei/' );
152
+		$this->permissions_message = array( 'title' => __( 'Permission Denied', 'woothemes-sensei' ), 'message' => __( 'Unfortunately you do not have permissions to access this page.', 'woothemes-sensei' ) );
153
+
154
+		// Initialize the core Sensei functionality
155
+		$this->init();
156
+
157
+		// Installation
158
+		if ( is_admin() && ! defined( 'DOING_AJAX' ) ) $this->install();
159
+
160
+		// Run this on activation.
161
+		register_activation_hook( $this->file, array( $this, 'activation' ) );
162
+
163
+		// Image Sizes
164
+		$this->init_image_sizes();
165
+
166
+		// Force WooCommerce Required Settings
167
+		$this->set_woocommerce_functionality();
168
+
169
+		// load all hooks
170
+		$this->load_hooks();
171
+
172
+	} // End __construct()
173
+
174
+	/**
175
+	 * Load the foundations of Sensei.
176
+	 * @since 1.9.0
177
+	 */
178
+	protected function init(){
179
+
180
+		// Localisation
181
+		$this->load_plugin_textdomain();
182
+		add_action( 'init', array( $this, 'load_localisation' ), 0 );
183
+
184
+		// load the shortcode loader into memory, so as to listen to all for
185
+		// all shortcodes on the front end
186
+		new Sensei_Shortcode_Loader();
187
+
188
+	}
189
+
190
+	/**
191
+	 * Global Sensei Instance
192
+	 *
193
+	 * Ensure that only one instance of the main Sensei class can be loaded.
194
+	 *
195
+	 * @since 1.8.0
196
+	 * @static
197
+	 * @see WC()
198
+	 * @return WooThemes_Sensei Instance.
199
+	 */
200
+	public static function instance() {
201 201
 
202
-        if ( is_null( self::$_instance ) ) {
202
+		if ( is_null( self::$_instance ) ) {
203 203
 
204
-            //Sensei requires a reference to the main Sensei plugin file
205
-            $sensei_main_plugin_file = dirname ( dirname( __FILE__ ) ) . '/woothemes-sensei.php';
204
+			//Sensei requires a reference to the main Sensei plugin file
205
+			$sensei_main_plugin_file = dirname ( dirname( __FILE__ ) ) . '/woothemes-sensei.php';
206 206
 
207
-            self::$_instance = new self( $sensei_main_plugin_file  );
207
+			self::$_instance = new self( $sensei_main_plugin_file  );
208 208
 
209
-            // load the global class objects needed throughout Sensei
210
-            self::$_instance->initialize_global_objects();
209
+			// load the global class objects needed throughout Sensei
210
+			self::$_instance->initialize_global_objects();
211 211
 
212
-        }
212
+		}
213 213
 
214
-        return self::$_instance;
214
+		return self::$_instance;
215 215
 
216
-    } // end instance()
216
+	} // end instance()
217 217
 
218
-    /**
219
-     * This function is linked into the activation
220
-     * hook to reset flush the urls to ensure Sensei post types show up.
221
-     *
222
-     * @since 1.9.0
223
-     *
224
-     * @param $plugin
225
-     */
226
-    public static function activation_flush_rules( $plugin ){
218
+	/**
219
+	 * This function is linked into the activation
220
+	 * hook to reset flush the urls to ensure Sensei post types show up.
221
+	 *
222
+	 * @since 1.9.0
223
+	 *
224
+	 * @param $plugin
225
+	 */
226
+	public static function activation_flush_rules( $plugin ){
227 227
 
228
-        if( strpos( $plugin, '/woothemes-sensei.php' ) > 0  ){
228
+		if( strpos( $plugin, '/woothemes-sensei.php' ) > 0  ){
229 229
 
230
-            flush_rewrite_rules(true);
230
+			flush_rewrite_rules(true);
231 231
 
232
-        }
232
+		}
233 233
 
234
-    }
234
+	}
235 235
 
236
-    /**
237
-     * Cloning is forbidden.
238
-     * @since 1.8.0
239
-     */
240
-    public function __clone() {
241
-        _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'woothemes-sensei' ), '1.8' );
242
-    }
236
+	/**
237
+	 * Cloning is forbidden.
238
+	 * @since 1.8.0
239
+	 */
240
+	public function __clone() {
241
+		_doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'woothemes-sensei' ), '1.8' );
242
+	}
243 243
 
244
-    /**
245
-     * Unserializing instances of this class is forbidden.
246
-     * @since 1.8.0
247
-     */
248
-    public function __wakeup() {
249
-        _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'woothemes-sensei' ), '1.8' );
250
-    }
244
+	/**
245
+	 * Unserializing instances of this class is forbidden.
246
+	 * @since 1.8.0
247
+	 */
248
+	public function __wakeup() {
249
+		_doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'woothemes-sensei' ), '1.8' );
250
+	}
251 251
 
252
-    /**
253
-     * Load the properties for the main Sensei object
254
-     *
255
-     * @since 1.9.0
256
-     */
257
-    public function initialize_global_objects(){
252
+	/**
253
+	 * Load the properties for the main Sensei object
254
+	 *
255
+	 * @since 1.9.0
256
+	 */
257
+	public function initialize_global_objects(){
258 258
 
259
-        // Setup post types.
260
-        $this->post_types = new Sensei_PostTypes();
259
+		// Setup post types.
260
+		$this->post_types = new Sensei_PostTypes();
261 261
 
262
-        // Lad the updates class
263
-        $this->updates = new Sensei_Updates( $this );
262
+		// Lad the updates class
263
+		$this->updates = new Sensei_Updates( $this );
264 264
 
265
-        // Setup settings
266
-        $this->settings = new Sensei_Settings();
265
+		// Setup settings
266
+		$this->settings = new Sensei_Settings();
267 267
 
268
-        // Load Course Results Class
269
-        $this->course_results = new Sensei_Course_Results();
268
+		// Load Course Results Class
269
+		$this->course_results = new Sensei_Course_Results();
270 270
 
271
-        // Load the teacher role
272
-        $this->teacher = new Sensei_Teacher();
271
+		// Load the teacher role
272
+		$this->teacher = new Sensei_Teacher();
273 273
 
274
-        // Add the Course class
275
-        $this->course = $this->post_types->course;
274
+		// Add the Course class
275
+		$this->course = $this->post_types->course;
276 276
 
277
-        // Add the lesson class
278
-        $this->lesson = $this->post_types->lesson;
277
+		// Add the lesson class
278
+		$this->lesson = $this->post_types->lesson;
279 279
 
280
-        // Add the question class
281
-        $this->question = $this->post_types->question;
280
+		// Add the question class
281
+		$this->question = $this->post_types->question;
282 282
 
283
-        //Add the quiz class
284
-        $this->quiz = $this->post_types->quiz;
283
+		//Add the quiz class
284
+		$this->quiz = $this->post_types->quiz;
285 285
 
286
-        // load the modules class after all plugsin are loaded
287
-        add_action( 'plugins_loaded', array( $this, 'load_modules_class' ) );
286
+		// load the modules class after all plugsin are loaded
287
+		add_action( 'plugins_loaded', array( $this, 'load_modules_class' ) );
288 288
 
289
-        // Load Learner Management Functionality
290
-        $this->learners = new Sensei_Learner_Management( $this->file );
289
+		// Load Learner Management Functionality
290
+		$this->learners = new Sensei_Learner_Management( $this->file );
291 291
 
292
-        // Differentiate between administration and frontend logic.
293
-        if ( is_admin() ) {
292
+		// Differentiate between administration and frontend logic.
293
+		if ( is_admin() ) {
294 294
 
295
-            // Load Admin Welcome class
296
-            new Sensei_Welcome();
295
+			// Load Admin Welcome class
296
+			new Sensei_Welcome();
297 297
 
298
-            // Load Admin Class
299
-            $this->admin = new Sensei_Admin( $this->file );
298
+			// Load Admin Class
299
+			$this->admin = new Sensei_Admin( $this->file );
300 300
 
301
-            // Load Analysis Reports
302
-            $this->analysis = new Sensei_Analysis( $this->file );
301
+			// Load Analysis Reports
302
+			$this->analysis = new Sensei_Analysis( $this->file );
303 303
 
304
-        } else {
304
+		} else {
305 305
 
306
-            // Load Frontend Class
307
-            $this->frontend = new Sensei_Frontend();
306
+			// Load Frontend Class
307
+			$this->frontend = new Sensei_Frontend();
308 308
 
309
-            // Load notice Class
310
-            $this->notices = new Sensei_Notices();
309
+			// Load notice Class
310
+			$this->notices = new Sensei_Notices();
311 311
 
312
-            // Load built in themes support integration
313
-            new Sensei_Theme_Integration_Loader();
312
+			// Load built in themes support integration
313
+			new Sensei_Theme_Integration_Loader();
314 314
 
315 315
 
316
-        }
316
+		}
317 317
 
318
-        // Load Grading Functionality
319
-        $this->grading = new Sensei_Grading( $this->file );
318
+		// Load Grading Functionality
319
+		$this->grading = new Sensei_Grading( $this->file );
320 320
 
321
-        // Load Email Class
322
-        $this->emails = new Sensei_Emails( $this->file );
321
+		// Load Email Class
322
+		$this->emails = new Sensei_Emails( $this->file );
323 323
 
324
-        // Load Learner Profiles Class
325
-        $this->learner_profiles = new Sensei_Learner_Profiles();
324
+		// Load Learner Profiles Class
325
+		$this->learner_profiles = new Sensei_Learner_Profiles();
326 326
 
327
-    }
327
+	}
328 328
 
329
-    /**
330
-     * Initialize all Sensei hooks
331
-     *
332
-     * @since 1.9.0
333
-     */
334
-    public function load_hooks(){
335
-
336
-        add_action( 'widgets_init', array( $this, 'register_widgets' ) );
337
-        add_action( 'after_setup_theme', array( $this, 'ensure_post_thumbnails_support' ) );
338
-
339
-        // WooCommerce Payment Actions
340
-        add_action( 'woocommerce_payment_complete' , array( $this, 'sensei_woocommerce_complete_order' ) );
341
-        add_action( 'woocommerce_thankyou' , array( $this, 'sensei_woocommerce_complete_order' ) );
342
-        add_action( 'woocommerce_order_status_completed' , array( $this, 'sensei_woocommerce_complete_order' ) );
343
-        add_action( 'woocommerce_order_status_processing' , array( $this, 'sensei_woocommerce_complete_order' ) );
344
-        add_action( 'woocommerce_order_status_cancelled' , array( $this, 'sensei_woocommerce_cancel_order' ) );
345
-        add_action( 'woocommerce_order_status_refunded' , array( $this, 'sensei_woocommerce_cancel_order' ) );
346
-        add_action( 'subscriptions_activated_for_order', array( $this, 'sensei_activate_subscription' ) );
347
-
348
-        // WooCommerce Subscriptions Actions
349
-        add_action( 'reactivated_subscription', array( $this, 'sensei_woocommerce_reactivate_subscription' ), 10, 2 );
350
-        add_action( 'subscription_expired' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 );
351
-        add_action( 'subscription_end_of_prepaid_term' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 );
352
-        add_action( 'cancelled_subscription' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 );
353
-        add_action( 'subscription_put_on-hold' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 );
354
-
355
-        // Add Email link to course orders
356
-        add_action( 'woocommerce_email_after_order_table', array( $this, 'sensei_woocommerce_email_course_details' ), 10, 1 );
357
-
358
-        // Filter comment counts
359
-        add_filter( 'wp_count_comments', array( $this, 'sensei_count_comments' ), 10, 2 );
360
-
361
-        add_action( 'body_class', array( $this, 'body_class' ) );
362
-
363
-        // Check for and activate JetPack LaTeX support
364
-        add_action( 'plugins_loaded', array( $this, 'jetpack_latex_support'), 200 ); // Runs after Jetpack has loaded it's modules
365
-
366
-        // check flush the rewrite rules if the option sensei_flush_rewrite_rules option is 1
367
-        add_action( 'init', array( $this, 'flush_rewrite_rules'), 101 );
368
-
369
-    }
370
-
371
-    /**
372
-     * Run Sensei updates.
373
-     * @access  public
374
-     * @since   1.1.0
375
-     * @return  void
376
-     */
377
-    public function run_updates() {
378
-        // Run updates if administrator
379
-        if ( current_user_can( 'manage_options' ) || current_user_can( 'manage_sensei' ) ) {
380
-
381
-            $this->updates->update();
382
-
383
-        } // End If Statement
384
-    } // End run_updates()
385
-
386
-
387
-
388
-    /**
389
-     * Setup required WooCommerce settings.
390
-     * @access  public
391
-     * @since   1.1.0
392
-     * @return  void
393
-     */
394
-    public function set_woocommerce_functionality() {
395
-        // Disable guest checkout if a course is in the cart as we need a valid user to store data for
396
-        add_filter( 'pre_option_woocommerce_enable_guest_checkout', array( $this, 'disable_guest_checkout' ) );
397
-
398
-        // Mark orders with virtual products as complete rather then stay processing
399
-        add_filter( 'woocommerce_payment_complete_order_status', array( $this, 'virtual_order_payment_complete' ), 10, 2 );
400
-
401
-    } // End set_woocommerce_functionality()
402
-
403
-    /**
404
-     * Disable guest checkout if a course product is in the cart
405
-     * @param  boolean $guest_checkout Current guest checkout setting
406
-     * @return boolean                 Modified guest checkout setting
407
-     */
408
-    public function disable_guest_checkout( $guest_checkout ) {
409
-        global $woocommerce;
410
-
411
-        if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
412
-
413
-            if( isset( $woocommerce->cart->cart_contents ) && count( $woocommerce->cart->cart_contents ) > 0 ) {
414
-                foreach( $woocommerce->cart->cart_contents as $cart_key => $product ) {
415
-                    if( isset( $product['product_id'] ) ) {
416
-                        $args = array(
417
-                            'posts_per_page' => -1,
418
-                            'post_type' => 'course',
419
-                            'meta_query' => array(
420
-                                array(
421
-                                    'key' => '_course_woocommerce_product',
422
-                                    'value' => $product['product_id']
423
-                                )
424
-                            )
425
-                        );
426
-                        $posts = get_posts( $args );
427
-                        if( $posts && count( $posts ) > 0 ) {
428
-                            foreach( $posts as $course ) {
429
-                                $guest_checkout = '';
430
-                                break;
431
-                            }
432
-                        }
433
-                    }
434
-                }
435
-            }
436
-        }
437
-
438
-        return $guest_checkout;
439
-    }
440
-
441
-    /**
442
-     * Change order status with virtual products to completed
443
-     * @since  1.1.0
444
-     * @param string $order_status
445
-     * @param int $order_id
446
-     * @return string
447
-     **/
448
-    public function virtual_order_payment_complete( $order_status, $order_id ) {
449
-        $order = new WC_Order( $order_id );
450
-        if ( ! isset ( $order ) ) return '';
451
-        if ( $order_status == 'wc-processing' && ( $order->post_status == 'wc-on-hold' || $order->post_status == 'wc-pending' || $order->post_status == 'wc-failed' ) ) {
452
-            $virtual_order = true;
453
-
454
-            if ( count( $order->get_items() ) > 0 ) {
455
-                foreach( $order->get_items() as $item ) {
456
-                    if ( $item['product_id'] > 0 ) {
457
-                        $_product = $order->get_product_from_item( $item );
458
-                        if ( ! $_product->is_virtual() ) {
459
-                            $virtual_order = false;
460
-                            break;
461
-                        } // End If Statement
462
-                    } // End If Statement
463
-                } // End For Loop
464
-            } // End If Statement
465
-
466
-            // virtual order, mark as completed
467
-            if ( $virtual_order ) {
468
-                return 'completed';
469
-            } // End If Statement
470
-        } // End If Statement
471
-        return $order_status;
472
-    }
473
-
474
-    /**
475
-     * Register the widgets.
476
-     * @access public
477
-     * @since  1.0.0
478
-     * @return void
479
-     */
480
-    public function register_widgets () {
481
-        // Widget List (key => value is filename => widget class).
482
-        $widget_list = apply_filters( 'sensei_registered_widgets_list', array( 	'course-component' 	=> 'Course_Component',
483
-                'lesson-component' 	=> 'Lesson_Component',
484
-                'course-categories' => 'Course_Categories',
485
-                'category-courses' 	=> 'Category_Courses' )
486
-        );
487
-        foreach ( $widget_list as $key => $value ) {
488
-            if ( file_exists( $this->plugin_path . 'widgets/widget-woothemes-sensei-' . $key  . '.php' ) ) {
489
-                require_once( $this->plugin_path . 'widgets/widget-woothemes-sensei-' . $key  . '.php' );
490
-                register_widget( 'WooThemes_Sensei_' . $value . '_Widget' );
491
-            }
492
-        } // End For Loop
493
-
494
-        do_action( 'sensei_register_widgets' );
495
-
496
-    } // End register_widgets()
497
-
498
-    /**
499
-     * Load the plugin's localisation file.
500
-     * @access public
501
-     * @since  1.0.0
502
-     * @return void
503
-     */
504
-    public function load_localisation () {
505
-        load_plugin_textdomain( 'woothemes-sensei', false, dirname( plugin_basename( $this->file ) ) . '/lang/' );
506
-    } // End load_localisation()
507
-
508
-    /**
509
-     * Load the plugin textdomain from the main WordPress "languages" folder.
510
-     * @access  public
511
-     * @since   1.0.0
512
-     * @return  void
513
-     */
514
-    public function load_plugin_textdomain () {
515
-        $domain = 'woothemes-sensei';
516
-        // The "plugin_locale" filter is also used in load_plugin_textdomain()
517
-        $locale = apply_filters( 'plugin_locale', get_locale(), $domain );
518
-        load_textdomain( $domain, WP_LANG_DIR . '/' . $domain . '/' . $domain . '-' . $locale . '.mo' );
519
-        load_plugin_textdomain( $domain, FALSE, dirname( plugin_basename( $this->file ) ) . '/lang/' );
520
-    } // End load_plugin_textdomain()
521
-
522
-    /**
523
-     * Run on activation.
524
-     * @access public
525
-     * @since  1.0.0
526
-     * @return void
527
-     */
528
-    public function activation () {
529
-        $this->register_plugin_version();
530
-    } // End activation()
531
-
532
-
533
-    /**
534
-     * Register activation hooks.
535
-     * @access public
536
-     * @since  1.0.0
537
-     * @return void
538
-     */
539
-    public function install () {
540
-        register_activation_hook( $this->file, array( $this, 'activate_sensei' ) );
541
-        register_activation_hook( $this->file, 'flush_rewrite_rules' );
542
-    } // End install()
543
-
544
-
545
-    /**
546
-     * Run on activation of the plugin.
547
-     * @access public
548
-     * @since  1.0.0
549
-     * @return void
550
-     */
551
-    public function activate_sensei () {
552
-        update_option( 'skip_install_sensei_pages', 0 );
553
-        update_option( 'sensei_installed', 1 );
554
-    } // End activate_sensei()
555
-
556
-    /**
557
-     * Register the plugin's version.
558
-     * @access public
559
-     * @since  1.0.0
560
-     * @return void
561
-     */
562
-    private function register_plugin_version () {
563
-        if ( $this->version != '' ) {
564
-
565
-            // Check previous version to see if forced updates must run
566
-            // $old_version = get_option( 'woothemes-sensei-version', false );
567
-            // if( $old_version && version_compare( $old_version, '1.7.0', '<' )  ) {
568
-            // 	update_option( 'woothemes-sensei-force-updates', $this->version );
569
-            // } else {
570
-            // 	delete_option( 'woothemes-sensei-force-updates' );
571
-            // }
572
-
573
-            update_option( 'woothemes-sensei-version', $this->version );
574
-        }
575
-    } // End register_plugin_version()
576
-
577
-    /**
578
-     * Ensure that "post-thumbnails" support is available for those themes that don't register it.
579
-     * @access  public
580
-     * @since   1.0.1
581
-     * @return  void
582
-     */
583
-    public function ensure_post_thumbnails_support () {
584
-        if ( ! current_theme_supports( 'post-thumbnails' ) ) { add_theme_support( 'post-thumbnails' ); }
585
-    } // End ensure_post_thumbnails_support()
586
-
587
-
588
-    /**
589
-     * template_loader function.
590
-     *
591
-     * @access public
592
-     * @param mixed $template
593
-     * @return void
594
-     * @deprecated
595
-     */
596
-    public function template_loader ( $template = '' ) {
597
-
598
-        _deprecated_function( 'Sensei()->template_loader', '1.9.0', 'Use Sensei_Templates::template_loader( $template ) instead' );
599
-        Sensei_Templates::template_loader( $template );
600
-
601
-    } // End template_loader()
602
-
603
-    /**
604
-     * Determine the relative path to the plugin's directory.
605
-     * @access public
606
-     * @since  1.0.0
607
-     * @return string $sensei_plugin_path
608
-     */
609
-    public function plugin_path () {
610
-
611
-        if ( $this->plugin_path ) {
612
-
613
-            $sensei_plugin_path =  $this->plugin_path;
614
-
615
-        }else{
616
-
617
-            $sensei_plugin_path = plugin_dir_path( __FILE__ );
618
-
619
-        }
620
-
621
-        return $sensei_plugin_path;
622
-
623
-    } // End plugin_path()
624
-
625
-
626
-    /**
627
-     * Retrieve the ID of a specified page setting.
628
-     * @access public
629
-     * @since  1.0.0
630
-     * @param  string $page
631
-     * @return int
632
-     */
633
-    public function get_page_id ( $page ) {
634
-        $page = apply_filters( 'sensei_get_' . esc_attr( $page ) . '_page_id', get_option( 'sensei_' . esc_attr( $page ) . '_page_id' ) );
635
-        return ( $page ) ? $page : -1;
636
-    } // End get_page_id()
637
-
638
-
639
-    /**
640
-     * If WooCommerce is activated and the customer has purchased the course, update Sensei to indicate that they are taking the course.
641
-     * @access public
642
-     * @since  1.0.0
643
-     * @param  int 			$course_id  (default: 0)
644
-     * @param  array/Object $order_user (default: array()) Specific user's data.
645
-     * @return bool|int
646
-     */
647
-    public function woocommerce_course_update ( $course_id = 0, $order_user = array()  ) {
648
-        global $current_user;
649
-
650
-        if ( ! isset( $current_user ) || !$current_user->ID > 0 ) return false;
651
-
652
-        $data_update = false;
653
-
654
-        // Get the product ID
655
-        $wc_post_id = get_post_meta( intval( $course_id ), '_course_woocommerce_product', true );
656
-
657
-        // Check if in the admin
658
-        if ( is_admin() ) {
659
-            $user_login = $order_user['user_login'];
660
-            $user_email = $order_user['user_email'];
661
-            $user_url = $order_user['user_url'];
662
-            $user_id = $order_user['ID'];
663
-        } else {
664
-            $user_login = $current_user->user_login;
665
-            $user_email = $current_user->user_email;
666
-            $user_url = $current_user->user_url;
667
-            $user_id = $current_user->ID;
668
-        } // End If Statement
669
-
670
-        // This doesn't appear to be purely WooCommerce related. Should it be in a separate function?
671
-        $course_prerequisite_id = (int) get_post_meta( $course_id, '_course_prerequisite', true );
672
-        if( 0 < absint( $course_prerequisite_id ) ) {
673
-            $prereq_course_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, intval( $user_id ) );
674
-            if ( ! $prereq_course_complete ) {
675
-                // Remove all course user meta
676
-                return Sensei_Utils::sensei_remove_user_from_course( $course_id, $user_id );
677
-            }
678
-        }
679
-
680
-        $is_user_taking_course = Sensei_Utils::user_started_course( intval( $course_id ), intval( $user_id ) );
681
-
682
-        if( ! $is_user_taking_course ) {
683
-
684
-            if ( Sensei_WC::is_woocommerce_active() && Sensei_Utils::sensei_customer_bought_product( $user_email, $user_id, $wc_post_id ) && ( 0 < $wc_post_id ) ) {
685
-
686
-                $activity_logged = Sensei_Utils::user_start_course( intval( $user_id), intval( $course_id ) );
687
-
688
-                $is_user_taking_course = false;
689
-                if ( true == $activity_logged ) {
690
-                    $is_user_taking_course = true;
691
-                } // End If Statement
692
-            } // End If Statement
693
-        }
694
-
695
-        return $is_user_taking_course;
696
-    } // End woocommerce_course_update()
697
-
698
-
699
-    /**
700
-     * check_user_permissions function.
701
-     *
702
-     * @access public
703
-     * @param string $page (default: '')
704
-     *
705
-     * @return bool
706
-     */
707
-    public function check_user_permissions ( $page = '' ) {
708
-        // REFACTOR
709
-        global $current_user, $post;
710
-
711
-        // if use is not logged in
712
-        // skipped for single lesson
713
-        if ( empty( $current_user->caps ) && Sensei()->settings->get('access_permission')
714
-            && 'lesson-single' !=  $page ){
715
-            $this->permissions_message['title'] = __('Restricted Access', 'woothemes-sensei' );
716
-            $this->permissions_message['message'] = sprintf( __('You must be logged in to view this %s'), get_post_type() );
717
-            return false;
718
-        }
719
-
720
-        $user_allowed = false;
721
-
722
-        switch ( $page ) {
723
-            case 'course-single':
724
-                // check for prerequisite course or lesson,
725
-                $course_prerequisite_id = (int) get_post_meta( $post->ID, '_course_prerequisite', true);
726
-                $update_course = $this->woocommerce_course_update( $post->ID );
727
-                // Count completed lessons
728
-                if ( 0 < absint( $course_prerequisite_id ) ) {
729
-
730
-                    $prerequisite_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, $current_user->ID );
731
-
732
-                }
733
-                else {
734
-                    $prerequisite_complete = true;
735
-                } // End If Statement
736
-                // Handles restrictions
737
-                if ( !$prerequisite_complete && 0 < absint( $course_prerequisite_id ) ) {
738
-                    $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' );
739
-                    $course_link = '<a href="' . esc_url( get_permalink( $course_prerequisite_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>';
740
-                    $this->permissions_message['message'] = sprintf( __('Please complete the previous %1$s before taking this course.', 'woothemes-sensei' ), $course_link );
741
-                } else {
742
-                    $user_allowed = true;
743
-                } // End If Statement
744
-                break;
745
-            case 'lesson-single':
746
-                // Check for WC purchase
747
-                $lesson_course_id = get_post_meta( $post->ID, '_lesson_course',true );
748
-
749
-                $update_course = $this->woocommerce_course_update( $lesson_course_id );
750
-                $is_preview = Sensei_Utils::is_preview_lesson( $post->ID );
751
-
752
-                if ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) {
753
-                    $user_allowed = true;
754
-                } elseif( $this->access_settings() && false == $is_preview ) {
755
-
756
-                    $user_allowed = true;
757
-
758
-                } else {
759
-                    $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' );
760
-                    $course_link = '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>';
761
-                    $wc_post_id = get_post_meta( $lesson_course_id, '_course_woocommerce_product',true );
762
-                    if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) {
763
-                        if ( $is_preview ) {
764
-                            $this->permissions_message['message'] = sprintf( __('This is a preview lesson. Please purchase the %1$s to access all lessons.', 'woothemes-sensei' ), $course_link );
765
-                        } else {
766
-                            $this->permissions_message['message'] =  sprintf( __('Please purchase the %1$s before starting this Lesson.', 'woothemes-sensei' ), $course_link );
767
-                        }
768
-                    } else {
769
-                        if ( $is_preview ) {
770
-                            $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 );
771
-                        } else {
772
-                            /** This filter is documented in class-woothemes-sensei-frontend.php */
773
-                            $this->permissions_message['message'] =  sprintf( __( 'Please sign up for the %1$s before starting the lesson.', 'woothemes-sensei' ), $course_link );
774
-                        }
775
-                    } // End If Statement
776
-                } // End If Statement
777
-                break;
778
-            case 'quiz-single':
779
-                $lesson_id = get_post_meta( $post->ID, '_quiz_lesson',true );
780
-                $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course',true );
781
-
782
-                $update_course = $this->woocommerce_course_update( $lesson_course_id );
783
-                if ( ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) || sensei_all_access() ) {
784
-
785
-                    // Check for prerequisite lesson for this quiz
786
-                    $lesson_prerequisite_id = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true);
787
-                    $user_lesson_prerequisite_complete = Sensei_Utils::user_completed_lesson( $lesson_prerequisite_id, $current_user->ID);
788
-
789
-                    // Handle restrictions
790
-                    if( sensei_all_access() ) {
791
-                        $user_allowed = true;
792
-                    } else {
793
-                        if ( 0 < absint( $lesson_prerequisite_id ) && ( !$user_lesson_prerequisite_complete ) ) {
794
-                            $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' );
795
-                            $lesson_link = '<a href="' . esc_url( get_permalink( $lesson_prerequisite_id ) ) . '">' . __( 'lesson', 'woothemes-sensei' ) . '</a>';
796
-                            $this->permissions_message['message'] = sprintf( __('Please complete the previous %1$s before taking this Quiz.', 'woothemes-sensei' ), $lesson_link );
797
-                        } else {
798
-                            $user_allowed = true;
799
-                        } // End If Statement
800
-                    } // End If Statement
801
-                } elseif( $this->access_settings() ) {
802
-                    // Check if the user has started the course
803
-
804
-                    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'] ) ) ) {
805
-
806
-                        $user_allowed = false;
807
-                        $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' );
808
-                        $course_link = '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>';
809
-                        $wc_post_id = get_post_meta( $lesson_course_id, '_course_woocommerce_product',true );
810
-                        if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) {
811
-                            $this->permissions_message['message'] = sprintf( __('Please purchase the %1$s before starting this Quiz.', 'woothemes-sensei' ), $course_link );
812
-                        } else {
813
-                            $this->permissions_message['message'] = sprintf( __('Please sign up for the %1$s before starting this Quiz.', 'woothemes-sensei' ), $course_link );
814
-                        } // End If Statement
815
-                    } else {
816
-                        $user_allowed = true;
817
-                    } // End If Statement
818
-                } else {
819
-                    $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' );
820
-                    $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>';
821
-                    $this->permissions_message['message'] = sprintf( __('Please sign up for the %1$s before taking this Quiz.', 'woothemes-sensei' ), $course_link );
822
-                } // End If Statement
823
-                break;
824
-            default:
825
-                $user_allowed = true;
826
-                break;
827
-
828
-        } // End Switch Statement
829
-
830
-        /**
831
-         * filter the permissions message shown on sensei post types.
832
-         *
833
-         * @since 1.8.7
834
-         *
835
-         * @param array $permissions_message{
836
-         *
837
-         *   @type string $title
838
-         *   @type string $message
839
-         *
840
-         * }
841
-         * @param string $post_id
842
-         */
843
-        $this->permissions_message = apply_filters( 'sensei_permissions_message', $this->permissions_message, $post->ID );
844
-
845
-
846
-        if( sensei_all_access() || Sensei_Utils::is_preview_lesson( $post->ID ) ) {
847
-            $user_allowed = true;
848
-        }
849
-
850
-        return apply_filters( 'sensei_access_permissions', $user_allowed );
851
-    } // End get_placeholder_image()
852
-
853
-
854
-    /**
855
-     * Check if visitors have access permission. If the "access_permission" setting is active, do a log in check.
856
-     * @since  1.0.0
857
-     * @access public
858
-     * @return bool
859
-     */
860
-    public function access_settings () {
861
-
862
-        if( sensei_all_access() ) return true;
863
-
864
-        if ( isset( $this->settings->settings['access_permission'] ) && ( true == $this->settings->settings['access_permission'] ) ) {
865
-            if ( is_user_logged_in() ) {
866
-                return true;
867
-            } else {
868
-                return false;
869
-            } // End If Statement
870
-        } else {
871
-            return true;
872
-        } // End If Statement
873
-    } // End access_settings()
874
-
875
-    /**
876
-     * sensei_woocommerce_complete_order description
877
-     * @since   1.0.3
878
-     * @access  public
879
-     * @param   int $order_id WC order ID
880
-     * @return  void
881
-     */
882
-    public function sensei_woocommerce_complete_order ( $order_id = 0 ) {
883
-        $order_user = array();
884
-        // Check for WooCommerce
885
-        if ( Sensei_WC::is_woocommerce_active() && ( 0 < $order_id ) ) {
886
-            // Get order object
887
-            $order = new WC_Order( $order_id );
888
-            $user = get_user_by( 'id', $order->get_user_id() );
889
-            $order_user['ID'] = $user->ID;
890
-            $order_user['user_login'] = $user->user_login;
891
-            $order_user['user_email'] = $user->user_email;
892
-            $order_user['user_url'] = $user->user_url;
893
-            // Run through each product ordered
894
-            if ( 0 < sizeof( $order->get_items() ) ) {
895
-                foreach( $order->get_items() as $item ) {
896
-                    $product_type = '';
897
-                    if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
898
-                        $item_id = $item['variation_id'];
899
-                        $product_type = 'variation';
900
-                    } else {
901
-                        $item_id = $item['product_id'];
902
-                    } // End If Statement
903
-                    $_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type );
904
-                    // Get courses that use the WC product
905
-                    $courses = $this->post_types->course->get_product_courses( $_product->id );
906
-                    // Loop and update those courses
907
-                    foreach ( $courses as $course_item ) {
908
-                        $update_course = $this->woocommerce_course_update( $course_item->ID, $order_user );
909
-                    } // End For Loop
910
-                } // End For Loop
911
-            } // End If Statement
912
-            // Add meta to indicate that payment has been completed successfully
913
-            update_post_meta( $order_id, 'sensei_payment_complete', '1' );
914
-        } // End If Statement
915
-    } // End sensei_woocommerce_complete_order()
916
-
917
-    /**
918
-     * Runs when an order is cancelled.
919
-     * @since   1.2.0
920
-     * @access  public
921
-     * @param   integer $order_id order ID
922
-     * @return  void
923
-     */
924
-    public function sensei_woocommerce_cancel_order ( $order_id ) {
925
-
926
-        // Get order object
927
-        $order = new WC_Order( $order_id );
928
-
929
-        // Run through each product ordered
930
-        if ( 0 < sizeof( $order->get_items() ) ) {
931
-
932
-            // Get order user
933
-            $user_id = $order->__get( 'user_id' );
934
-
935
-            foreach( $order->get_items() as $item ) {
936
-
937
-                $product_type = '';
938
-                if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
939
-                    $item_id = $item['variation_id'];
940
-                    $product_type = 'variation';
941
-                } else {
942
-                    $item_id = $item['product_id'];
943
-                } // End If Statement
944
-                $_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type );
945
-
946
-                // Get courses that use the WC product
947
-                $courses = array();
948
-                $courses = $this->post_types->course->get_product_courses( $item_id );
949
-
950
-                // Loop and update those courses
951
-                foreach ($courses as $course_item){
952
-                    // Check and Remove course from courses user meta
953
-                    $dataset_changes = Sensei_Utils::sensei_remove_user_from_course( $course_item->ID, $user_id );
954
-                } // End For Loop
955
-            } // End For Loop
956
-        } // End If Statement
957
-    } // End sensei_woocommerce_cancel_order()
958
-
959
-    /**
960
-     * Runs when an subscription is cancelled or expires.
961
-     * @since   1.3.3
962
-     * @access  public
963
-     * @param   integer $user_id User ID
964
-     * @param   integer $subscription_key Subscription Unique Key
965
-     * @return  void
966
-     */
967
-    public function sensei_woocommerce_subscription_ended( $user_id, $subscription_key ) {
968
-        $subscription = WC_Subscriptions_Manager::get_users_subscription( $user_id, $subscription_key );
969
-        self::sensei_woocommerce_cancel_order( $subscription['order_id'] );
970
-    }
971
-
972
-    /**
973
-     * Runs when an subscription is re-activated after suspension.
974
-     * @since   1.3.3
975
-     * @access  public
976
-     * @param   integer $user_id User ID
977
-     * @param   integer $subscription_key Subscription Unique Key
978
-     * @return  void
979
-     */
980
-    public function sensei_woocommerce_reactivate_subscription( $user_id, $subscription_key ) {
981
-        $subscription = WC_Subscriptions_Manager::get_users_subscription( $user_id, $subscription_key );
982
-        $order = new WC_Order( $subscription['order_id'] );
983
-        $user = get_user_by( 'id', $order->get_user_id() );
984
-        $order_user = array();
985
-        $order_user['ID'] = $user->ID;
986
-        $order_user['user_login'] = $user->user_login;
987
-        $order_user['user_email'] = $user->user_email;
988
-        $order_user['user_url'] = $user->user_url;
989
-        $courses = $this->post_types->course->get_product_courses( $subscription['product_id'] );
990
-        foreach ( $courses as $course_item ){
991
-            $update_course = $this->woocommerce_course_update( $course_item->ID, $order_user );
992
-        } // End For Loop
993
-    } // End sensei_woocommerce_reactivate_subscription
994
-
995
-    /**
996
-     * Returns the WooCommerce Product Object
997
-     *
998
-     * The code caters for pre and post WooCommerce 2.2 installations.
999
-     *
1000
-     * @since   1.1.1
1001
-     * @access  public
1002
-     * @param   integer $wc_product_id Product ID or Variation ID
1003
-     * @param   string  $product_type  '' or 'variation'
1004
-     * @return   WC_Product $wc_product_object
1005
-     */
1006
-    public function sensei_get_woocommerce_product_object ( $wc_product_id = 0, $product_type = '' ) {
1007
-
1008
-        $wc_product_object = false;
1009
-        if ( 0 < intval( $wc_product_id ) ) {
1010
-
1011
-            // Get the product
1012
-            if ( function_exists( 'wc_get_product' ) ) {
1013
-
1014
-                $wc_product_object = wc_get_product( $wc_product_id ); // Post WC 2.3
1015
-
1016
-            } elseif ( function_exists( 'get_product' ) ) {
1017
-
1018
-                $wc_product_object = get_product( $wc_product_id ); // Post WC 2.0
1019
-
1020
-            } else {
1021
-
1022
-                // Pre WC 2.0
1023
-                if ( 'variation' == $product_type || 'subscription_variation' == $product_type ) {
1024
-
1025
-                    $wc_product_object = new WC_Product_Variation( $wc_product_id );
1026
-
1027
-                } else {
1028
-
1029
-                    $wc_product_object = new WC_Product( $wc_product_id );
1030
-
1031
-                } // End If Statement
1032
-
1033
-            } // End If Statement
1034
-
1035
-        } // End If Statement
1036
-
1037
-        return $wc_product_object;
1038
-
1039
-    } // End sensei_get_woocommerce_product_object()
1040
-
1041
-    /**
1042
-     * load_class loads in class files
1043
-     * @since   1.2.0
1044
-     * @access  public
1045
-     * @return  void
1046
-     */
1047
-    public function load_class ( $class_name = '' ) {
1048
-        if ( '' != $class_name && '' != $this->token ) {
1049
-            require_once( 'class-' . esc_attr( $this->token ) . '-' . esc_attr( $class_name ) . '.php' );
1050
-        } // End If Statement
1051
-    } // End load_class()
1052
-
1053
-    /**
1054
-     * sensei_activate_subscription runs when a subscription product is purchased
1055
-     * @since   1.2.0
1056
-     * @access  public
1057
-     * @param   integer $order_id order ID
1058
-     * @return  void
1059
-     */
1060
-    public function sensei_activate_subscription(  $order_id = 0 ) {
1061
-        if ( 0 < intval( $order_id ) ) {
1062
-            $order = new WC_Order( $order_id );
1063
-            $user = get_user_by('id', $order->user_id);
1064
-            $order_user['ID'] = $user->ID;
1065
-            $order_user['user_login'] = $user->user_login;
1066
-            $order_user['user_email'] = $user->user_email;
1067
-            $order_user['user_url'] = $user->user_url;
1068
-            // Run through each product ordered
1069
-            if (sizeof($order->get_items())>0) {
1070
-                foreach($order->get_items() as $item) {
1071
-                    $product_type = '';
1072
-                    if (isset($item['variation_id']) && $item['variation_id'] > 0) {
1073
-                        $item_id = $item['variation_id'];
1074
-                        $product_type = 'subscription_variation';
1075
-                    } else {
1076
-                        $item_id = $item['product_id'];
1077
-                    } // End If Statement
1078
-                    $_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type );
1079
-                    // Get courses that use the WC product
1080
-                    $courses = array();
1081
-                    if ( $product_type == 'subscription_variation' ) {
1082
-                        $courses = $this->post_types->course->get_product_courses( $item_id );
1083
-                    } // End If Statement
1084
-                    // Loop and update those courses
1085
-                    foreach ($courses as $course_item){
1086
-                        $update_course = $this->woocommerce_course_update( $course_item->ID, $order_user );
1087
-                    } // End For Loop
1088
-                } // End For Loop
1089
-            } // End If Statement
1090
-        } // End If Statement
1091
-    } // End sensei_activate_subscription()
1092
-
1093
-    /**
1094
-     * sensei_woocommerce_email_course_details adds detail to email
1095
-     * @since   1.4.5
1096
-     * @access  public
1097
-     * @param   WC_Order $order
1098
-     * @return  void
1099
-     */
1100
-    public function sensei_woocommerce_email_course_details( $order ) {
1101
-        global $woocommerce;
1102
-
1103
-        // exit early if not wc-completed or wc-processing
1104
-        if( 'wc-completed' != $order->post_status
1105
-            && 'wc-processing' != $order->post_status  ) {
1106
-            return;
1107
-        }
1108
-
1109
-        $order_items = $order->get_items();
1110
-        $order_id = $order->id;
1111
-
1112
-        //If object have items go through them all to find course
1113
-        if ( 0 < sizeof( $order_items ) ) {
1114
-
1115
-            $course_details_html =  '<h2>' . __( 'Course details', 'woothemes-sensei' ) . '</h2>';
1116
-            $order_contains_courses = false;
1117
-
1118
-
1119
-            foreach ( $order_items as $item ) {
1120
-
1121
-                $product_type = '';
1122
-                if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
1123
-                    // If item has variation_id then its from variation
1124
-                    $item_id = $item['variation_id'];
1125
-                    $product_type = 'variation';
1126
-                } else {
1127
-                    // If not its real product set its id to item_id
1128
-                    $item_id = $item['product_id'];
1129
-                } // End If Statement
1130
-
1131
-                $user_id = get_post_meta( $order_id, '_customer_user', true );
1132
-
1133
-                if( $user_id ) {
1134
-
1135
-                    // Get all courses for product
1136
-                    $args = array(
1137
-                        'posts_per_page' => -1,
1138
-                        'post_type' => 'course',
1139
-                        'meta_query' => array(
1140
-                            array(
1141
-                                'key' => '_course_woocommerce_product',
1142
-                                'value' => $item_id
1143
-                            )
1144
-                        ),
1145
-                        'orderby' => 'menu_order date',
1146
-                        'order' => 'ASC',
1147
-                    );
1148
-                    $courses = get_posts( $args );
1149
-
1150
-                    if( $courses && count( $courses ) > 0 ) {
1151
-
1152
-                        foreach( $courses as $course ) {
1153
-
1154
-                            $title = $course->post_title;
1155
-                            $permalink = get_permalink( $course->ID );
1156
-                            $order_contains_courses = true;
1157
-                            $course_details_html .=  '<p><strong>' . sprintf( __( 'View course: %1$s', 'woothemes-sensei' ), '</strong><a href="' . esc_url( $permalink ) . '">' . $title . '</a>' ) . '</p>';
1158
-                        }
1159
-
1160
-
1161
-                    } // end if has courses
1162
-
1163
-                } // end if $userPid
1164
-
1165
-            } // end for each order item
1166
-
1167
-            // Output Course details
1168
-            if( $order_contains_courses ){
1169
-
1170
-                echo $course_details_html;
1171
-
1172
-            }
1173
-
1174
-
1175
-        } // end if  order items not empty
1176
-
1177
-    } // end func email course details
1178
-
1179
-    /**
1180
-     * Filtering wp_count_comments to ensure that Sensei comments are ignored
1181
-     * @since   1.4.0
1182
-     * @access  public
1183
-     * @param  array   $comments
1184
-     * @param  integer $post_id
1185
-     * @return array
1186
-     */
1187
-    public function sensei_count_comments( $comments, $post_id ) {
1188
-        global $wpdb;
1189
-
1190
-        $post_id = (int) $post_id;
1191
-
1192
-        $count = wp_cache_get("comments-{$post_id}", 'counts');
1193
-
1194
-        if ( false !== $count ) {
1195
-            return $count;
1196
-        }
1197
-
1198
-        $statuses = array( '' ); // Default to the WP normal comments
1199
-        $stati = $wpdb->get_results( "SELECT comment_type FROM {$wpdb->comments} GROUP BY comment_type", ARRAY_A );
1200
-        foreach ( (array) $stati AS $status ) {
1201
-            if ( 'sensei_' != substr($status['comment_type'], 0, 7 ) ) {
1202
-                $statuses[] = $status['comment_type'];
1203
-            }
1204
-        }
1205
-        $where = "WHERE comment_type IN ('" . join("', '", array_unique( $statuses ) ) . "')";
1206
-
1207
-        if ( $post_id > 0 )
1208
-            $where .= $wpdb->prepare( " AND comment_post_ID = %d", $post_id );
1209
-
1210
-        $count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A );
1211
-
1212
-        $total = 0;
1213
-        $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash', 'post-trashed' => 'post-trashed');
1214
-        foreach ( (array) $count as $row ) {
1215
-            // Don't count post-trashed toward totals
1216
-            if ( 'post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'] )
1217
-                $total += $row['num_comments'];
1218
-            if ( isset( $approved[$row['comment_approved']] ) )
1219
-                $stats[$approved[$row['comment_approved']]] = $row['num_comments'];
1220
-        }
1221
-
1222
-        $stats['total_comments'] = $total;
1223
-        foreach ( $approved as $key ) {
1224
-            if ( empty($stats[$key]) )
1225
-                $stats[$key] = 0;
1226
-        }
1227
-
1228
-        $stats = (object) $stats;
1229
-        wp_cache_set("comments-{$post_id}", $stats, 'counts');
1230
-
1231
-        return $stats;
1232
-    }
1233
-
1234
-    /**
1235
-     * Init images.
1236
-     *
1237
-     * @since 1.4.5
1238
-     * @access public
1239
-     * @return void
1240
-     */
1241
-    public function init_image_sizes() {
1242
-        $course_archive_thumbnail 	= $this->get_image_size( 'course_archive_image' );
1243
-        $course_single_thumbnail	= $this->get_image_size( 'course_single_image' );
1244
-        $lesson_archive_thumbnail 	= $this->get_image_size( 'lesson_archive_image' );
1245
-        $lesson_single_thumbnail	= $this->get_image_size( 'lesson_single_image' );
1246
-
1247
-        add_image_size( 'course_archive_thumbnail', $course_archive_thumbnail['width'], $course_archive_thumbnail['height'], $course_archive_thumbnail['crop'] );
1248
-        add_image_size( 'course_single_thumbnail', $course_single_thumbnail['width'], $course_single_thumbnail['height'], $course_single_thumbnail['crop'] );
1249
-        add_image_size( 'lesson_archive_thumbnail', $lesson_archive_thumbnail['width'], $lesson_archive_thumbnail['height'], $lesson_archive_thumbnail['crop'] );
1250
-        add_image_size( 'lesson_single_thumbnail', $lesson_single_thumbnail['width'], $lesson_single_thumbnail['height'], $lesson_single_thumbnail['crop'] );
1251
-    }
1252
-
1253
-    /**
1254
-     * Get an image size.
1255
-     *
1256
-     * Variable is filtered by sensei_get_image_size_{image_size}
1257
-     *
1258
-     * @since 1.4.5
1259
-     * @access public
1260
-     * @param mixed $image_size
1261
-     * @return string
1262
-     */
1263
-    public function get_image_size( $image_size ) {
1264
-
1265
-        // Only return sizes we define in settings
1266
-        if ( ! in_array( $image_size, array( 'course_archive_image', 'course_single_image', 'lesson_archive_image', 'lesson_single_image' ) ) )
1267
-            return apply_filters( 'sensei_get_image_size_' . $image_size, '' );
1268
-
1269
-        if( ! isset( $this->settings->settings[ $image_size . '_width' ] ) ) {
1270
-            $this->settings->settings[ $image_size . '_width' ] = false;
1271
-        }
1272
-        if( ! isset( $this->settings->settings[ $image_size . '_height' ] ) ) {
1273
-            $this->settings->settings[ $image_size . '_height' ] = false;
1274
-        }
1275
-        if( ! isset( $this->settings->settings[ $image_size . '_hard_crop' ] ) ) {
1276
-            $this->settings->settings[ $image_size . '_hard_crop' ] = false;
1277
-        }
1278
-
1279
-        $size = array_filter( array(
1280
-            'width' => $this->settings->settings[ $image_size . '_width' ],
1281
-            'height' => $this->settings->settings[ $image_size . '_height' ],
1282
-            'crop' => $this->settings->settings[ $image_size . '_hard_crop' ]
1283
-        ) );
1284
-
1285
-        $size['width'] 	= isset( $size['width'] ) ? $size['width'] : '100';
1286
-        $size['height'] = isset( $size['height'] ) ? $size['height'] : '100';
1287
-        $size['crop'] 	= isset( $size['crop'] ) ? $size['crop'] : 0;
1288
-
1289
-        return apply_filters( 'sensei_get_image_size_' . $image_size, $size );
1290
-    }
1291
-
1292
-    public function body_class( $classes ) {
1293
-        if( is_sensei() ) {
1294
-            $classes[] = 'sensei';
1295
-        }
1296
-        return $classes;
1297
-    }
1298
-
1299
-    /**
1300
-     * Checks that the Jetpack Beautiful Maths module has been activated to support LaTeX within question titles and answers
1301
-     *
1302
-     * @return null
1303
-     * @since 1.7.0
1304
-     */
1305
-    public function jetpack_latex_support() {
1306
-        if ( function_exists( 'latex_markup') ) {
1307
-            add_filter( 'sensei_question_title', 'latex_markup' );
1308
-            add_filter( 'sensei_answer_text', 'latex_markup' );
1309
-        }
1310
-    }
1311
-
1312
-    /**
1313
-     * Load the module functionality.
1314
-     *
1315
-     * This function is hooked into plugins_loaded to avoid conflicts with
1316
-     * the retired modules extension.
1317
-     *
1318
-     * @since 1.8.0
1319
-     */
1320
-    public function load_modules_class(){
1321
-        global $sensei_modules;
1322
-
1323
-        if( !class_exists( 'Sensei_Modules' )
1324
-            &&  'Sensei_Modules' != get_class( $sensei_modules ) ) {
1325
-
1326
-            //Load the modules class
1327
-            require_once( 'class-sensei-modules.php');
1328
-            Sensei()->modules = new Sensei_Core_Modules( $this->file );
1329
-
1330
-        }else{
1331
-            // fallback for people still using the modules extension.
1332
-            global $sensei_modules;
1333
-            Sensei()->modules = $sensei_modules;
1334
-            add_action( 'admin_notices', array( $this, 'disable_sensei_modules_extension'), 30 );
1335
-        }
1336
-    }
1337
-
1338
-    /**
1339
-     * Tell the user to that the modules extension is no longer needed.
1340
-     *
1341
-     * @since 1.8.0
1342
-     */
1343
-    public function disable_sensei_modules_extension(){ ?>
329
+	/**
330
+	 * Initialize all Sensei hooks
331
+	 *
332
+	 * @since 1.9.0
333
+	 */
334
+	public function load_hooks(){
335
+
336
+		add_action( 'widgets_init', array( $this, 'register_widgets' ) );
337
+		add_action( 'after_setup_theme', array( $this, 'ensure_post_thumbnails_support' ) );
338
+
339
+		// WooCommerce Payment Actions
340
+		add_action( 'woocommerce_payment_complete' , array( $this, 'sensei_woocommerce_complete_order' ) );
341
+		add_action( 'woocommerce_thankyou' , array( $this, 'sensei_woocommerce_complete_order' ) );
342
+		add_action( 'woocommerce_order_status_completed' , array( $this, 'sensei_woocommerce_complete_order' ) );
343
+		add_action( 'woocommerce_order_status_processing' , array( $this, 'sensei_woocommerce_complete_order' ) );
344
+		add_action( 'woocommerce_order_status_cancelled' , array( $this, 'sensei_woocommerce_cancel_order' ) );
345
+		add_action( 'woocommerce_order_status_refunded' , array( $this, 'sensei_woocommerce_cancel_order' ) );
346
+		add_action( 'subscriptions_activated_for_order', array( $this, 'sensei_activate_subscription' ) );
347
+
348
+		// WooCommerce Subscriptions Actions
349
+		add_action( 'reactivated_subscription', array( $this, 'sensei_woocommerce_reactivate_subscription' ), 10, 2 );
350
+		add_action( 'subscription_expired' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 );
351
+		add_action( 'subscription_end_of_prepaid_term' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 );
352
+		add_action( 'cancelled_subscription' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 );
353
+		add_action( 'subscription_put_on-hold' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 );
354
+
355
+		// Add Email link to course orders
356
+		add_action( 'woocommerce_email_after_order_table', array( $this, 'sensei_woocommerce_email_course_details' ), 10, 1 );
357
+
358
+		// Filter comment counts
359
+		add_filter( 'wp_count_comments', array( $this, 'sensei_count_comments' ), 10, 2 );
360
+
361
+		add_action( 'body_class', array( $this, 'body_class' ) );
362
+
363
+		// Check for and activate JetPack LaTeX support
364
+		add_action( 'plugins_loaded', array( $this, 'jetpack_latex_support'), 200 ); // Runs after Jetpack has loaded it's modules
365
+
366
+		// check flush the rewrite rules if the option sensei_flush_rewrite_rules option is 1
367
+		add_action( 'init', array( $this, 'flush_rewrite_rules'), 101 );
368
+
369
+	}
370
+
371
+	/**
372
+	 * Run Sensei updates.
373
+	 * @access  public
374
+	 * @since   1.1.0
375
+	 * @return  void
376
+	 */
377
+	public function run_updates() {
378
+		// Run updates if administrator
379
+		if ( current_user_can( 'manage_options' ) || current_user_can( 'manage_sensei' ) ) {
380
+
381
+			$this->updates->update();
382
+
383
+		} // End If Statement
384
+	} // End run_updates()
385
+
386
+
387
+
388
+	/**
389
+	 * Setup required WooCommerce settings.
390
+	 * @access  public
391
+	 * @since   1.1.0
392
+	 * @return  void
393
+	 */
394
+	public function set_woocommerce_functionality() {
395
+		// Disable guest checkout if a course is in the cart as we need a valid user to store data for
396
+		add_filter( 'pre_option_woocommerce_enable_guest_checkout', array( $this, 'disable_guest_checkout' ) );
397
+
398
+		// Mark orders with virtual products as complete rather then stay processing
399
+		add_filter( 'woocommerce_payment_complete_order_status', array( $this, 'virtual_order_payment_complete' ), 10, 2 );
400
+
401
+	} // End set_woocommerce_functionality()
402
+
403
+	/**
404
+	 * Disable guest checkout if a course product is in the cart
405
+	 * @param  boolean $guest_checkout Current guest checkout setting
406
+	 * @return boolean                 Modified guest checkout setting
407
+	 */
408
+	public function disable_guest_checkout( $guest_checkout ) {
409
+		global $woocommerce;
410
+
411
+		if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
412
+
413
+			if( isset( $woocommerce->cart->cart_contents ) && count( $woocommerce->cart->cart_contents ) > 0 ) {
414
+				foreach( $woocommerce->cart->cart_contents as $cart_key => $product ) {
415
+					if( isset( $product['product_id'] ) ) {
416
+						$args = array(
417
+							'posts_per_page' => -1,
418
+							'post_type' => 'course',
419
+							'meta_query' => array(
420
+								array(
421
+									'key' => '_course_woocommerce_product',
422
+									'value' => $product['product_id']
423
+								)
424
+							)
425
+						);
426
+						$posts = get_posts( $args );
427
+						if( $posts && count( $posts ) > 0 ) {
428
+							foreach( $posts as $course ) {
429
+								$guest_checkout = '';
430
+								break;
431
+							}
432
+						}
433
+					}
434
+				}
435
+			}
436
+		}
437
+
438
+		return $guest_checkout;
439
+	}
440
+
441
+	/**
442
+	 * Change order status with virtual products to completed
443
+	 * @since  1.1.0
444
+	 * @param string $order_status
445
+	 * @param int $order_id
446
+	 * @return string
447
+	 **/
448
+	public function virtual_order_payment_complete( $order_status, $order_id ) {
449
+		$order = new WC_Order( $order_id );
450
+		if ( ! isset ( $order ) ) return '';
451
+		if ( $order_status == 'wc-processing' && ( $order->post_status == 'wc-on-hold' || $order->post_status == 'wc-pending' || $order->post_status == 'wc-failed' ) ) {
452
+			$virtual_order = true;
453
+
454
+			if ( count( $order->get_items() ) > 0 ) {
455
+				foreach( $order->get_items() as $item ) {
456
+					if ( $item['product_id'] > 0 ) {
457
+						$_product = $order->get_product_from_item( $item );
458
+						if ( ! $_product->is_virtual() ) {
459
+							$virtual_order = false;
460
+							break;
461
+						} // End If Statement
462
+					} // End If Statement
463
+				} // End For Loop
464
+			} // End If Statement
465
+
466
+			// virtual order, mark as completed
467
+			if ( $virtual_order ) {
468
+				return 'completed';
469
+			} // End If Statement
470
+		} // End If Statement
471
+		return $order_status;
472
+	}
473
+
474
+	/**
475
+	 * Register the widgets.
476
+	 * @access public
477
+	 * @since  1.0.0
478
+	 * @return void
479
+	 */
480
+	public function register_widgets () {
481
+		// Widget List (key => value is filename => widget class).
482
+		$widget_list = apply_filters( 'sensei_registered_widgets_list', array( 	'course-component' 	=> 'Course_Component',
483
+				'lesson-component' 	=> 'Lesson_Component',
484
+				'course-categories' => 'Course_Categories',
485
+				'category-courses' 	=> 'Category_Courses' )
486
+		);
487
+		foreach ( $widget_list as $key => $value ) {
488
+			if ( file_exists( $this->plugin_path . 'widgets/widget-woothemes-sensei-' . $key  . '.php' ) ) {
489
+				require_once( $this->plugin_path . 'widgets/widget-woothemes-sensei-' . $key  . '.php' );
490
+				register_widget( 'WooThemes_Sensei_' . $value . '_Widget' );
491
+			}
492
+		} // End For Loop
493
+
494
+		do_action( 'sensei_register_widgets' );
495
+
496
+	} // End register_widgets()
497
+
498
+	/**
499
+	 * Load the plugin's localisation file.
500
+	 * @access public
501
+	 * @since  1.0.0
502
+	 * @return void
503
+	 */
504
+	public function load_localisation () {
505
+		load_plugin_textdomain( 'woothemes-sensei', false, dirname( plugin_basename( $this->file ) ) . '/lang/' );
506
+	} // End load_localisation()
507
+
508
+	/**
509
+	 * Load the plugin textdomain from the main WordPress "languages" folder.
510
+	 * @access  public
511
+	 * @since   1.0.0
512
+	 * @return  void
513
+	 */
514
+	public function load_plugin_textdomain () {
515
+		$domain = 'woothemes-sensei';
516
+		// The "plugin_locale" filter is also used in load_plugin_textdomain()
517
+		$locale = apply_filters( 'plugin_locale', get_locale(), $domain );
518
+		load_textdomain( $domain, WP_LANG_DIR . '/' . $domain . '/' . $domain . '-' . $locale . '.mo' );
519
+		load_plugin_textdomain( $domain, FALSE, dirname( plugin_basename( $this->file ) ) . '/lang/' );
520
+	} // End load_plugin_textdomain()
521
+
522
+	/**
523
+	 * Run on activation.
524
+	 * @access public
525
+	 * @since  1.0.0
526
+	 * @return void
527
+	 */
528
+	public function activation () {
529
+		$this->register_plugin_version();
530
+	} // End activation()
531
+
532
+
533
+	/**
534
+	 * Register activation hooks.
535
+	 * @access public
536
+	 * @since  1.0.0
537
+	 * @return void
538
+	 */
539
+	public function install () {
540
+		register_activation_hook( $this->file, array( $this, 'activate_sensei' ) );
541
+		register_activation_hook( $this->file, 'flush_rewrite_rules' );
542
+	} // End install()
543
+
544
+
545
+	/**
546
+	 * Run on activation of the plugin.
547
+	 * @access public
548
+	 * @since  1.0.0
549
+	 * @return void
550
+	 */
551
+	public function activate_sensei () {
552
+		update_option( 'skip_install_sensei_pages', 0 );
553
+		update_option( 'sensei_installed', 1 );
554
+	} // End activate_sensei()
555
+
556
+	/**
557
+	 * Register the plugin's version.
558
+	 * @access public
559
+	 * @since  1.0.0
560
+	 * @return void
561
+	 */
562
+	private function register_plugin_version () {
563
+		if ( $this->version != '' ) {
564
+
565
+			// Check previous version to see if forced updates must run
566
+			// $old_version = get_option( 'woothemes-sensei-version', false );
567
+			// if( $old_version && version_compare( $old_version, '1.7.0', '<' )  ) {
568
+			// 	update_option( 'woothemes-sensei-force-updates', $this->version );
569
+			// } else {
570
+			// 	delete_option( 'woothemes-sensei-force-updates' );
571
+			// }
572
+
573
+			update_option( 'woothemes-sensei-version', $this->version );
574
+		}
575
+	} // End register_plugin_version()
576
+
577
+	/**
578
+	 * Ensure that "post-thumbnails" support is available for those themes that don't register it.
579
+	 * @access  public
580
+	 * @since   1.0.1
581
+	 * @return  void
582
+	 */
583
+	public function ensure_post_thumbnails_support () {
584
+		if ( ! current_theme_supports( 'post-thumbnails' ) ) { add_theme_support( 'post-thumbnails' ); }
585
+	} // End ensure_post_thumbnails_support()
586
+
587
+
588
+	/**
589
+	 * template_loader function.
590
+	 *
591
+	 * @access public
592
+	 * @param mixed $template
593
+	 * @return void
594
+	 * @deprecated
595
+	 */
596
+	public function template_loader ( $template = '' ) {
597
+
598
+		_deprecated_function( 'Sensei()->template_loader', '1.9.0', 'Use Sensei_Templates::template_loader( $template ) instead' );
599
+		Sensei_Templates::template_loader( $template );
600
+
601
+	} // End template_loader()
602
+
603
+	/**
604
+	 * Determine the relative path to the plugin's directory.
605
+	 * @access public
606
+	 * @since  1.0.0
607
+	 * @return string $sensei_plugin_path
608
+	 */
609
+	public function plugin_path () {
610
+
611
+		if ( $this->plugin_path ) {
612
+
613
+			$sensei_plugin_path =  $this->plugin_path;
614
+
615
+		}else{
616
+
617
+			$sensei_plugin_path = plugin_dir_path( __FILE__ );
618
+
619
+		}
620
+
621
+		return $sensei_plugin_path;
622
+
623
+	} // End plugin_path()
624
+
625
+
626
+	/**
627
+	 * Retrieve the ID of a specified page setting.
628
+	 * @access public
629
+	 * @since  1.0.0
630
+	 * @param  string $page
631
+	 * @return int
632
+	 */
633
+	public function get_page_id ( $page ) {
634
+		$page = apply_filters( 'sensei_get_' . esc_attr( $page ) . '_page_id', get_option( 'sensei_' . esc_attr( $page ) . '_page_id' ) );
635
+		return ( $page ) ? $page : -1;
636
+	} // End get_page_id()
637
+
638
+
639
+	/**
640
+	 * If WooCommerce is activated and the customer has purchased the course, update Sensei to indicate that they are taking the course.
641
+	 * @access public
642
+	 * @since  1.0.0
643
+	 * @param  int 			$course_id  (default: 0)
644
+	 * @param  array/Object $order_user (default: array()) Specific user's data.
645
+	 * @return bool|int
646
+	 */
647
+	public function woocommerce_course_update ( $course_id = 0, $order_user = array()  ) {
648
+		global $current_user;
649
+
650
+		if ( ! isset( $current_user ) || !$current_user->ID > 0 ) return false;
651
+
652
+		$data_update = false;
653
+
654
+		// Get the product ID
655
+		$wc_post_id = get_post_meta( intval( $course_id ), '_course_woocommerce_product', true );
656
+
657
+		// Check if in the admin
658
+		if ( is_admin() ) {
659
+			$user_login = $order_user['user_login'];
660
+			$user_email = $order_user['user_email'];
661
+			$user_url = $order_user['user_url'];
662
+			$user_id = $order_user['ID'];
663
+		} else {
664
+			$user_login = $current_user->user_login;
665
+			$user_email = $current_user->user_email;
666
+			$user_url = $current_user->user_url;
667
+			$user_id = $current_user->ID;
668
+		} // End If Statement
669
+
670
+		// This doesn't appear to be purely WooCommerce related. Should it be in a separate function?
671
+		$course_prerequisite_id = (int) get_post_meta( $course_id, '_course_prerequisite', true );
672
+		if( 0 < absint( $course_prerequisite_id ) ) {
673
+			$prereq_course_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, intval( $user_id ) );
674
+			if ( ! $prereq_course_complete ) {
675
+				// Remove all course user meta
676
+				return Sensei_Utils::sensei_remove_user_from_course( $course_id, $user_id );
677
+			}
678
+		}
679
+
680
+		$is_user_taking_course = Sensei_Utils::user_started_course( intval( $course_id ), intval( $user_id ) );
681
+
682
+		if( ! $is_user_taking_course ) {
683
+
684
+			if ( Sensei_WC::is_woocommerce_active() && Sensei_Utils::sensei_customer_bought_product( $user_email, $user_id, $wc_post_id ) && ( 0 < $wc_post_id ) ) {
685
+
686
+				$activity_logged = Sensei_Utils::user_start_course( intval( $user_id), intval( $course_id ) );
687
+
688
+				$is_user_taking_course = false;
689
+				if ( true == $activity_logged ) {
690
+					$is_user_taking_course = true;
691
+				} // End If Statement
692
+			} // End If Statement
693
+		}
694
+
695
+		return $is_user_taking_course;
696
+	} // End woocommerce_course_update()
697
+
698
+
699
+	/**
700
+	 * check_user_permissions function.
701
+	 *
702
+	 * @access public
703
+	 * @param string $page (default: '')
704
+	 *
705
+	 * @return bool
706
+	 */
707
+	public function check_user_permissions ( $page = '' ) {
708
+		// REFACTOR
709
+		global $current_user, $post;
710
+
711
+		// if use is not logged in
712
+		// skipped for single lesson
713
+		if ( empty( $current_user->caps ) && Sensei()->settings->get('access_permission')
714
+			&& 'lesson-single' !=  $page ){
715
+			$this->permissions_message['title'] = __('Restricted Access', 'woothemes-sensei' );
716
+			$this->permissions_message['message'] = sprintf( __('You must be logged in to view this %s'), get_post_type() );
717
+			return false;
718
+		}
719
+
720
+		$user_allowed = false;
721
+
722
+		switch ( $page ) {
723
+			case 'course-single':
724
+				// check for prerequisite course or lesson,
725
+				$course_prerequisite_id = (int) get_post_meta( $post->ID, '_course_prerequisite', true);
726
+				$update_course = $this->woocommerce_course_update( $post->ID );
727
+				// Count completed lessons
728
+				if ( 0 < absint( $course_prerequisite_id ) ) {
729
+
730
+					$prerequisite_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, $current_user->ID );
731
+
732
+				}
733
+				else {
734
+					$prerequisite_complete = true;
735
+				} // End If Statement
736
+				// Handles restrictions
737
+				if ( !$prerequisite_complete && 0 < absint( $course_prerequisite_id ) ) {
738
+					$this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' );
739
+					$course_link = '<a href="' . esc_url( get_permalink( $course_prerequisite_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>';
740
+					$this->permissions_message['message'] = sprintf( __('Please complete the previous %1$s before taking this course.', 'woothemes-sensei' ), $course_link );
741
+				} else {
742
+					$user_allowed = true;
743
+				} // End If Statement
744
+				break;
745
+			case 'lesson-single':
746
+				// Check for WC purchase
747
+				$lesson_course_id = get_post_meta( $post->ID, '_lesson_course',true );
748
+
749
+				$update_course = $this->woocommerce_course_update( $lesson_course_id );
750
+				$is_preview = Sensei_Utils::is_preview_lesson( $post->ID );
751
+
752
+				if ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) {
753
+					$user_allowed = true;
754
+				} elseif( $this->access_settings() && false == $is_preview ) {
755
+
756
+					$user_allowed = true;
757
+
758
+				} else {
759
+					$this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' );
760
+					$course_link = '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>';
761
+					$wc_post_id = get_post_meta( $lesson_course_id, '_course_woocommerce_product',true );
762
+					if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) {
763
+						if ( $is_preview ) {
764
+							$this->permissions_message['message'] = sprintf( __('This is a preview lesson. Please purchase the %1$s to access all lessons.', 'woothemes-sensei' ), $course_link );
765
+						} else {
766
+							$this->permissions_message['message'] =  sprintf( __('Please purchase the %1$s before starting this Lesson.', 'woothemes-sensei' ), $course_link );
767
+						}
768
+					} else {
769
+						if ( $is_preview ) {
770
+							$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 );
771
+						} else {
772
+							/** This filter is documented in class-woothemes-sensei-frontend.php */
773
+							$this->permissions_message['message'] =  sprintf( __( 'Please sign up for the %1$s before starting the lesson.', 'woothemes-sensei' ), $course_link );
774
+						}
775
+					} // End If Statement
776
+				} // End If Statement
777
+				break;
778
+			case 'quiz-single':
779
+				$lesson_id = get_post_meta( $post->ID, '_quiz_lesson',true );
780
+				$lesson_course_id = get_post_meta( $lesson_id, '_lesson_course',true );
781
+
782
+				$update_course = $this->woocommerce_course_update( $lesson_course_id );
783
+				if ( ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) || sensei_all_access() ) {
784
+
785
+					// Check for prerequisite lesson for this quiz
786
+					$lesson_prerequisite_id = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true);
787
+					$user_lesson_prerequisite_complete = Sensei_Utils::user_completed_lesson( $lesson_prerequisite_id, $current_user->ID);
788
+
789
+					// Handle restrictions
790
+					if( sensei_all_access() ) {
791
+						$user_allowed = true;
792
+					} else {
793
+						if ( 0 < absint( $lesson_prerequisite_id ) && ( !$user_lesson_prerequisite_complete ) ) {
794
+							$this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' );
795
+							$lesson_link = '<a href="' . esc_url( get_permalink( $lesson_prerequisite_id ) ) . '">' . __( 'lesson', 'woothemes-sensei' ) . '</a>';
796
+							$this->permissions_message['message'] = sprintf( __('Please complete the previous %1$s before taking this Quiz.', 'woothemes-sensei' ), $lesson_link );
797
+						} else {
798
+							$user_allowed = true;
799
+						} // End If Statement
800
+					} // End If Statement
801
+				} elseif( $this->access_settings() ) {
802
+					// Check if the user has started the course
803
+
804
+					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'] ) ) ) {
805
+
806
+						$user_allowed = false;
807
+						$this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' );
808
+						$course_link = '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>';
809
+						$wc_post_id = get_post_meta( $lesson_course_id, '_course_woocommerce_product',true );
810
+						if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) {
811
+							$this->permissions_message['message'] = sprintf( __('Please purchase the %1$s before starting this Quiz.', 'woothemes-sensei' ), $course_link );
812
+						} else {
813
+							$this->permissions_message['message'] = sprintf( __('Please sign up for the %1$s before starting this Quiz.', 'woothemes-sensei' ), $course_link );
814
+						} // End If Statement
815
+					} else {
816
+						$user_allowed = true;
817
+					} // End If Statement
818
+				} else {
819
+					$this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' );
820
+					$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>';
821
+					$this->permissions_message['message'] = sprintf( __('Please sign up for the %1$s before taking this Quiz.', 'woothemes-sensei' ), $course_link );
822
+				} // End If Statement
823
+				break;
824
+			default:
825
+				$user_allowed = true;
826
+				break;
827
+
828
+		} // End Switch Statement
829
+
830
+		/**
831
+		 * filter the permissions message shown on sensei post types.
832
+		 *
833
+		 * @since 1.8.7
834
+		 *
835
+		 * @param array $permissions_message{
836
+		 *
837
+		 *   @type string $title
838
+		 *   @type string $message
839
+		 *
840
+		 * }
841
+		 * @param string $post_id
842
+		 */
843
+		$this->permissions_message = apply_filters( 'sensei_permissions_message', $this->permissions_message, $post->ID );
844
+
845
+
846
+		if( sensei_all_access() || Sensei_Utils::is_preview_lesson( $post->ID ) ) {
847
+			$user_allowed = true;
848
+		}
849
+
850
+		return apply_filters( 'sensei_access_permissions', $user_allowed );
851
+	} // End get_placeholder_image()
852
+
853
+
854
+	/**
855
+	 * Check if visitors have access permission. If the "access_permission" setting is active, do a log in check.
856
+	 * @since  1.0.0
857
+	 * @access public
858
+	 * @return bool
859
+	 */
860
+	public function access_settings () {
861
+
862
+		if( sensei_all_access() ) return true;
863
+
864
+		if ( isset( $this->settings->settings['access_permission'] ) && ( true == $this->settings->settings['access_permission'] ) ) {
865
+			if ( is_user_logged_in() ) {
866
+				return true;
867
+			} else {
868
+				return false;
869
+			} // End If Statement
870
+		} else {
871
+			return true;
872
+		} // End If Statement
873
+	} // End access_settings()
874
+
875
+	/**
876
+	 * sensei_woocommerce_complete_order description
877
+	 * @since   1.0.3
878
+	 * @access  public
879
+	 * @param   int $order_id WC order ID
880
+	 * @return  void
881
+	 */
882
+	public function sensei_woocommerce_complete_order ( $order_id = 0 ) {
883
+		$order_user = array();
884
+		// Check for WooCommerce
885
+		if ( Sensei_WC::is_woocommerce_active() && ( 0 < $order_id ) ) {
886
+			// Get order object
887
+			$order = new WC_Order( $order_id );
888
+			$user = get_user_by( 'id', $order->get_user_id() );
889
+			$order_user['ID'] = $user->ID;
890
+			$order_user['user_login'] = $user->user_login;
891
+			$order_user['user_email'] = $user->user_email;
892
+			$order_user['user_url'] = $user->user_url;
893
+			// Run through each product ordered
894
+			if ( 0 < sizeof( $order->get_items() ) ) {
895
+				foreach( $order->get_items() as $item ) {
896
+					$product_type = '';
897
+					if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
898
+						$item_id = $item['variation_id'];
899
+						$product_type = 'variation';
900
+					} else {
901
+						$item_id = $item['product_id'];
902
+					} // End If Statement
903
+					$_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type );
904
+					// Get courses that use the WC product
905
+					$courses = $this->post_types->course->get_product_courses( $_product->id );
906
+					// Loop and update those courses
907
+					foreach ( $courses as $course_item ) {
908
+						$update_course = $this->woocommerce_course_update( $course_item->ID, $order_user );
909
+					} // End For Loop
910
+				} // End For Loop
911
+			} // End If Statement
912
+			// Add meta to indicate that payment has been completed successfully
913
+			update_post_meta( $order_id, 'sensei_payment_complete', '1' );
914
+		} // End If Statement
915
+	} // End sensei_woocommerce_complete_order()
916
+
917
+	/**
918
+	 * Runs when an order is cancelled.
919
+	 * @since   1.2.0
920
+	 * @access  public
921
+	 * @param   integer $order_id order ID
922
+	 * @return  void
923
+	 */
924
+	public function sensei_woocommerce_cancel_order ( $order_id ) {
925
+
926
+		// Get order object
927
+		$order = new WC_Order( $order_id );
928
+
929
+		// Run through each product ordered
930
+		if ( 0 < sizeof( $order->get_items() ) ) {
931
+
932
+			// Get order user
933
+			$user_id = $order->__get( 'user_id' );
934
+
935
+			foreach( $order->get_items() as $item ) {
936
+
937
+				$product_type = '';
938
+				if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
939
+					$item_id = $item['variation_id'];
940
+					$product_type = 'variation';
941
+				} else {
942
+					$item_id = $item['product_id'];
943
+				} // End If Statement
944
+				$_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type );
945
+
946
+				// Get courses that use the WC product
947
+				$courses = array();
948
+				$courses = $this->post_types->course->get_product_courses( $item_id );
949
+
950
+				// Loop and update those courses
951
+				foreach ($courses as $course_item){
952
+					// Check and Remove course from courses user meta
953
+					$dataset_changes = Sensei_Utils::sensei_remove_user_from_course( $course_item->ID, $user_id );
954
+				} // End For Loop
955
+			} // End For Loop
956
+		} // End If Statement
957
+	} // End sensei_woocommerce_cancel_order()
958
+
959
+	/**
960
+	 * Runs when an subscription is cancelled or expires.
961
+	 * @since   1.3.3
962
+	 * @access  public
963
+	 * @param   integer $user_id User ID
964
+	 * @param   integer $subscription_key Subscription Unique Key
965
+	 * @return  void
966
+	 */
967
+	public function sensei_woocommerce_subscription_ended( $user_id, $subscription_key ) {
968
+		$subscription = WC_Subscriptions_Manager::get_users_subscription( $user_id, $subscription_key );
969
+		self::sensei_woocommerce_cancel_order( $subscription['order_id'] );
970
+	}
971
+
972
+	/**
973
+	 * Runs when an subscription is re-activated after suspension.
974
+	 * @since   1.3.3
975
+	 * @access  public
976
+	 * @param   integer $user_id User ID
977
+	 * @param   integer $subscription_key Subscription Unique Key
978
+	 * @return  void
979
+	 */
980
+	public function sensei_woocommerce_reactivate_subscription( $user_id, $subscription_key ) {
981
+		$subscription = WC_Subscriptions_Manager::get_users_subscription( $user_id, $subscription_key );
982
+		$order = new WC_Order( $subscription['order_id'] );
983
+		$user = get_user_by( 'id', $order->get_user_id() );
984
+		$order_user = array();
985
+		$order_user['ID'] = $user->ID;
986
+		$order_user['user_login'] = $user->user_login;
987
+		$order_user['user_email'] = $user->user_email;
988
+		$order_user['user_url'] = $user->user_url;
989
+		$courses = $this->post_types->course->get_product_courses( $subscription['product_id'] );
990
+		foreach ( $courses as $course_item ){
991
+			$update_course = $this->woocommerce_course_update( $course_item->ID, $order_user );
992
+		} // End For Loop
993
+	} // End sensei_woocommerce_reactivate_subscription
994
+
995
+	/**
996
+	 * Returns the WooCommerce Product Object
997
+	 *
998
+	 * The code caters for pre and post WooCommerce 2.2 installations.
999
+	 *
1000
+	 * @since   1.1.1
1001
+	 * @access  public
1002
+	 * @param   integer $wc_product_id Product ID or Variation ID
1003
+	 * @param   string  $product_type  '' or 'variation'
1004
+	 * @return   WC_Product $wc_product_object
1005
+	 */
1006
+	public function sensei_get_woocommerce_product_object ( $wc_product_id = 0, $product_type = '' ) {
1007
+
1008
+		$wc_product_object = false;
1009
+		if ( 0 < intval( $wc_product_id ) ) {
1010
+
1011
+			// Get the product
1012
+			if ( function_exists( 'wc_get_product' ) ) {
1013
+
1014
+				$wc_product_object = wc_get_product( $wc_product_id ); // Post WC 2.3
1015
+
1016
+			} elseif ( function_exists( 'get_product' ) ) {
1017
+
1018
+				$wc_product_object = get_product( $wc_product_id ); // Post WC 2.0
1019
+
1020
+			} else {
1021
+
1022
+				// Pre WC 2.0
1023
+				if ( 'variation' == $product_type || 'subscription_variation' == $product_type ) {
1024
+
1025
+					$wc_product_object = new WC_Product_Variation( $wc_product_id );
1026
+
1027
+				} else {
1028
+
1029
+					$wc_product_object = new WC_Product( $wc_product_id );
1030
+
1031
+				} // End If Statement
1032
+
1033
+			} // End If Statement
1034
+
1035
+		} // End If Statement
1036
+
1037
+		return $wc_product_object;
1038
+
1039
+	} // End sensei_get_woocommerce_product_object()
1040
+
1041
+	/**
1042
+	 * load_class loads in class files
1043
+	 * @since   1.2.0
1044
+	 * @access  public
1045
+	 * @return  void
1046
+	 */
1047
+	public function load_class ( $class_name = '' ) {
1048
+		if ( '' != $class_name && '' != $this->token ) {
1049
+			require_once( 'class-' . esc_attr( $this->token ) . '-' . esc_attr( $class_name ) . '.php' );
1050
+		} // End If Statement
1051
+	} // End load_class()
1052
+
1053
+	/**
1054
+	 * sensei_activate_subscription runs when a subscription product is purchased
1055
+	 * @since   1.2.0
1056
+	 * @access  public
1057
+	 * @param   integer $order_id order ID
1058
+	 * @return  void
1059
+	 */
1060
+	public function sensei_activate_subscription(  $order_id = 0 ) {
1061
+		if ( 0 < intval( $order_id ) ) {
1062
+			$order = new WC_Order( $order_id );
1063
+			$user = get_user_by('id', $order->user_id);
1064
+			$order_user['ID'] = $user->ID;
1065
+			$order_user['user_login'] = $user->user_login;
1066
+			$order_user['user_email'] = $user->user_email;
1067
+			$order_user['user_url'] = $user->user_url;
1068
+			// Run through each product ordered
1069
+			if (sizeof($order->get_items())>0) {
1070
+				foreach($order->get_items() as $item) {
1071
+					$product_type = '';
1072
+					if (isset($item['variation_id']) && $item['variation_id'] > 0) {
1073
+						$item_id = $item['variation_id'];
1074
+						$product_type = 'subscription_variation';
1075
+					} else {
1076
+						$item_id = $item['product_id'];
1077
+					} // End If Statement
1078
+					$_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type );
1079
+					// Get courses that use the WC product
1080
+					$courses = array();
1081
+					if ( $product_type == 'subscription_variation' ) {
1082
+						$courses = $this->post_types->course->get_product_courses( $item_id );
1083
+					} // End If Statement
1084
+					// Loop and update those courses
1085
+					foreach ($courses as $course_item){
1086
+						$update_course = $this->woocommerce_course_update( $course_item->ID, $order_user );
1087
+					} // End For Loop
1088
+				} // End For Loop
1089
+			} // End If Statement
1090
+		} // End If Statement
1091
+	} // End sensei_activate_subscription()
1092
+
1093
+	/**
1094
+	 * sensei_woocommerce_email_course_details adds detail to email
1095
+	 * @since   1.4.5
1096
+	 * @access  public
1097
+	 * @param   WC_Order $order
1098
+	 * @return  void
1099
+	 */
1100
+	public function sensei_woocommerce_email_course_details( $order ) {
1101
+		global $woocommerce;
1102
+
1103
+		// exit early if not wc-completed or wc-processing
1104
+		if( 'wc-completed' != $order->post_status
1105
+			&& 'wc-processing' != $order->post_status  ) {
1106
+			return;
1107
+		}
1108
+
1109
+		$order_items = $order->get_items();
1110
+		$order_id = $order->id;
1111
+
1112
+		//If object have items go through them all to find course
1113
+		if ( 0 < sizeof( $order_items ) ) {
1114
+
1115
+			$course_details_html =  '<h2>' . __( 'Course details', 'woothemes-sensei' ) . '</h2>';
1116
+			$order_contains_courses = false;
1117
+
1118
+
1119
+			foreach ( $order_items as $item ) {
1120
+
1121
+				$product_type = '';
1122
+				if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
1123
+					// If item has variation_id then its from variation
1124
+					$item_id = $item['variation_id'];
1125
+					$product_type = 'variation';
1126
+				} else {
1127
+					// If not its real product set its id to item_id
1128
+					$item_id = $item['product_id'];
1129
+				} // End If Statement
1130
+
1131
+				$user_id = get_post_meta( $order_id, '_customer_user', true );
1132
+
1133
+				if( $user_id ) {
1134
+
1135
+					// Get all courses for product
1136
+					$args = array(
1137
+						'posts_per_page' => -1,
1138
+						'post_type' => 'course',
1139
+						'meta_query' => array(
1140
+							array(
1141
+								'key' => '_course_woocommerce_product',
1142
+								'value' => $item_id
1143
+							)
1144
+						),
1145
+						'orderby' => 'menu_order date',
1146
+						'order' => 'ASC',
1147
+					);
1148
+					$courses = get_posts( $args );
1149
+
1150
+					if( $courses && count( $courses ) > 0 ) {
1151
+
1152
+						foreach( $courses as $course ) {
1153
+
1154
+							$title = $course->post_title;
1155
+							$permalink = get_permalink( $course->ID );
1156
+							$order_contains_courses = true;
1157
+							$course_details_html .=  '<p><strong>' . sprintf( __( 'View course: %1$s', 'woothemes-sensei' ), '</strong><a href="' . esc_url( $permalink ) . '">' . $title . '</a>' ) . '</p>';
1158
+						}
1159
+
1160
+
1161
+					} // end if has courses
1162
+
1163
+				} // end if $userPid
1164
+
1165
+			} // end for each order item
1166
+
1167
+			// Output Course details
1168
+			if( $order_contains_courses ){
1169
+
1170
+				echo $course_details_html;
1171
+
1172
+			}
1173
+
1174
+
1175
+		} // end if  order items not empty
1176
+
1177
+	} // end func email course details
1178
+
1179
+	/**
1180
+	 * Filtering wp_count_comments to ensure that Sensei comments are ignored
1181
+	 * @since   1.4.0
1182
+	 * @access  public
1183
+	 * @param  array   $comments
1184
+	 * @param  integer $post_id
1185
+	 * @return array
1186
+	 */
1187
+	public function sensei_count_comments( $comments, $post_id ) {
1188
+		global $wpdb;
1189
+
1190
+		$post_id = (int) $post_id;
1191
+
1192
+		$count = wp_cache_get("comments-{$post_id}", 'counts');
1193
+
1194
+		if ( false !== $count ) {
1195
+			return $count;
1196
+		}
1197
+
1198
+		$statuses = array( '' ); // Default to the WP normal comments
1199
+		$stati = $wpdb->get_results( "SELECT comment_type FROM {$wpdb->comments} GROUP BY comment_type", ARRAY_A );
1200
+		foreach ( (array) $stati AS $status ) {
1201
+			if ( 'sensei_' != substr($status['comment_type'], 0, 7 ) ) {
1202
+				$statuses[] = $status['comment_type'];
1203
+			}
1204
+		}
1205
+		$where = "WHERE comment_type IN ('" . join("', '", array_unique( $statuses ) ) . "')";
1206
+
1207
+		if ( $post_id > 0 )
1208
+			$where .= $wpdb->prepare( " AND comment_post_ID = %d", $post_id );
1209
+
1210
+		$count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A );
1211
+
1212
+		$total = 0;
1213
+		$approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash', 'post-trashed' => 'post-trashed');
1214
+		foreach ( (array) $count as $row ) {
1215
+			// Don't count post-trashed toward totals
1216
+			if ( 'post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'] )
1217
+				$total += $row['num_comments'];
1218
+			if ( isset( $approved[$row['comment_approved']] ) )
1219
+				$stats[$approved[$row['comment_approved']]] = $row['num_comments'];
1220
+		}
1221
+
1222
+		$stats['total_comments'] = $total;
1223
+		foreach ( $approved as $key ) {
1224
+			if ( empty($stats[$key]) )
1225
+				$stats[$key] = 0;
1226
+		}
1227
+
1228
+		$stats = (object) $stats;
1229
+		wp_cache_set("comments-{$post_id}", $stats, 'counts');
1230
+
1231
+		return $stats;
1232
+	}
1233
+
1234
+	/**
1235
+	 * Init images.
1236
+	 *
1237
+	 * @since 1.4.5
1238
+	 * @access public
1239
+	 * @return void
1240
+	 */
1241
+	public function init_image_sizes() {
1242
+		$course_archive_thumbnail 	= $this->get_image_size( 'course_archive_image' );
1243
+		$course_single_thumbnail	= $this->get_image_size( 'course_single_image' );
1244
+		$lesson_archive_thumbnail 	= $this->get_image_size( 'lesson_archive_image' );
1245
+		$lesson_single_thumbnail	= $this->get_image_size( 'lesson_single_image' );
1246
+
1247
+		add_image_size( 'course_archive_thumbnail', $course_archive_thumbnail['width'], $course_archive_thumbnail['height'], $course_archive_thumbnail['crop'] );
1248
+		add_image_size( 'course_single_thumbnail', $course_single_thumbnail['width'], $course_single_thumbnail['height'], $course_single_thumbnail['crop'] );
1249
+		add_image_size( 'lesson_archive_thumbnail', $lesson_archive_thumbnail['width'], $lesson_archive_thumbnail['height'], $lesson_archive_thumbnail['crop'] );
1250
+		add_image_size( 'lesson_single_thumbnail', $lesson_single_thumbnail['width'], $lesson_single_thumbnail['height'], $lesson_single_thumbnail['crop'] );
1251
+	}
1252
+
1253
+	/**
1254
+	 * Get an image size.
1255
+	 *
1256
+	 * Variable is filtered by sensei_get_image_size_{image_size}
1257
+	 *
1258
+	 * @since 1.4.5
1259
+	 * @access public
1260
+	 * @param mixed $image_size
1261
+	 * @return string
1262
+	 */
1263
+	public function get_image_size( $image_size ) {
1264
+
1265
+		// Only return sizes we define in settings
1266
+		if ( ! in_array( $image_size, array( 'course_archive_image', 'course_single_image', 'lesson_archive_image', 'lesson_single_image' ) ) )
1267
+			return apply_filters( 'sensei_get_image_size_' . $image_size, '' );
1268
+
1269
+		if( ! isset( $this->settings->settings[ $image_size . '_width' ] ) ) {
1270
+			$this->settings->settings[ $image_size . '_width' ] = false;
1271
+		}
1272
+		if( ! isset( $this->settings->settings[ $image_size . '_height' ] ) ) {
1273
+			$this->settings->settings[ $image_size . '_height' ] = false;
1274
+		}
1275
+		if( ! isset( $this->settings->settings[ $image_size . '_hard_crop' ] ) ) {
1276
+			$this->settings->settings[ $image_size . '_hard_crop' ] = false;
1277
+		}
1278
+
1279
+		$size = array_filter( array(
1280
+			'width' => $this->settings->settings[ $image_size . '_width' ],
1281
+			'height' => $this->settings->settings[ $image_size . '_height' ],
1282
+			'crop' => $this->settings->settings[ $image_size . '_hard_crop' ]
1283
+		) );
1284
+
1285
+		$size['width'] 	= isset( $size['width'] ) ? $size['width'] : '100';
1286
+		$size['height'] = isset( $size['height'] ) ? $size['height'] : '100';
1287
+		$size['crop'] 	= isset( $size['crop'] ) ? $size['crop'] : 0;
1288
+
1289
+		return apply_filters( 'sensei_get_image_size_' . $image_size, $size );
1290
+	}
1291
+
1292
+	public function body_class( $classes ) {
1293
+		if( is_sensei() ) {
1294
+			$classes[] = 'sensei';
1295
+		}
1296
+		return $classes;
1297
+	}
1298
+
1299
+	/**
1300
+	 * Checks that the Jetpack Beautiful Maths module has been activated to support LaTeX within question titles and answers
1301
+	 *
1302
+	 * @return null
1303
+	 * @since 1.7.0
1304
+	 */
1305
+	public function jetpack_latex_support() {
1306
+		if ( function_exists( 'latex_markup') ) {
1307
+			add_filter( 'sensei_question_title', 'latex_markup' );
1308
+			add_filter( 'sensei_answer_text', 'latex_markup' );
1309
+		}
1310
+	}
1311
+
1312
+	/**
1313
+	 * Load the module functionality.
1314
+	 *
1315
+	 * This function is hooked into plugins_loaded to avoid conflicts with
1316
+	 * the retired modules extension.
1317
+	 *
1318
+	 * @since 1.8.0
1319
+	 */
1320
+	public function load_modules_class(){
1321
+		global $sensei_modules;
1322
+
1323
+		if( !class_exists( 'Sensei_Modules' )
1324
+			&&  'Sensei_Modules' != get_class( $sensei_modules ) ) {
1325
+
1326
+			//Load the modules class
1327
+			require_once( 'class-sensei-modules.php');
1328
+			Sensei()->modules = new Sensei_Core_Modules( $this->file );
1329
+
1330
+		}else{
1331
+			// fallback for people still using the modules extension.
1332
+			global $sensei_modules;
1333
+			Sensei()->modules = $sensei_modules;
1334
+			add_action( 'admin_notices', array( $this, 'disable_sensei_modules_extension'), 30 );
1335
+		}
1336
+	}
1337
+
1338
+	/**
1339
+	 * Tell the user to that the modules extension is no longer needed.
1340
+	 *
1341
+	 * @since 1.8.0
1342
+	 */
1343
+	public function disable_sensei_modules_extension(){ ?>
1344 1344
         <div class="notice updated fade">
1345 1345
             <p>
1346 1346
                 <?php
1347
-                $plugin_manage_url = admin_url().'plugins.php#sensei-modules';
1348
-                $plugin_link_element = '<a href="' . $plugin_manage_url . '" >plugins page</a> ';
1349
-                ?>
1347
+				$plugin_manage_url = admin_url().'plugins.php#sensei-modules';
1348
+				$plugin_link_element = '<a href="' . $plugin_manage_url . '" >plugins page</a> ';
1349
+				?>
1350 1350
                 <strong> Modules are now included in Sensei,</strong> so you no longer need the Sensei Modules extension.
1351 1351
                 Please deactivate and delete it from your <?php echo $plugin_link_element; ?>. (This will not affect your existing modules).
1352 1352
             </p>
@@ -1354,46 +1354,46 @@  discard block
 block discarded – undo
1354 1354
 
1355 1355
     <?php }// end function
1356 1356
 
1357
-    /**
1358
-     * Sensei wide rewrite flush call.
1359
-     *
1360
-     * To use this simply update the option 'sensei_flush_rewrite_rules' to 1
1361
-     *
1362
-     * After the option is one the Rules will be flushed.
1363
-     *
1364
-     * @since 1.9.0
1365
-     */
1366
-    public function flush_rewrite_rules(){
1357
+	/**
1358
+	 * Sensei wide rewrite flush call.
1359
+	 *
1360
+	 * To use this simply update the option 'sensei_flush_rewrite_rules' to 1
1361
+	 *
1362
+	 * After the option is one the Rules will be flushed.
1363
+	 *
1364
+	 * @since 1.9.0
1365
+	 */
1366
+	public function flush_rewrite_rules(){
1367 1367
 
1368
-        // ensures that the rewrite rules are flushed on the second
1369
-        // attempt. This ensure that the settings for any other process
1370
-        // have been completed and saved to the database before we refresh the
1371
-        // rewrite rules.
1372
-        $option =  get_option('sensei_flush_rewrite_rules');
1373
-        if( '1' == $option ) {
1368
+		// ensures that the rewrite rules are flushed on the second
1369
+		// attempt. This ensure that the settings for any other process
1370
+		// have been completed and saved to the database before we refresh the
1371
+		// rewrite rules.
1372
+		$option =  get_option('sensei_flush_rewrite_rules');
1373
+		if( '1' == $option ) {
1374 1374
 
1375
-            update_option('sensei_flush_rewrite_rules', '2');
1375
+			update_option('sensei_flush_rewrite_rules', '2');
1376 1376
 
1377
-        }elseif( '2' == $option ) {
1377
+		}elseif( '2' == $option ) {
1378 1378
 
1379
-            flush_rewrite_rules();
1380
-            update_option('sensei_flush_rewrite_rules', '0');
1379
+			flush_rewrite_rules();
1380
+			update_option('sensei_flush_rewrite_rules', '0');
1381 1381
 
1382
-        }
1382
+		}
1383 1383
 
1384
-    } // end flush_rewrite_rules
1384
+	} // end flush_rewrite_rules
1385 1385
 
1386
-    /**
1387
-     * Calling this function will tell Sensei to flush rewrite
1388
-     * rules on the next load.
1389
-     *
1390
-     * @since 1.9.0
1391
-     */
1392
-    public function initiate_rewrite_rules_flush(){
1386
+	/**
1387
+	 * Calling this function will tell Sensei to flush rewrite
1388
+	 * rules on the next load.
1389
+	 *
1390
+	 * @since 1.9.0
1391
+	 */
1392
+	public function initiate_rewrite_rules_flush(){
1393 1393
 
1394
-        update_option('sensei_flush_rewrite_rules', '1');
1394
+		update_option('sensei_flush_rewrite_rules', '1');
1395 1395
 
1396
-    }
1396
+	}
1397 1397
 
1398 1398
 } // End Class
1399 1399
 
Please login to merge, or discard this patch.
includes/theme-integrations/theme-integration-loader.php 2 patches
Indentation   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -10,91 +10,91 @@
 block discarded – undo
10 10
  */
11 11
 class Sensei_Theme_Integration_Loader {
12 12
 
13
-    /**
14
-     * @var array
15
-     * Holding a reference core supported themes
16
-     */
17
-    protected $themes;
18
-
19
-    /**
20
-     * @var string
21
-     * reference to the theme currently active on this site
22
-     */
23
-    protected $active_theme;
24
-
25
-    public function __construct() {
26
-
27
-        $this->setup_themes();
28
-        $this->setup_currently_active_theme();
29
-        $this->possibly_load_supported_theme_wrappers();
30
-
31
-    }
32
-
33
-    /**
34
-     * Setup the theme slugs supported by Sensei Core
35
-     *
36
-     * @since 1.9.0
37
-     */
38
-    private function setup_themes(){
39
-
40
-        $this->themes = array(
41
-            'twentyeleven',
42
-            'twentytwelve',
43
-            'twentythirteen',
44
-            'twentyfourteen',
45
-            'twentyfifteen',
46
-            'twentysixteen',
47
-            'storefront',
48
-        );
49
-
50
-    }// end setup themes
51
-
52
-    /**
53
-     * Setup the currently active theme
54
-     *
55
-     * @since 1.9.0
56
-     */
57
-    private function setup_currently_active_theme(){
58
-
59
-        $this->active_theme = get_option('template');
60
-
61
-    }
62
-
63
-    /**
64
-     * Remove default Sensei wrappers and load
65
-     * supported wrappers if the current theme is
66
-     * a theme we have an integration for within core.
67
-     *
68
-     * @since 1.9.0
69
-     */
70
-    private function possibly_load_supported_theme_wrappers(){
71
-
72
-        if ( in_array( $this->active_theme, $this->themes ) ){
73
-
74
-            // setup file and class names
75
-            $supported_theme_class_file = trailingslashit( Sensei()->plugin_path ) . 'includes/theme-integrations/' . $this->active_theme . '.php';
76
-            $supported_theme_class_name  = 'Sensei_'. ucfirst( $this->active_theme  );
77
-
78
-            // load the file or exit if there is no file for this theme
79
-            if( ! file_exists( $supported_theme_class_file ) ){
80
-                return;
81
-            }
82
-            include_once( $supported_theme_class_file );
83
-            include_once( 'twentytwelve.php' );
84
-            //initialize the class or exit if there is no class for this theme
85
-            if( ! class_exists( $supported_theme_class_name ) ){
86
-                return;
87
-            }
88
-            $supported_theme = new $supported_theme_class_name;
89
-
90
-            // remove default wrappers
91
-            remove_action( 'sensei_before_main_content', array( Sensei()->frontend, 'sensei_output_content_wrapper' ), 10 );
92
-            remove_action( 'sensei_after_main_content', array( Sensei()->frontend, 'sensei_output_content_wrapper_end' ), 10 );
93
-
94
-            // load the supported theme wrappers
95
-            add_action( 'sensei_before_main_content', array( $supported_theme, 'wrapper_start' ), 10 );
96
-            add_action( 'sensei_after_main_content', array( $supported_theme, 'wrapper_end' ), 10 );
97
-        }
98
-    }
13
+	/**
14
+	 * @var array
15
+	 * Holding a reference core supported themes
16
+	 */
17
+	protected $themes;
18
+
19
+	/**
20
+	 * @var string
21
+	 * reference to the theme currently active on this site
22
+	 */
23
+	protected $active_theme;
24
+
25
+	public function __construct() {
26
+
27
+		$this->setup_themes();
28
+		$this->setup_currently_active_theme();
29
+		$this->possibly_load_supported_theme_wrappers();
30
+
31
+	}
32
+
33
+	/**
34
+	 * Setup the theme slugs supported by Sensei Core
35
+	 *
36
+	 * @since 1.9.0
37
+	 */
38
+	private function setup_themes(){
39
+
40
+		$this->themes = array(
41
+			'twentyeleven',
42
+			'twentytwelve',
43
+			'twentythirteen',
44
+			'twentyfourteen',
45
+			'twentyfifteen',
46
+			'twentysixteen',
47
+			'storefront',
48
+		);
49
+
50
+	}// end setup themes
51
+
52
+	/**
53
+	 * Setup the currently active theme
54
+	 *
55
+	 * @since 1.9.0
56
+	 */
57
+	private function setup_currently_active_theme(){
58
+
59
+		$this->active_theme = get_option('template');
60
+
61
+	}
62
+
63
+	/**
64
+	 * Remove default Sensei wrappers and load
65
+	 * supported wrappers if the current theme is
66
+	 * a theme we have an integration for within core.
67
+	 *
68
+	 * @since 1.9.0
69
+	 */
70
+	private function possibly_load_supported_theme_wrappers(){
71
+
72
+		if ( in_array( $this->active_theme, $this->themes ) ){
73
+
74
+			// setup file and class names
75
+			$supported_theme_class_file = trailingslashit( Sensei()->plugin_path ) . 'includes/theme-integrations/' . $this->active_theme . '.php';
76
+			$supported_theme_class_name  = 'Sensei_'. ucfirst( $this->active_theme  );
77
+
78
+			// load the file or exit if there is no file for this theme
79
+			if( ! file_exists( $supported_theme_class_file ) ){
80
+				return;
81
+			}
82
+			include_once( $supported_theme_class_file );
83
+			include_once( 'twentytwelve.php' );
84
+			//initialize the class or exit if there is no class for this theme
85
+			if( ! class_exists( $supported_theme_class_name ) ){
86
+				return;
87
+			}
88
+			$supported_theme = new $supported_theme_class_name;
89
+
90
+			// remove default wrappers
91
+			remove_action( 'sensei_before_main_content', array( Sensei()->frontend, 'sensei_output_content_wrapper' ), 10 );
92
+			remove_action( 'sensei_after_main_content', array( Sensei()->frontend, 'sensei_output_content_wrapper_end' ), 10 );
93
+
94
+			// load the supported theme wrappers
95
+			add_action( 'sensei_before_main_content', array( $supported_theme, 'wrapper_start' ), 10 );
96
+			add_action( 'sensei_after_main_content', array( $supported_theme, 'wrapper_end' ), 10 );
97
+		}
98
+	}
99 99
 
100 100
 } /// end class
101 101
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
      *
36 36
      * @since 1.9.0
37 37
      */
38
-    private function setup_themes(){
38
+    private function setup_themes() {
39 39
 
40 40
         $this->themes = array(
41 41
             'twentyeleven',
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
      *
55 55
      * @since 1.9.0
56 56
      */
57
-    private function setup_currently_active_theme(){
57
+    private function setup_currently_active_theme() {
58 58
 
59 59
         $this->active_theme = get_option('template');
60 60
 
@@ -67,33 +67,33 @@  discard block
 block discarded – undo
67 67
      *
68 68
      * @since 1.9.0
69 69
      */
70
-    private function possibly_load_supported_theme_wrappers(){
70
+    private function possibly_load_supported_theme_wrappers() {
71 71
 
72
-        if ( in_array( $this->active_theme, $this->themes ) ){
72
+        if (in_array($this->active_theme, $this->themes)) {
73 73
 
74 74
             // setup file and class names
75
-            $supported_theme_class_file = trailingslashit( Sensei()->plugin_path ) . 'includes/theme-integrations/' . $this->active_theme . '.php';
76
-            $supported_theme_class_name  = 'Sensei_'. ucfirst( $this->active_theme  );
75
+            $supported_theme_class_file = trailingslashit(Sensei()->plugin_path).'includes/theme-integrations/'.$this->active_theme.'.php';
76
+            $supported_theme_class_name = 'Sensei_'.ucfirst($this->active_theme);
77 77
 
78 78
             // load the file or exit if there is no file for this theme
79
-            if( ! file_exists( $supported_theme_class_file ) ){
79
+            if ( ! file_exists($supported_theme_class_file)) {
80 80
                 return;
81 81
             }
82
-            include_once( $supported_theme_class_file );
83
-            include_once( 'twentytwelve.php' );
82
+            include_once($supported_theme_class_file);
83
+            include_once('twentytwelve.php');
84 84
             //initialize the class or exit if there is no class for this theme
85
-            if( ! class_exists( $supported_theme_class_name ) ){
85
+            if ( ! class_exists($supported_theme_class_name)) {
86 86
                 return;
87 87
             }
88 88
             $supported_theme = new $supported_theme_class_name;
89 89
 
90 90
             // remove default wrappers
91
-            remove_action( 'sensei_before_main_content', array( Sensei()->frontend, 'sensei_output_content_wrapper' ), 10 );
92
-            remove_action( 'sensei_after_main_content', array( Sensei()->frontend, 'sensei_output_content_wrapper_end' ), 10 );
91
+            remove_action('sensei_before_main_content', array(Sensei()->frontend, 'sensei_output_content_wrapper'), 10);
92
+            remove_action('sensei_after_main_content', array(Sensei()->frontend, 'sensei_output_content_wrapper_end'), 10);
93 93
 
94 94
             // load the supported theme wrappers
95
-            add_action( 'sensei_before_main_content', array( $supported_theme, 'wrapper_start' ), 10 );
96
-            add_action( 'sensei_after_main_content', array( $supported_theme, 'wrapper_end' ), 10 );
95
+            add_action('sensei_before_main_content', array($supported_theme, 'wrapper_start'), 10);
96
+            add_action('sensei_after_main_content', array($supported_theme, 'wrapper_end'), 10);
97 97
         }
98 98
     }
99 99
 
Please login to merge, or discard this patch.
includes/theme-integrations/twentyfourteen.php 2 patches
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -9,12 +9,12 @@  discard block
 block discarded – undo
9 9
 */
10 10
 Class Sensei_Twentyfourteen {
11 11
 
12
-    /**
13
-     * Output opening wrappers
14
-     * @since 1.9.0
15
-     */
16
-    public function wrapper_start(){
17
-    ?>
12
+	/**
13
+	 * Output opening wrappers
14
+	 * @since 1.9.0
15
+	 */
16
+	public function wrapper_start(){
17
+	?>
18 18
 
19 19
         <div id="main-content" class="main-content">
20 20
             <div id="primary" class="content-area">
@@ -23,12 +23,12 @@  discard block
 block discarded – undo
23 23
 
24 24
     <?php }
25 25
 
26
-    /**
27
-     * Output closing wrappers
28
-     *
29
-     * @since 1.9.0
30
-     */
31
-    public function wrapper_end(){ ?>
26
+	/**
27
+	 * Output closing wrappers
28
+	 *
29
+	 * @since 1.9.0
30
+	 */
31
+	public function wrapper_end(){ ?>
32 32
 
33 33
 
34 34
                     </div>
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
         </div>
38 38
 
39 39
         <?php
40
-        get_sidebar();
40
+		get_sidebar();
41 41
 	 }
42 42
 
43 43
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
      * Output opening wrappers
14 14
      * @since 1.9.0
15 15
      */
16
-    public function wrapper_start(){
16
+    public function wrapper_start() {
17 17
     ?>
18 18
 
19 19
         <div id="primary" class="site-content">
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
      *
27 27
      * @since 1.9.0
28 28
      */
29
-    public function wrapper_end(){ ?>
29
+    public function wrapper_end() { ?>
30 30
 
31 31
 			</div>
32 32
 		</div>
Please login to merge, or discard this patch.
includes/theme-integrations/twentyfifteen.php 2 patches
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -9,28 +9,28 @@
 block discarded – undo
9 9
 */
10 10
 Class Sensei_Twentyfifteen extends Sensei__S {
11 11
 
12
-    /**
13
-     * Output opening wrappers
14
-     * @since 1.9.0
15
-     */
16
-    public function wrapper_start(){
12
+	/**
13
+	 * Output opening wrappers
14
+	 * @since 1.9.0
15
+	 */
16
+	public function wrapper_start(){
17 17
 
18
-        // output inline styles
19
-        $this->print_styles();
18
+		// output inline styles
19
+		$this->print_styles();
20 20
 
21
-        // call the parent starting wrappers
22
-        parent::wrapper_start();
21
+		// call the parent starting wrappers
22
+		parent::wrapper_start();
23 23
 
24
-    }
24
+	}
25 25
 
26 26
 
27
-    /**
28
-     * Output the style for the
29
-     * twenty fifteen theme integration.
30
-     *
31
-     * @since 1.9.0
32
-     */
33
-    private function print_styles(){?>
27
+	/**
28
+	 * Output the style for the
29
+	 * twenty fifteen theme integration.
30
+	 *
31
+	 * @since 1.9.0
32
+	 */
33
+	private function print_styles(){?>
34 34
 
35 35
         <style>
36 36
             @media screen and (min-width: 59.6875em){
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
      * Output opening wrappers
14 14
      * @since 1.9.0
15 15
      */
16
-    public function wrapper_start(){
16
+    public function wrapper_start() {
17 17
 
18 18
         // output inline styles
19 19
         $this->print_styles();
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
      *
31 31
      * @since 1.9.0
32 32
      */
33
-    private function print_styles(){?>
33
+    private function print_styles() {?>
34 34
 
35 35
         <style>
36 36
             @media screen and (min-width: 59.6875em){
Please login to merge, or discard this patch.
includes/theme-integrations/_s.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
      * Output opening wrappers
14 14
      * @since 1.9.0
15 15
      */
16
-    public function wrapper_start(){ ?>
16
+    public function wrapper_start() { ?>
17 17
         <div id="primary" class="content-area">
18 18
             <main id="main" class="site-main" role="main">
19 19
 
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
      *
25 25
      * @since 1.9.0
26 26
      */
27
-    public function wrapper_end(){ ?>
27
+    public function wrapper_end() { ?>
28 28
 
29 29
             </main> <!-- main-site -->
30 30
           </div> <!-- content-area -->
Please login to merge, or discard this patch.
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -1,42 +1,42 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * Class Sensei__S
4
- *
5
- * Responsible for wrapping for the underscores theme
6
- * with the correct markup
7
- *
8
- *
9
- * @package Views
10
- * @subpackage Theme-Integration
11
- * @author Automattic
12
- *
13
- * @since 1.9.0
3
+	 * Class Sensei__S
4
+	 *
5
+	 * Responsible for wrapping for the underscores theme
6
+	 * with the correct markup
7
+	 *
8
+	 *
9
+	 * @package Views
10
+	 * @subpackage Theme-Integration
11
+	 * @author Automattic
12
+	 *
13
+	 * @since 1.9.0
14 14
 */
15 15
 Class Sensei__S {
16 16
 
17
-    /**
18
-     * Output opening wrappers
19
-     * @since 1.9.0
20
-     */
21
-    public function wrapper_start(){ ?>
17
+	/**
18
+	 * Output opening wrappers
19
+	 * @since 1.9.0
20
+	 */
21
+	public function wrapper_start(){ ?>
22 22
         <div id="primary" class="content-area">
23 23
             <main id="main" class="site-main" role="main">
24 24
 
25 25
     <?php }
26 26
 
27
-    /**
28
-     * Output closing wrappers
29
-     *
30
-     * @since 1.9.0
31
-     */
32
-    public function wrapper_end(){ ?>
27
+	/**
28
+	 * Output closing wrappers
29
+	 *
30
+	 * @since 1.9.0
31
+	 */
32
+	public function wrapper_end(){ ?>
33 33
 
34 34
             </main> <!-- main-site -->
35 35
           </div> <!-- content-area -->
36 36
 
37 37
 	    <?php
38 38
 
39
-        get_sidebar();
39
+		get_sidebar();
40 40
 
41
-    }
41
+	}
42 42
 } // end class
Please login to merge, or discard this patch.
includes/theme-integrations/twentythirteen.php 2 patches
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -9,24 +9,24 @@
 block discarded – undo
9 9
 */
10 10
 Class Sensei_Twentythirteen {
11 11
 
12
-    /**
13
-     * Output opening wrappers
14
-     * @since 1.9.0
15
-     */
16
-    public function wrapper_start(){
17
-    ?>
12
+	/**
13
+	 * Output opening wrappers
14
+	 * @since 1.9.0
15
+	 */
16
+	public function wrapper_start(){
17
+	?>
18 18
 
19 19
         <div id="primary" class="site-content">
20 20
             <div id="content" role="main" class="entry-content">
21 21
 
22 22
     <?php }
23 23
 
24
-    /**
25
-     * Output closing wrappers
26
-     *
27
-     * @since 1.9.0
28
-     */
29
-    public function wrapper_end(){ ?>
24
+	/**
25
+	 * Output closing wrappers
26
+	 *
27
+	 * @since 1.9.0
28
+	 */
29
+	public function wrapper_end(){ ?>
30 30
 
31 31
 			</div>
32 32
 		</div>
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
      * Output opening wrappers
14 14
      * @since 1.9.0
15 15
      */
16
-    public function wrapper_start(){
16
+    public function wrapper_start() {
17 17
     ?>
18 18
 
19 19
         <div id="primary" class="site-content">
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
      *
27 27
      * @since 1.9.0
28 28
      */
29
-    public function wrapper_end(){ ?>
29
+    public function wrapper_end() { ?>
30 30
 
31 31
 			</div>
32 32
 		</div>
Please login to merge, or discard this patch.
includes/theme-integrations/twentysixteen.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -7,4 +7,4 @@
 block discarded – undo
7 7
  *
8 8
  * @since 1.9.0
9 9
 */
10
-Class Sensei_Twentysixteen extends Sensei__S{ }
10
+Class Sensei_Twentysixteen extends Sensei__S { }
Please login to merge, or discard this patch.
includes/theme-integrations/twentyeleven.php 2 patches
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -9,24 +9,24 @@
 block discarded – undo
9 9
 */
10 10
 Class Sensei_Twentythirteen {
11 11
 
12
-    /**
13
-     * Output opening wrappers
14
-     * @since 1.9.0
15
-     */
16
-    public function wrapper_start(){
17
-    ?>
12
+	/**
13
+	 * Output opening wrappers
14
+	 * @since 1.9.0
15
+	 */
16
+	public function wrapper_start(){
17
+	?>
18 18
 
19 19
         <div id="primary" class="site-content">
20 20
             <div id="content" role="main" class="entry-content">
21 21
 
22 22
     <?php }
23 23
 
24
-    /**
25
-     * Output closing wrappers
26
-     *
27
-     * @since 1.9.0
28
-     */
29
-    public function wrapper_end(){ ?>
24
+	/**
25
+	 * Output closing wrappers
26
+	 *
27
+	 * @since 1.9.0
28
+	 */
29
+	public function wrapper_end(){ ?>
30 30
 
31 31
 			</div>
32 32
 		</div>
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
      * Output opening wrappers
14 14
      * @since 1.9.0
15 15
      */
16
-    public function wrapper_start(){
16
+    public function wrapper_start() {
17 17
     ?>
18 18
 
19 19
         <div id="primary" class="site-content">
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
      *
27 27
      * @since 1.9.0
28 28
      */
29
-    public function wrapper_end(){ ?>
29
+    public function wrapper_end() { ?>
30 30
 
31 31
 			</div>
32 32
 		</div>
Please login to merge, or discard this patch.
includes/theme-integrations/twentytwelve.php 2 patches
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -9,24 +9,24 @@
 block discarded – undo
9 9
 */
10 10
 Class Sensei_Twentythirteen {
11 11
 
12
-    /**
13
-     * Output opening wrappers
14
-     * @since 1.9.0
15
-     */
16
-    public function wrapper_start(){
17
-    ?>
12
+	/**
13
+	 * Output opening wrappers
14
+	 * @since 1.9.0
15
+	 */
16
+	public function wrapper_start(){
17
+	?>
18 18
 
19 19
         <div id="primary" class="site-content">
20 20
             <div id="content" role="main" class="entry-content">
21 21
 
22 22
     <?php }
23 23
 
24
-    /**
25
-     * Output closing wrappers
26
-     *
27
-     * @since 1.9.0
28
-     */
29
-    public function wrapper_end(){ ?>
24
+	/**
25
+	 * Output closing wrappers
26
+	 *
27
+	 * @since 1.9.0
28
+	 */
29
+	public function wrapper_end(){ ?>
30 30
 
31 31
 			</div>
32 32
 		</div>
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
      * Output opening wrappers
14 14
      * @since 1.9.0
15 15
      */
16
-    public function wrapper_start(){
16
+    public function wrapper_start() {
17 17
     ?>
18 18
 
19 19
         <div id="primary" class="site-content">
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
      *
27 27
      * @since 1.9.0
28 28
      */
29
-    public function wrapper_end(){ ?>
29
+    public function wrapper_end() { ?>
30 30
 
31 31
 			</div>
32 32
 		</div>
Please login to merge, or discard this patch.