Completed
Push — master ( 3a4fb0...eccc4a )
by Dwain
05:18
created
includes/class-sensei-wc.php 4 patches
Braces   +12 added lines, -5 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; // security check, don't load file outside WP
2
+if ( ! defined( 'ABSPATH' ) ) {
3
+	exit;
4
+}
5
+// security check, don't load file outside WP
3 6
 
4 7
 /**
5 8
  * Sensei WooCommerce class
@@ -1161,7 +1164,7 @@  discard block
 block discarded – undo
1161 1164
 
1162 1165
             $order = $order_id;
1163 1166
 
1164
-        }else{
1167
+        } else{
1165 1168
 
1166 1169
             $order = new WC_Order( $order_id );
1167 1170
         }
@@ -1267,7 +1270,9 @@  discard block
 block discarded – undo
1267 1270
 
1268 1271
         global $current_user;
1269 1272
 
1270
-        if ( ! isset( $current_user ) || !$current_user->ID > 0 ) return false;
1273
+        if ( ! isset( $current_user ) || !$current_user->ID > 0 ) {
1274
+        	return false;
1275
+        }
1271 1276
 
1272 1277
         $data_update = false;
1273 1278
 
@@ -1393,7 +1398,9 @@  discard block
 block discarded – undo
1393 1398
 
1394 1399
         $order = new WC_Order( $order_id );
1395 1400
 
1396
-        if ( ! isset ( $order ) ) return '';
1401
+        if ( ! isset ( $order ) ) {
1402
+        	return '';
1403
+        }
1397 1404
 
1398 1405
         if ( $order_status == 'wc-processing' && ( $order->post_status == 'wc-on-hold' || $order->post_status == 'wc-pending' || $order->post_status == 'wc-failed' ) ) {
1399 1406
 
@@ -1488,7 +1495,7 @@  discard block
 block discarded – undo
1488 1495
 
1489 1496
             $user_access_permission = true;
1490 1497
 
1491
-        }else{
1498
+        } else{
1492 1499
 
1493 1500
             $user_access_permission = false;
1494 1501
             // do not show the WC permissions message
Please login to merge, or discard this patch.
Doc Comments   +8 added lines, -7 removed lines patch added patch discarded remove patch
@@ -836,7 +836,7 @@  discard block
 block discarded – undo
836 836
      * @param  int $user_id
837 837
      * @param  int $product_id
838 838
      *
839
-     * @return bool
839
+     * @return boolean|null
840 840
      */
841 841
     public static function has_customer_bought_product ( $user_id, $product_id ){
842 842
 
@@ -941,7 +941,7 @@  discard block
 block discarded – undo
941 941
      * @since   1.2.0
942 942
      * @since  1.9.0 move to class Sensei_WC
943 943
      *
944
-     * @param   WC_Order $order
944
+     * @param   integer $order
945 945
      *
946 946
      * @return  void
947 947
      */
@@ -1152,6 +1152,7 @@  discard block
 block discarded – undo
1152 1152
      * @since   1.2.0
1153 1153
      * @since   1.9.0 Move function to the Sensei_WC class
1154 1154
      * @param   integer| WC_Order $order_id order ID
1155
+     * @param integer $order_id
1155 1156
      * @return  void
1156 1157
      */
1157 1158
     public static function cancel_order ( $order_id ) {
@@ -1261,7 +1262,7 @@  discard block
 block discarded – undo
1261 1262
      * @param  int 			$course_id  (default: 0)
1262 1263
      * @param  array/Object $order_user (default: array()) Specific user's data.
1263 1264
      *
1264
-     * @return bool|int
1265
+     * @return boolean|string
1265 1266
      */
1266 1267
     public static function course_update ( $course_id = 0, $order_user = array()  ) {
1267 1268
 
@@ -1334,7 +1335,7 @@  discard block
 block discarded – undo
1334 1335
      *
1335 1336
      * @param  boolean $guest_checkout Current guest checkout setting
1336 1337
      *
1337
-     * @return boolean                 Modified guest checkout setting
1338
+     * @return string|boolean                 Modified guest checkout setting
1338 1339
      */
1339 1340
     public static function disable_guest_checkout( $guest_checkout ) {
1340 1341
 
@@ -1508,7 +1509,7 @@  discard block
 block discarded – undo
1508 1509
      * Get all the valid subscription types.
1509 1510
      *
1510 1511
      * @since 1.9.0
1511
-     * @return array
1512
+     * @return string[]
1512 1513
      */
1513 1514
     public static function get_subscription_types(){
1514 1515
 
@@ -1526,8 +1527,8 @@  discard block
 block discarded – undo
1526 1527
      *
1527 1528
      * @since 1.9.0
1528 1529
      *
1529
-     * @param $user_id
1530
-     * @param $product_id
1530
+     * @param integer $user_id
1531
+     * @param string $product_id
1531 1532
      * @param $course_id
1532 1533
      *
1533 1534
      * @return bool
Please login to merge, or discard this patch.
Indentation   +1209 added lines, -1209 removed lines patch added patch discarded remove patch
@@ -12,741 +12,741 @@  discard block
 block discarded – undo
12 12
  */
13 13
 
14 14
 Class Sensei_WC{
15
-    /**
16
-     * Load the files needed for the woocommerce integration.
17
-     *
18
-     * @since 1.9.0
19
-     */
20
-    public static function load_woocommerce_integration_hooks(){
15
+	/**
16
+	 * Load the files needed for the woocommerce integration.
17
+	 *
18
+	 * @since 1.9.0
19
+	 */
20
+	public static function load_woocommerce_integration_hooks(){
21 21
 
22
-	    $woocommerce_hooks_file_path = Sensei()->plugin_path() . 'includes/hooks/woocommerce.php';
23
-        require_once( $woocommerce_hooks_file_path );
22
+		$woocommerce_hooks_file_path = Sensei()->plugin_path() . 'includes/hooks/woocommerce.php';
23
+		require_once( $woocommerce_hooks_file_path );
24 24
 
25
-    }
26
-    /**
27
-     * check if WooCommerce plugin is loaded and allowed by Sensei
28
-     *
29
-     * @since 1.9.0
30
-     * @return bool
31
-     */
32
-    public static function is_woocommerce_active(){
25
+	}
26
+	/**
27
+	 * check if WooCommerce plugin is loaded and allowed by Sensei
28
+	 *
29
+	 * @since 1.9.0
30
+	 * @return bool
31
+	 */
32
+	public static function is_woocommerce_active(){
33 33
 
34
-        $is_woocommerce_enabled_in_settings = isset( Sensei()->settings->settings['woocommerce_enabled'] ) && Sensei()->settings->settings['woocommerce_enabled'];
35
-        return self::is_woocommerce_present() && $is_woocommerce_enabled_in_settings;
34
+		$is_woocommerce_enabled_in_settings = isset( Sensei()->settings->settings['woocommerce_enabled'] ) && Sensei()->settings->settings['woocommerce_enabled'];
35
+		return self::is_woocommerce_present() && $is_woocommerce_enabled_in_settings;
36 36
 
37
-    } // end is_woocommerce_active
37
+	} // end is_woocommerce_active
38 38
 
39
-    /**
40
-     * Checks if the WooCommerce plugin is installed and activation.
41
-     *
42
-     * If you need to check if WooCommerce is activated use Sensei_Utils::is_woocommerce_active().
43
-     * This function does nott check to see if the Sensei setting for WooCommerce is enabled.
44
-     *
45
-     * @since 1.9.0
46
-     *
47
-     * @return bool
48
-     */
49
-    public static function is_woocommerce_present(){
39
+	/**
40
+	 * Checks if the WooCommerce plugin is installed and activation.
41
+	 *
42
+	 * If you need to check if WooCommerce is activated use Sensei_Utils::is_woocommerce_active().
43
+	 * This function does nott check to see if the Sensei setting for WooCommerce is enabled.
44
+	 *
45
+	 * @since 1.9.0
46
+	 *
47
+	 * @return bool
48
+	 */
49
+	public static function is_woocommerce_present(){
50 50
 
51
-        $active_plugins = (array) get_option( 'active_plugins', array() );
51
+		$active_plugins = (array) get_option( 'active_plugins', array() );
52 52
 
53
-        if ( is_multisite() ){
53
+		if ( is_multisite() ){
54 54
 
55
-            $active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) );
55
+			$active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) );
56 56
 
57
-        }
57
+		}
58 58
 
59
-        $is_woocommerce_plugin_present_and_activated = in_array( 'woocommerce/woocommerce.php', $active_plugins ) || array_key_exists( 'woocommerce/woocommerce.php', $active_plugins );
59
+		$is_woocommerce_plugin_present_and_activated = in_array( 'woocommerce/woocommerce.php', $active_plugins ) || array_key_exists( 'woocommerce/woocommerce.php', $active_plugins );
60 60
 
61
-        return class_exists( 'Woocommerce' ) || $is_woocommerce_plugin_present_and_activated;
61
+		return class_exists( 'Woocommerce' ) || $is_woocommerce_plugin_present_and_activated;
62 62
 
63
-    }// end is_woocommerce_present
63
+	}// end is_woocommerce_present
64 64
 
65
-    /**
66
-     * Find the order active number (completed or processing ) for a given user on a course. It will return the latest order.
67
-     *
68
-     * If multiple exist we will return the latest order.
69
-     *
70
-     * @param $user_id
71
-     * @param $course_id
72
-     * @return array $user_course_orders
73
-     */
74
-    public static function get_learner_course_active_order_id( $user_id, $course_id ){
65
+	/**
66
+	 * Find the order active number (completed or processing ) for a given user on a course. It will return the latest order.
67
+	 *
68
+	 * If multiple exist we will return the latest order.
69
+	 *
70
+	 * @param $user_id
71
+	 * @param $course_id
72
+	 * @return array $user_course_orders
73
+	 */
74
+	public static function get_learner_course_active_order_id( $user_id, $course_id ){
75 75
 
76
-        $course_product_id = get_post_meta( $course_id, '_course_woocommerce_product', true );
76
+		$course_product_id = get_post_meta( $course_id, '_course_woocommerce_product', true );
77 77
 
78
-        $orders_query = new WP_Query( array(
79
-            'post_type'   => 'shop_order',
80
-            'posts_per_page' => -1,
81
-            'post_status' => array( 'wc-processing', 'wc-completed' ),
82
-            'meta_key'=> '_customer_user',
83
-            'meta_value'=> $user_id,
84
-        ) );
78
+		$orders_query = new WP_Query( array(
79
+			'post_type'   => 'shop_order',
80
+			'posts_per_page' => -1,
81
+			'post_status' => array( 'wc-processing', 'wc-completed' ),
82
+			'meta_key'=> '_customer_user',
83
+			'meta_value'=> $user_id,
84
+		) );
85 85
 
86
-        if( $orders_query->post_count == 0 ){
86
+		if( $orders_query->post_count == 0 ){
87 87
 
88
-            return false;
88
+			return false;
89 89
 
90
-        }
90
+		}
91 91
 
92
-        foreach( $orders_query->get_posts() as $order ){
92
+		foreach( $orders_query->get_posts() as $order ){
93 93
 
94
-            $order = new WC_Order( $order->ID );
95
-            $items = $order->get_items();
94
+			$order = new WC_Order( $order->ID );
95
+			$items = $order->get_items();
96 96
 
97
-            $user_orders =  array();
97
+			$user_orders =  array();
98 98
 
99
-            foreach( $items as $item ){
99
+			foreach( $items as $item ){
100 100
 
101
-                // if the product id on the order and the one given to this function
102
-                // this order has been placed by the given user on the given course.
103
-                $product = wc_get_product( $item['product_id'] );
101
+				// if the product id on the order and the one given to this function
102
+				// this order has been placed by the given user on the given course.
103
+				$product = wc_get_product( $item['product_id'] );
104 104
 
105
-                if ( is_object( $product ) && $product->is_type( 'variable' )) {
105
+				if ( is_object( $product ) && $product->is_type( 'variable' )) {
106 106
 
107
-                    $item_product_id = $item['variation_id'];
107
+					$item_product_id = $item['variation_id'];
108 108
 
109
-                } else {
109
+				} else {
110 110
 
111
-                    $item_product_id =  $item['product_id'];
111
+					$item_product_id =  $item['product_id'];
112 112
 
113
-                }
113
+				}
114 114
 
115
-                if( $course_product_id == $item_product_id ){
115
+				if( $course_product_id == $item_product_id ){
116 116
 
117
-                    return $order->id;
117
+					return $order->id;
118 118
 
119
-                }
119
+				}
120 120
 
121 121
 
122
-            }//end for each order item
122
+			}//end for each order item
123 123
 
124
-        } // end for each order
124
+		} // end for each order
125 125
 
126
-        // if we reach this place we found no order
127
-        return false;
126
+		// if we reach this place we found no order
127
+		return false;
128 128
 
129
-    } // end get_learner_course_active_order_ids
129
+	} // end get_learner_course_active_order_ids
130 130
 
131
-    /**
132
-     * Output WooCommerce specific course filters
133
-     * Removing the paged argument
134
-     *
135
-     * @since 1.9.0
136
-     * @param $filter_links
137
-     * @return mixed
138
-     */
139
-    public static function add_course_archive_wc_filter_links( $filter_links ){
131
+	/**
132
+	 * Output WooCommerce specific course filters
133
+	 * Removing the paged argument
134
+	 *
135
+	 * @since 1.9.0
136
+	 * @param $filter_links
137
+	 * @return mixed
138
+	 */
139
+	public static function add_course_archive_wc_filter_links( $filter_links ){
140 140
 
141
-        $free_courses = self::get_free_courses();
142
-        $paid_courses = self::get_paid_courses();
141
+		$free_courses = self::get_free_courses();
142
+		$paid_courses = self::get_paid_courses();
143 143
 
144
-        if ( empty( $free_courses ) || empty( $paid_courses )  ){
145
-            // do not show any WooCommerce filters if all courses are
146
-            // free or if all courses are paid
147
-            return $filter_links;
144
+		if ( empty( $free_courses ) || empty( $paid_courses )  ){
145
+			// do not show any WooCommerce filters if all courses are
146
+			// free or if all courses are paid
147
+			return $filter_links;
148 148
 
149
-        }
149
+		}
150 150
 
151
-        $filter_links[] = array(
152
-            'id'=>'paid' ,
153
-            'url'=> add_query_arg( array( 'course_filter'=>'paid'), Sensei_Course::get_courses_page_url() ),
154
-            'title'=>__( 'Paid', 'woothemes-sensei' )
155
-        );
151
+		$filter_links[] = array(
152
+			'id'=>'paid' ,
153
+			'url'=> add_query_arg( array( 'course_filter'=>'paid'), Sensei_Course::get_courses_page_url() ),
154
+			'title'=>__( 'Paid', 'woothemes-sensei' )
155
+		);
156 156
 
157
-        $filter_links[] = array(
158
-            'id'=>'free',
159
-            'url'=> add_query_arg( array( 'course_filter'=>'free'), Sensei_Course::get_courses_page_url() ),
160
-            'title'=>__( 'Free', 'woothemes-sensei' )
161
-        );
157
+		$filter_links[] = array(
158
+			'id'=>'free',
159
+			'url'=> add_query_arg( array( 'course_filter'=>'free'), Sensei_Course::get_courses_page_url() ),
160
+			'title'=>__( 'Free', 'woothemes-sensei' )
161
+		);
162 162
 
163
-        return $filter_links;
163
+		return $filter_links;
164 164
 
165
-    }// end add_course_archive_wc_filter_links
165
+	}// end add_course_archive_wc_filter_links
166 166
 
167
-    /**
168
-     * Apply the free filter the the course query
169
-     * getting all course with no products or products with zero price
170
-     *
171
-     * hooked into pre_get_posts
172
-     *
173
-     * @since 1.9.0
174
-     * @param WP_Query $query
175
-     * @return WP_Query $query
176
-     */
177
-    public static function course_archive_wc_filter_free( $query ){
167
+	/**
168
+	 * Apply the free filter the the course query
169
+	 * getting all course with no products or products with zero price
170
+	 *
171
+	 * hooked into pre_get_posts
172
+	 *
173
+	 * @since 1.9.0
174
+	 * @param WP_Query $query
175
+	 * @return WP_Query $query
176
+	 */
177
+	public static function course_archive_wc_filter_free( $query ){
178 178
 
179
-        if( isset( $_GET['course_filter'] ) && 'free' == $_GET['course_filter']
180
-            && 'course' == $query->get( 'post_type') && $query->is_main_query()  ){
179
+		if( isset( $_GET['course_filter'] ) && 'free' == $_GET['course_filter']
180
+			&& 'course' == $query->get( 'post_type') && $query->is_main_query()  ){
181 181
 
182
-            // setup the course meta query
183
-            $meta_query = self::get_free_courses_meta_query_args();
182
+			// setup the course meta query
183
+			$meta_query = self::get_free_courses_meta_query_args();
184 184
 
185
-            // manipulate the query to return free courses
186
-            $query->set('meta_query', $meta_query );
185
+			// manipulate the query to return free courses
186
+			$query->set('meta_query', $meta_query );
187 187
 
188
-            // don't show any paid courses
189
-            $courses = self::get_paid_courses();
190
-            $ids = array();
191
-            foreach( $courses as $course ){
192
-                $ids[] = $course->ID;
193
-            }
194
-            $query->set( 'post__not_in', $ids );
188
+			// don't show any paid courses
189
+			$courses = self::get_paid_courses();
190
+			$ids = array();
191
+			foreach( $courses as $course ){
192
+				$ids[] = $course->ID;
193
+			}
194
+			$query->set( 'post__not_in', $ids );
195 195
 
196
-        }// end if course_filter
196
+		}// end if course_filter
197 197
 
198
-        return $query;
198
+		return $query;
199 199
 
200
-    }// course_archive_wc_filter_free
200
+	}// course_archive_wc_filter_free
201 201
 
202
-    /**
203
-     * Apply the paid filter to the course query on the courses page
204
-     * will include all course with a product attached with a price
205
-     * more than 0
206
-     *
207
-     * hooked into pre_get_posts
208
-     *
209
-     * @since 1.9.0
210
-     * @param WP_Query $query
211
-     * @return WP_Query $query
212
-     */
213
-    public static function course_archive_wc_filter_paid( $query ){
202
+	/**
203
+	 * Apply the paid filter to the course query on the courses page
204
+	 * will include all course with a product attached with a price
205
+	 * more than 0
206
+	 *
207
+	 * hooked into pre_get_posts
208
+	 *
209
+	 * @since 1.9.0
210
+	 * @param WP_Query $query
211
+	 * @return WP_Query $query
212
+	 */
213
+	public static function course_archive_wc_filter_paid( $query ){
214 214
 
215
-        if( isset( $_GET['course_filter'] ) && 'paid' == $_GET['course_filter']
216
-            && 'course' == $query->get( 'post_type') && $query->is_main_query() ){
217
-
218
-            // setup the course meta query
219
-            $meta_query = self::get_paid_courses_meta_query_args();
220
-
221
-            // manipulate the query to return free courses
222
-            $query->set('meta_query', $meta_query );
223
-
224
-        }
225
-
226
-        return $query;
227
-
228
-    }
229
-
230
-    /**
231
-     * Load the WooCommerce single product actions above
232
-     * single courses if woocommerce is active allowing purchase
233
-     * information and actions to be hooked from WooCommerce.
234
-     */
235
-    public static function do_single_course_wc_single_product_action(){
236
-
237
-        /**
238
-         * this hooks is documented within the WooCommerce plugin.
239
-         */
240
-        if ( Sensei_WC::is_woocommerce_active() ) {
241
-
242
-            do_action( 'woocommerce_before_single_product' );
243
-
244
-        } // End If Statement
245
-
246
-    }// end do_single_course_wc_single_product_action
247
-
248
-    /**
249
-     * Hooking into the single lesson page to alter the
250
-     * user access permissions based on if they have purchased the
251
-     * course the lesson belongs to.
252
-     *
253
-     * This function will only return false or the passed in user_access value.
254
-     * It doesn't return true in order to avoid altering other options.
255
-     *
256
-     * @since 1.9.0
257
-     *
258
-     * @param $can_user_view_lesson
259
-     * @param $lesson_id
260
-     * @param $user_id
261
-     * @return bool
262
-     */
263
-    public static function alter_can_user_view_lesson ( $can_user_view_lesson, $lesson_id, $user_id  ){
264
-
265
-	    // do not override access to admins
266
-	    if( sensei_all_access() || Sensei_Utils::is_preview_lesson( $lesson_id ) ){
267
-		    return true;
268
-	    }
269
-
270
-        // check if the course has a valid product attached to it
271
-        // which the user should have purchased if they want to access
272
-        // the current lesson
273
-        $course_id = get_post_meta( $lesson_id , '_lesson_course', true);
274
-        $wc_post_id = get_post_meta( $course_id, '_course_woocommerce_product', true );
275
-        $product = Sensei()->sensei_get_woocommerce_product_object($wc_post_id);
276
-        if( isset ($product) && is_object($product) ){
277
-
278
-            // valid product found
279
-            $order_id = self::get_learner_course_active_order_id( $user_id, $course_id );
280
-
281
-            // product has a successful order so this user may access the content
282
-            // this function may only return false or the default
283
-            // returning true may override other negatives which we don't want
284
-            if( ! $order_id ){
285
-
286
-                return false;
287
-
288
-            }
289
-
290
-        }
291
-
292
-        // return the passed in value
293
-        return $can_user_view_lesson;
294
-
295
-    }
296
-
297
-    /**
298
-     * Add course link to order thank you and details pages.
299
-     *
300
-     * @since  1.4.5
301
-     * @access public
302
-     *
303
-     * @return void
304
-     */
305
-    public static function course_link_from_order( ) {
306
-
307
-        if( ! is_order_received_page() ){
308
-            return;
309
-        }
310
-
311
-        $order_id = get_query_var( 'order-received' );
215
+		if( isset( $_GET['course_filter'] ) && 'paid' == $_GET['course_filter']
216
+			&& 'course' == $query->get( 'post_type') && $query->is_main_query() ){
217
+
218
+			// setup the course meta query
219
+			$meta_query = self::get_paid_courses_meta_query_args();
220
+
221
+			// manipulate the query to return free courses
222
+			$query->set('meta_query', $meta_query );
223
+
224
+		}
225
+
226
+		return $query;
227
+
228
+	}
229
+
230
+	/**
231
+	 * Load the WooCommerce single product actions above
232
+	 * single courses if woocommerce is active allowing purchase
233
+	 * information and actions to be hooked from WooCommerce.
234
+	 */
235
+	public static function do_single_course_wc_single_product_action(){
236
+
237
+		/**
238
+		 * this hooks is documented within the WooCommerce plugin.
239
+		 */
240
+		if ( Sensei_WC::is_woocommerce_active() ) {
241
+
242
+			do_action( 'woocommerce_before_single_product' );
243
+
244
+		} // End If Statement
245
+
246
+	}// end do_single_course_wc_single_product_action
247
+
248
+	/**
249
+	 * Hooking into the single lesson page to alter the
250
+	 * user access permissions based on if they have purchased the
251
+	 * course the lesson belongs to.
252
+	 *
253
+	 * This function will only return false or the passed in user_access value.
254
+	 * It doesn't return true in order to avoid altering other options.
255
+	 *
256
+	 * @since 1.9.0
257
+	 *
258
+	 * @param $can_user_view_lesson
259
+	 * @param $lesson_id
260
+	 * @param $user_id
261
+	 * @return bool
262
+	 */
263
+	public static function alter_can_user_view_lesson ( $can_user_view_lesson, $lesson_id, $user_id  ){
264
+
265
+		// do not override access to admins
266
+		if( sensei_all_access() || Sensei_Utils::is_preview_lesson( $lesson_id ) ){
267
+			return true;
268
+		}
269
+
270
+		// check if the course has a valid product attached to it
271
+		// which the user should have purchased if they want to access
272
+		// the current lesson
273
+		$course_id = get_post_meta( $lesson_id , '_lesson_course', true);
274
+		$wc_post_id = get_post_meta( $course_id, '_course_woocommerce_product', true );
275
+		$product = Sensei()->sensei_get_woocommerce_product_object($wc_post_id);
276
+		if( isset ($product) && is_object($product) ){
277
+
278
+			// valid product found
279
+			$order_id = self::get_learner_course_active_order_id( $user_id, $course_id );
280
+
281
+			// product has a successful order so this user may access the content
282
+			// this function may only return false or the default
283
+			// returning true may override other negatives which we don't want
284
+			if( ! $order_id ){
285
+
286
+				return false;
287
+
288
+			}
289
+
290
+		}
291
+
292
+		// return the passed in value
293
+		return $can_user_view_lesson;
294
+
295
+	}
296
+
297
+	/**
298
+	 * Add course link to order thank you and details pages.
299
+	 *
300
+	 * @since  1.4.5
301
+	 * @access public
302
+	 *
303
+	 * @return void
304
+	 */
305
+	public static function course_link_from_order( ) {
306
+
307
+		if( ! is_order_received_page() ){
308
+			return;
309
+		}
310
+
311
+		$order_id = get_query_var( 'order-received' );
312 312
 		$order = new WC_Order( $order_id );
313 313
 
314 314
 		// exit early if not wc-completed or wc-processing
315 315
 		if( 'wc-completed' != $order->post_status
316
-            && 'wc-processing' != $order->post_status  ) {
317
-            return;
318
-        }
316
+			&& 'wc-processing' != $order->post_status  ) {
317
+			return;
318
+		}
319 319
 
320
-        $course_links = array(); // store the for links for courses purchased
320
+		$course_links = array(); // store the for links for courses purchased
321 321
 		foreach ( $order->get_items() as $item ) {
322 322
 
323
-            if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
323
+			if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
324 324
 
325
-                // If item has variation_id then its a variation of the product
326
-                $item_id = $item['variation_id'];
325
+				// If item has variation_id then its a variation of the product
326
+				$item_id = $item['variation_id'];
327 327
 
328
-            } else {
328
+			} else {
329 329
 
330
-                //If not its real product set its id to item_id
331
-                $item_id = $item['product_id'];
330
+				//If not its real product set its id to item_id
331
+				$item_id = $item['product_id'];
332 332
 
333
-            } // End If Statement
333
+			} // End If Statement
334 334
 
335
-            $user_id = get_post_meta( $order->id, '_customer_user', true );
335
+			$user_id = get_post_meta( $order->id, '_customer_user', true );
336 336
 
337
-            if( $user_id ) {
337
+			if( $user_id ) {
338 338
 
339
-                // Get all courses for product
340
-                $args = Sensei_Course::get_default_query_args();
341
-                $args['meta_query'] = array( array(
342
-                            'key' => '_course_woocommerce_product',
343
-                            'value' => $item_id
344
-                        ) );
345
-                $args['orderby'] = 'menu_order date';
346
-                $args['order'] = 'ASC';
339
+				// Get all courses for product
340
+				$args = Sensei_Course::get_default_query_args();
341
+				$args['meta_query'] = array( array(
342
+							'key' => '_course_woocommerce_product',
343
+							'value' => $item_id
344
+						) );
345
+				$args['orderby'] = 'menu_order date';
346
+				$args['order'] = 'ASC';
347 347
 
348
-                // loop through courses
349
-                $courses = get_posts( $args );
350
-                if( $courses && count( $courses ) > 0 ) {
348
+				// loop through courses
349
+				$courses = get_posts( $args );
350
+				if( $courses && count( $courses ) > 0 ) {
351 351
 
352
-                    foreach( $courses as $course ) {
352
+					foreach( $courses as $course ) {
353 353
 
354
-                        $title = $course->post_title;
355
-                        $permalink = get_permalink( $course->ID );
356
-                        $course_links[] .= '<a href="' . esc_url( $permalink ) . '" >' . $title . '</a> ';
354
+						$title = $course->post_title;
355
+						$permalink = get_permalink( $course->ID );
356
+						$course_links[] .= '<a href="' . esc_url( $permalink ) . '" >' . $title . '</a> ';
357 357
 
358
-                    } // end for each
358
+					} // end for each
359 359
 
360
-                    // close the message div
360
+					// close the message div
361 361
 
362
-                }// end if $courses check
363
-            }
364
-        }// end loop through orders
362
+				}// end if $courses check
363
+			}
364
+		}// end loop through orders
365 365
 
366
-        // add the courses to the WooCommerce notice
367
-        if( ! empty( $course_links) ){
366
+		// add the courses to the WooCommerce notice
367
+		if( ! empty( $course_links) ){
368 368
 
369
-            $courses_html = _nx(
370
-                'You have purchased the following course:',
371
-                'You have purchased the following courses:',
372
-                count( $course_links ),
373
-                'Purchase thank you note on Checkout page. The course link(s) will be show', 'woothemes-sensei'
374
-            );
369
+			$courses_html = _nx(
370
+				'You have purchased the following course:',
371
+				'You have purchased the following courses:',
372
+				count( $course_links ),
373
+				'Purchase thank you note on Checkout page. The course link(s) will be show', 'woothemes-sensei'
374
+			);
375 375
 
376
-            foreach( $course_links as $link ){
376
+			foreach( $course_links as $link ){
377 377
 
378
-                $courses_html .= '<li>' . $link . '</li>';
378
+				$courses_html .= '<li>' . $link . '</li>';
379 379
 
380
-            }
380
+			}
381 381
 
382
-            $courses_html .= ' </ul>';
382
+			$courses_html .= ' </ul>';
383 383
 
384
-            wc_add_notice( $courses_html, 'success' );
385
-        }
384
+			wc_add_notice( $courses_html, 'success' );
385
+		}
386 386
 
387 387
 	} // end course_link_order_form
388 388
 
389
-    /**
390
-     * Show the message that a user should complete
391
-     * their purchase if the course is in the cart
392
-     *
393
-     * This should be used within the course loop or single course page
394
-     *
395
-     * @since 1.9.0
396
-     */
397
-    public static function course_in_cart_message(){
389
+	/**
390
+	 * Show the message that a user should complete
391
+	 * their purchase if the course is in the cart
392
+	 *
393
+	 * This should be used within the course loop or single course page
394
+	 *
395
+	 * @since 1.9.0
396
+	 */
397
+	public static function course_in_cart_message(){
398 398
 
399
-        global $post;
399
+		global $post;
400 400
 
401
-        if( self::is_course_in_cart( $post->ID ) ){ ?>
401
+		if( self::is_course_in_cart( $post->ID ) ){ ?>
402 402
 
403 403
             <div class="sensei-message info">
404 404
                 <?php
405 405
 
406
-                $cart_link =  '<a class="cart-complete" href="' . WC()->cart->get_checkout_url()
407
-                              . '" title="' . __('complete purchase', 'woothemes-sensei') . '">'
408
-                              . __('complete the purchase', 'woothemes-sensei') . '</a>';
406
+				$cart_link =  '<a class="cart-complete" href="' . WC()->cart->get_checkout_url()
407
+							  . '" title="' . __('complete purchase', 'woothemes-sensei') . '">'
408
+							  . __('complete the purchase', 'woothemes-sensei') . '</a>';
409 409
 
410
-                echo sprintf(  __('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei'), $cart_link );
410
+				echo sprintf(  __('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei'), $cart_link );
411 411
 
412
-                ?>
412
+				?>
413 413
             </div>
414 414
         <?php }
415 415
 
416
-    } // End sensei_woocommerce_in_cart_message()
416
+	} // End sensei_woocommerce_in_cart_message()
417 417
 
418
-    /**
419
-     * Checks the cart to see if a course is in the cart.
420
-     *
421
-     * @param $course_id
422
-     * @return bool
423
-     */
424
-    public static function is_course_in_cart( $course_id ){
425
-
426
-        $wc_post_id = absint( get_post_meta( $course_id, '_course_woocommerce_product', true ) );
427
-        $user_course_status_id = Sensei_Utils::user_started_course( $course_id , get_current_user_id() );
428
-
429
-        if ( 0 < intval( $wc_post_id ) && ! $user_course_status_id ) {
430
-
431
-            if ( self::is_product_in_cart( $wc_post_id ) ) {
432
-
433
-                return true;
434
-
435
-            }
436
-
437
-        }
438
-
439
-        return false;
440
-
441
-    }// is_course_in_cart
442
-
443
-    /**
444
-     * Check the cart to see if the product is in the cart
445
-     *
446
-     * @param $product_id
447
-     * @return bool
448
-     */
449
-    public static function is_product_in_cart( $product_id ){
450
-
451
-        if ( 0 < $product_id ) {
452
-
453
-            $product = wc_get_product( $product_id );
454
-
455
-            $parent_id = '';
456
-            if( isset( $product->variation_id ) && 0 < intval( $product->variation_id ) ) {
457
-                $wc_product_id = $product->parent->id;
458
-            }
459
-            foreach( WC()->cart->get_cart() as $cart_item_key => $values ) {
460
-
461
-                $cart_product = $values['data'];
462
-                if( $product_id == $cart_product->id ) {
463
-
464
-                    return true;
465
-
466
-                }
467
-
468
-            }
469
-        } // End If Statement
470
-
471
-        return false;
472
-
473
-    } // end is_product_in_car
474
-
475
-    /**
476
-     * Get all free WooCommerce products
477
-     *
478
-     * @since 1.9.0
479
-     *
480
-     * @return array $free_products{
481
-     *  @type int $wp_post_id
482
-     * }
483
-     */
484
-    public static function get_free_product_ids(){
485
-
486
-        return  get_posts( array(
487
-            'post_type' => 'product',
488
-            'posts_per_page' => '1000',
489
-            'fields' => 'ids',
490
-            'meta_query'=> array(
491
-                'relation' => 'OR',
492
-                array(
493
-                    'key'=> '_regular_price',
494
-                    'value' => 0,
495
-                ),
496
-                array(
497
-                    'key'=> '_sale_price',
498
-                    'value' => 0,
499
-                ),
500
-            ),
501
-        ));
502
-
503
-    }// end get free product query
504
-
505
-    /**
506
-     * The metat query for courses that are free
507
-     *
508
-     * @since 1.9.0
509
-     * @return array $wp_meta_query_param
510
-     */
511
-    public static function get_free_courses_meta_query_args(){
512
-
513
-        return array(
514
-            'relation' => 'OR',
515
-            array(
516
-                'key'     => '_course_woocommerce_product',
517
-                'value' => '-',
518
-                'compare' => '=',
519
-            ),
520
-            array(
521
-                'key'     => '_course_woocommerce_product',
522
-                'value' => self::get_free_product_ids(),
523
-                'compare' => 'IN',
524
-            ),
525
-        );
526
-
527
-    }// get_free_courses_meta_query
528
-
529
-    /**
530
-     * The metat query for courses that are free
531
-     *
532
-     * @since 1.9.0
533
-     * @return array $wp_query_meta_query_args_param
534
-     */
535
-    public static function get_paid_courses_meta_query_args(){
536
-
537
-        $paid_product_ids = self::get_paid_product_ids();
538
-
539
-        return array(
540
-            array(
541
-                'key'     => '_course_woocommerce_product',
542
-                // when empty we give a false post_id to ensure the caller doesn't get any courses for their
543
-                // query
544
-                'value' => empty( $paid_product_ids  )? '-1000' : $paid_product_ids,
545
-                'compare' => 'IN',
546
-            ),
547
-        );
548
-
549
-    }// get_free_courses_meta_query
550
-
551
-    /**
552
-     * The WordPress Query args
553
-     * for paid products on sale
554
-     *
555
-     * @since 1.9.0
556
-     * @return array $product_query_args
557
-     */
558
-    public static function get_paid_products_on_sale_query_args(){
559
-
560
-        $args = array(
561
-                   'post_type' 		=> 'product',
562
-                   'posts_per_page' 		=> 1000,
563
-                   'orderby'         	=> 'date',
564
-                   'order'           	=> 'DESC',
565
-                   'suppress_filters' 	=> 0
566
-        );
567
-
568
-        $args[ 'fields' ]     = 'ids';
569
-
570
-        $args[ 'meta_query' ] = array(
571
-            'relation' => 'AND',
572
-            array(
573
-                'key'=> '_regular_price',
574
-                'compare' => '>',
575
-                'value' => 0,
576
-            ),
577
-            array(
578
-                'key'=> '_sale_price',
579
-                'compare' => '>',
580
-                'value' => 0,
581
-            ),
582
-        );
583
-
584
-        return $args;
585
-
586
-    } // get_paid_products_on_sale_query_args
587
-
588
-
589
-    /**
590
-     * Return the WordPress query args for
591
-     * products not on sale but that is not a free
592
-     *
593
-     * @since 1.9.0
594
-     *
595
-     * @return array
596
-     */
597
-    public static function get_paid_products_not_on_sale_query_args(){
598
-
599
-        $args = array(
600
-            'post_type' 		=> 'product',
601
-            'posts_per_page' 		=> 1000,
602
-            'orderby'         	=> 'date',
603
-            'order'           	=> 'DESC',
604
-            'suppress_filters' 	=> 0
605
-        );
606
-
607
-        $args[ 'fields' ]     = 'ids';
608
-        $args[ 'meta_query' ] = array(
609
-            'relation' => 'AND',
610
-            array(
611
-                'key'=> '_regular_price',
612
-                'compare' => '>',
613
-                'value' => 0,
614
-            ),
615
-            array(
616
-                'key'=> '_sale_price',
617
-                'compare' => '=',
618
-                'value' => '',
619
-            ),
620
-        );
621
-
622
-        return $args;
623
-
624
-
625
-    } // get_paid_courses_meta_query
626
-
627
-    /**
628
-     * Get all WooCommerce non-free product id's
629
-     *
630
-     * @since 1.9.0
631
-     *
632
-     * @return array $woocommerce_paid_product_ids
633
-     */
634
-    public static function get_paid_product_ids(){
635
-
636
-        // get all the paid WooCommerce products that has regular
637
-        // and sale price greater than 0
638
-        // will be used later to check for course with the id as meta
639
-        $paid_product_ids_with_sale =  get_posts( self::get_paid_products_on_sale_query_args() );
640
-
641
-        // get all the paid WooCommerce products that has regular price
642
-        // greater than 0 without a sale price
643
-        // will be used later to check for course with the id as meta
644
-        $paid_product_ids_without_sale = get_posts( self::get_paid_products_not_on_sale_query_args() );
645
-
646
-        // combine products ID's with regular and sale price grater than zero and those without
647
-        // sale but regular price greater than zero
648
-        $woocommerce_paid_product_ids = array_merge( $paid_product_ids_with_sale, $paid_product_ids_without_sale );
649
-
650
-        // if
651
-        if( empty($woocommerce_paid_product_ids) ){
652
-            return array( );
653
-        }
654
-        return $woocommerce_paid_product_ids;
655
-
656
-    }
657
-
658
-    /**
659
-     * Get all free courses.
660
-     *
661
-     * This course that have a WC product attached
662
-     * that has a price or sale price of zero and
663
-     * other courses with no WooCommerce products
664
-     * attached.
665
-     *
666
-     * @since 1.9.0
667
-     *
668
-     * @return array
669
-     */
670
-    public static function get_free_courses(){
671
-
672
-        $free_course_query_args = Sensei_Course::get_default_query_args();
673
-        $free_course_query_args[ 'meta_query' ] = self::get_free_courses_meta_query_args();
674
-
675
-        // don't show any paid courses
676
-        $courses = self::get_paid_courses();
677
-        $ids = array();
678
-        foreach( $courses as $course ){
679
-            $ids[] = $course->ID;
680
-        }
681
-        $free_course_query_args[ 'post__not_in' ] =  $ids;
682
-
683
-        return get_posts( $free_course_query_args );
684
-
685
-    }
686
-
687
-    /**
688
-     * Return all products that are not free
689
-     *
690
-     * @since 1.9.0
691
-     * @return array
692
-     */
693
-    public static function get_paid_courses(){
694
-
695
-        $paid_course_query_args = Sensei_Course::get_default_query_args();
696
-
697
-        $paid_course_query_args[ 'meta_query' ] = self::get_paid_courses_meta_query_args();
698
-
699
-        return get_posts(  $paid_course_query_args );
700
-    }
701
-
702
-    /**
703
-     * Show the WooCommerce add to cart button for the  current course
704
-     *
705
-     * The function will only show the button if
706
-     * 1- the user can buy the course
707
-     * 2- if they have completed their pre-requisite
708
-     * 3- if the course has a valid product attached
709
-     *
710
-     * @since 1.9.0
711
-     * @param int $course_id
712
-     * @return string $html markup for the button or nothing if user not allowed to buy
713
-     */
714
-    public static function the_add_to_cart_button_html( $course_id ){
715
-
716
-        if ( ! Sensei_Course::is_prerequisite_complete( $course_id )) {
717
-            return '';
718
-        }
719
-
720
-        $wc_post_id = self::get_course_product_id( $course_id );
721
-
722
-        // Check if customer purchased the product
723
-        if ( self::has_customer_bought_product(  get_current_user_id(), $wc_post_id )
724
-            || empty( $wc_post_id ) ) {
725
-
726
-            return '';
727
-
728
-        }
729
-
730
-        // based on simple.php in WC templates/single-product/add-to-cart/
731
-        // Get the product
732
-        $product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id );
733
-
734
-        // do not show the button for invalid products, non purchasable products, out
735
-        // of stock product or if course is already in cart
736
-        if ( ! isset ( $product )
737
-            || ! is_object( $product )
738
-            || ! $product->is_purchasable()
739
-            || ! $product->is_in_stock()
740
-            || self::is_course_in_cart( $wc_post_id ) ) {
741
-
742
-            return '';
743
-
744
-        }
745
-
746
-        //
747
-        // button  output:
748
-        //
749
-        ?>
418
+	/**
419
+	 * Checks the cart to see if a course is in the cart.
420
+	 *
421
+	 * @param $course_id
422
+	 * @return bool
423
+	 */
424
+	public static function is_course_in_cart( $course_id ){
425
+
426
+		$wc_post_id = absint( get_post_meta( $course_id, '_course_woocommerce_product', true ) );
427
+		$user_course_status_id = Sensei_Utils::user_started_course( $course_id , get_current_user_id() );
428
+
429
+		if ( 0 < intval( $wc_post_id ) && ! $user_course_status_id ) {
430
+
431
+			if ( self::is_product_in_cart( $wc_post_id ) ) {
432
+
433
+				return true;
434
+
435
+			}
436
+
437
+		}
438
+
439
+		return false;
440
+
441
+	}// is_course_in_cart
442
+
443
+	/**
444
+	 * Check the cart to see if the product is in the cart
445
+	 *
446
+	 * @param $product_id
447
+	 * @return bool
448
+	 */
449
+	public static function is_product_in_cart( $product_id ){
450
+
451
+		if ( 0 < $product_id ) {
452
+
453
+			$product = wc_get_product( $product_id );
454
+
455
+			$parent_id = '';
456
+			if( isset( $product->variation_id ) && 0 < intval( $product->variation_id ) ) {
457
+				$wc_product_id = $product->parent->id;
458
+			}
459
+			foreach( WC()->cart->get_cart() as $cart_item_key => $values ) {
460
+
461
+				$cart_product = $values['data'];
462
+				if( $product_id == $cart_product->id ) {
463
+
464
+					return true;
465
+
466
+				}
467
+
468
+			}
469
+		} // End If Statement
470
+
471
+		return false;
472
+
473
+	} // end is_product_in_car
474
+
475
+	/**
476
+	 * Get all free WooCommerce products
477
+	 *
478
+	 * @since 1.9.0
479
+	 *
480
+	 * @return array $free_products{
481
+	 *  @type int $wp_post_id
482
+	 * }
483
+	 */
484
+	public static function get_free_product_ids(){
485
+
486
+		return  get_posts( array(
487
+			'post_type' => 'product',
488
+			'posts_per_page' => '1000',
489
+			'fields' => 'ids',
490
+			'meta_query'=> array(
491
+				'relation' => 'OR',
492
+				array(
493
+					'key'=> '_regular_price',
494
+					'value' => 0,
495
+				),
496
+				array(
497
+					'key'=> '_sale_price',
498
+					'value' => 0,
499
+				),
500
+			),
501
+		));
502
+
503
+	}// end get free product query
504
+
505
+	/**
506
+	 * The metat query for courses that are free
507
+	 *
508
+	 * @since 1.9.0
509
+	 * @return array $wp_meta_query_param
510
+	 */
511
+	public static function get_free_courses_meta_query_args(){
512
+
513
+		return array(
514
+			'relation' => 'OR',
515
+			array(
516
+				'key'     => '_course_woocommerce_product',
517
+				'value' => '-',
518
+				'compare' => '=',
519
+			),
520
+			array(
521
+				'key'     => '_course_woocommerce_product',
522
+				'value' => self::get_free_product_ids(),
523
+				'compare' => 'IN',
524
+			),
525
+		);
526
+
527
+	}// get_free_courses_meta_query
528
+
529
+	/**
530
+	 * The metat query for courses that are free
531
+	 *
532
+	 * @since 1.9.0
533
+	 * @return array $wp_query_meta_query_args_param
534
+	 */
535
+	public static function get_paid_courses_meta_query_args(){
536
+
537
+		$paid_product_ids = self::get_paid_product_ids();
538
+
539
+		return array(
540
+			array(
541
+				'key'     => '_course_woocommerce_product',
542
+				// when empty we give a false post_id to ensure the caller doesn't get any courses for their
543
+				// query
544
+				'value' => empty( $paid_product_ids  )? '-1000' : $paid_product_ids,
545
+				'compare' => 'IN',
546
+			),
547
+		);
548
+
549
+	}// get_free_courses_meta_query
550
+
551
+	/**
552
+	 * The WordPress Query args
553
+	 * for paid products on sale
554
+	 *
555
+	 * @since 1.9.0
556
+	 * @return array $product_query_args
557
+	 */
558
+	public static function get_paid_products_on_sale_query_args(){
559
+
560
+		$args = array(
561
+				   'post_type' 		=> 'product',
562
+				   'posts_per_page' 		=> 1000,
563
+				   'orderby'         	=> 'date',
564
+				   'order'           	=> 'DESC',
565
+				   'suppress_filters' 	=> 0
566
+		);
567
+
568
+		$args[ 'fields' ]     = 'ids';
569
+
570
+		$args[ 'meta_query' ] = array(
571
+			'relation' => 'AND',
572
+			array(
573
+				'key'=> '_regular_price',
574
+				'compare' => '>',
575
+				'value' => 0,
576
+			),
577
+			array(
578
+				'key'=> '_sale_price',
579
+				'compare' => '>',
580
+				'value' => 0,
581
+			),
582
+		);
583
+
584
+		return $args;
585
+
586
+	} // get_paid_products_on_sale_query_args
587
+
588
+
589
+	/**
590
+	 * Return the WordPress query args for
591
+	 * products not on sale but that is not a free
592
+	 *
593
+	 * @since 1.9.0
594
+	 *
595
+	 * @return array
596
+	 */
597
+	public static function get_paid_products_not_on_sale_query_args(){
598
+
599
+		$args = array(
600
+			'post_type' 		=> 'product',
601
+			'posts_per_page' 		=> 1000,
602
+			'orderby'         	=> 'date',
603
+			'order'           	=> 'DESC',
604
+			'suppress_filters' 	=> 0
605
+		);
606
+
607
+		$args[ 'fields' ]     = 'ids';
608
+		$args[ 'meta_query' ] = array(
609
+			'relation' => 'AND',
610
+			array(
611
+				'key'=> '_regular_price',
612
+				'compare' => '>',
613
+				'value' => 0,
614
+			),
615
+			array(
616
+				'key'=> '_sale_price',
617
+				'compare' => '=',
618
+				'value' => '',
619
+			),
620
+		);
621
+
622
+		return $args;
623
+
624
+
625
+	} // get_paid_courses_meta_query
626
+
627
+	/**
628
+	 * Get all WooCommerce non-free product id's
629
+	 *
630
+	 * @since 1.9.0
631
+	 *
632
+	 * @return array $woocommerce_paid_product_ids
633
+	 */
634
+	public static function get_paid_product_ids(){
635
+
636
+		// get all the paid WooCommerce products that has regular
637
+		// and sale price greater than 0
638
+		// will be used later to check for course with the id as meta
639
+		$paid_product_ids_with_sale =  get_posts( self::get_paid_products_on_sale_query_args() );
640
+
641
+		// get all the paid WooCommerce products that has regular price
642
+		// greater than 0 without a sale price
643
+		// will be used later to check for course with the id as meta
644
+		$paid_product_ids_without_sale = get_posts( self::get_paid_products_not_on_sale_query_args() );
645
+
646
+		// combine products ID's with regular and sale price grater than zero and those without
647
+		// sale but regular price greater than zero
648
+		$woocommerce_paid_product_ids = array_merge( $paid_product_ids_with_sale, $paid_product_ids_without_sale );
649
+
650
+		// if
651
+		if( empty($woocommerce_paid_product_ids) ){
652
+			return array( );
653
+		}
654
+		return $woocommerce_paid_product_ids;
655
+
656
+	}
657
+
658
+	/**
659
+	 * Get all free courses.
660
+	 *
661
+	 * This course that have a WC product attached
662
+	 * that has a price or sale price of zero and
663
+	 * other courses with no WooCommerce products
664
+	 * attached.
665
+	 *
666
+	 * @since 1.9.0
667
+	 *
668
+	 * @return array
669
+	 */
670
+	public static function get_free_courses(){
671
+
672
+		$free_course_query_args = Sensei_Course::get_default_query_args();
673
+		$free_course_query_args[ 'meta_query' ] = self::get_free_courses_meta_query_args();
674
+
675
+		// don't show any paid courses
676
+		$courses = self::get_paid_courses();
677
+		$ids = array();
678
+		foreach( $courses as $course ){
679
+			$ids[] = $course->ID;
680
+		}
681
+		$free_course_query_args[ 'post__not_in' ] =  $ids;
682
+
683
+		return get_posts( $free_course_query_args );
684
+
685
+	}
686
+
687
+	/**
688
+	 * Return all products that are not free
689
+	 *
690
+	 * @since 1.9.0
691
+	 * @return array
692
+	 */
693
+	public static function get_paid_courses(){
694
+
695
+		$paid_course_query_args = Sensei_Course::get_default_query_args();
696
+
697
+		$paid_course_query_args[ 'meta_query' ] = self::get_paid_courses_meta_query_args();
698
+
699
+		return get_posts(  $paid_course_query_args );
700
+	}
701
+
702
+	/**
703
+	 * Show the WooCommerce add to cart button for the  current course
704
+	 *
705
+	 * The function will only show the button if
706
+	 * 1- the user can buy the course
707
+	 * 2- if they have completed their pre-requisite
708
+	 * 3- if the course has a valid product attached
709
+	 *
710
+	 * @since 1.9.0
711
+	 * @param int $course_id
712
+	 * @return string $html markup for the button or nothing if user not allowed to buy
713
+	 */
714
+	public static function the_add_to_cart_button_html( $course_id ){
715
+
716
+		if ( ! Sensei_Course::is_prerequisite_complete( $course_id )) {
717
+			return '';
718
+		}
719
+
720
+		$wc_post_id = self::get_course_product_id( $course_id );
721
+
722
+		// Check if customer purchased the product
723
+		if ( self::has_customer_bought_product(  get_current_user_id(), $wc_post_id )
724
+			|| empty( $wc_post_id ) ) {
725
+
726
+			return '';
727
+
728
+		}
729
+
730
+		// based on simple.php in WC templates/single-product/add-to-cart/
731
+		// Get the product
732
+		$product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id );
733
+
734
+		// do not show the button for invalid products, non purchasable products, out
735
+		// of stock product or if course is already in cart
736
+		if ( ! isset ( $product )
737
+			|| ! is_object( $product )
738
+			|| ! $product->is_purchasable()
739
+			|| ! $product->is_in_stock()
740
+			|| self::is_course_in_cart( $wc_post_id ) ) {
741
+
742
+			return '';
743
+
744
+		}
745
+
746
+		//
747
+		// button  output:
748
+		//
749
+		?>
750 750
 
751 751
         <form action="<?php echo esc_url( $product->add_to_cart_url() ); ?>"
752 752
               class="cart"
@@ -779,54 +779,54 @@  discard block
 block discarded – undo
779 779
         </form>
780 780
 
781 781
         <?php
782
-    } // end the_add_to_cart_button_html
782
+	} // end the_add_to_cart_button_html
783 783
 
784
-    /**
785
-     * Alter the no permissions message on the single course page
786
-     * Changes the message to a WooCommerce specific message.
787
-     *
788
-     * @since 1.9.0
789
-     *
790
-     * @param $message
791
-     * @param $post_id
792
-     *
793
-     * @return string $message
794
-     */
795
-    public static function alter_no_permissions_message( $message, $post_id ){
784
+	/**
785
+	 * Alter the no permissions message on the single course page
786
+	 * Changes the message to a WooCommerce specific message.
787
+	 *
788
+	 * @since 1.9.0
789
+	 *
790
+	 * @param $message
791
+	 * @param $post_id
792
+	 *
793
+	 * @return string $message
794
+	 */
795
+	public static function alter_no_permissions_message( $message, $post_id ){
796 796
 
797
-        if( empty( $post_id ) || 'course'!=get_post_type( $post_id ) ){
798
-            return  $message;
799
-        }
797
+		if( empty( $post_id ) || 'course'!=get_post_type( $post_id ) ){
798
+			return  $message;
799
+		}
800 800
 
801
-        $product_id = self::get_course_product_id( $post_id );
801
+		$product_id = self::get_course_product_id( $post_id );
802 802
 
803
-        if( ! $product_id
804
-            || self::has_customer_bought_product( get_current_user_id(),$product_id ) ){
803
+		if( ! $product_id
804
+			|| self::has_customer_bought_product( get_current_user_id(),$product_id ) ){
805 805
 
806
-            return $message;
806
+			return $message;
807 807
 
808
-        }
808
+		}
809 809
 
810
-        ob_start();
811
-        self::the_course_no_permissions_message( $post_id );
812
-        $woocommerce_course_no_permissions_message = ob_get_clean();
810
+		ob_start();
811
+		self::the_course_no_permissions_message( $post_id );
812
+		$woocommerce_course_no_permissions_message = ob_get_clean();
813 813
 
814
-        return $woocommerce_course_no_permissions_message ;
814
+		return $woocommerce_course_no_permissions_message ;
815 815
 
816
-    }
817
-    /**
818
-     * Show the no permissions message when a user is logged in
819
-     * and have not yet purchased the current course
820
-     *
821
-     * @since 1.9.0
822
-     */
823
-    public static function the_course_no_permissions_message( $course_id ){
816
+	}
817
+	/**
818
+	 * Show the no permissions message when a user is logged in
819
+	 * and have not yet purchased the current course
820
+	 *
821
+	 * @since 1.9.0
822
+	 */
823
+	public static function the_course_no_permissions_message( $course_id ){
824 824
 
825
-        // login link
826
-        $my_courses_page_id = intval( Sensei()->settings->settings[ 'my_course_page' ] );
827
-        $login_link =  '<a href="' . esc_url( get_permalink( $my_courses_page_id ) ) . '">' . __( 'log in', 'woothemes-sensei' ) . '</a>';
825
+		// login link
826
+		$my_courses_page_id = intval( Sensei()->settings->settings[ 'my_course_page' ] );
827
+		$login_link =  '<a href="' . esc_url( get_permalink( $my_courses_page_id ) ) . '">' . __( 'log in', 'woothemes-sensei' ) . '</a>';
828 828
 
829
-        ?>
829
+		?>
830 830
 
831 831
         <span class="add-to-cart-login">
832 832
             <?php echo sprintf( __( 'Or %1$s to access your purchased courses', 'woothemes-sensei' ), $login_link ); ?>
@@ -834,765 +834,765 @@  discard block
 block discarded – undo
834 834
 
835 835
     <?php }
836 836
 
837
-    /**
838
-     * Checks if a user has bought a product item.
839
-     *
840
-     * @since  1.9.0
841
-     *
842
-     * @param  int $user_id
843
-     * @param  int $product_id
844
-     *
845
-     * @return bool
846
-     */
847
-    public static function has_customer_bought_product ( $user_id, $product_id ){
837
+	/**
838
+	 * Checks if a user has bought a product item.
839
+	 *
840
+	 * @since  1.9.0
841
+	 *
842
+	 * @param  int $user_id
843
+	 * @param  int $product_id
844
+	 *
845
+	 * @return bool
846
+	 */
847
+	public static function has_customer_bought_product ( $user_id, $product_id ){
848 848
 
849
-        $orders = get_posts( array(
850
-            'numberposts' => -1,
851
-            'post_type' => 'shope_order',
852
-            'meta_key'    => '_customer_user',
853
-            'meta_value'  => intval( $user_id ),
854
-            'post_status' => array( 'wc-complete','wc-processing' ),
855
-        ) );
856
-
857
-        foreach ( $orders as $order_id ) {
849
+		$orders = get_posts( array(
850
+			'numberposts' => -1,
851
+			'post_type' => 'shope_order',
852
+			'meta_key'    => '_customer_user',
853
+			'meta_value'  => intval( $user_id ),
854
+			'post_status' => array( 'wc-complete','wc-processing' ),
855
+		) );
856
+
857
+		foreach ( $orders as $order_id ) {
858 858
 
859
-            $order = new WC_Order( $order_id->ID );
860
-
861
-            // wc-active is the subscriptions complete status
862
-            if ( ! in_array( $order->post_status, array( 'wc-complete','wc-processing' ) ) ){
863
-
864
-                continue;
865
-
866
-            }
867
-
868
-            if ( ! ( 0 < sizeof( $order->get_items() ) ) ) {
859
+			$order = new WC_Order( $order_id->ID );
860
+
861
+			// wc-active is the subscriptions complete status
862
+			if ( ! in_array( $order->post_status, array( 'wc-complete','wc-processing' ) ) ){
863
+
864
+				continue;
865
+
866
+			}
867
+
868
+			if ( ! ( 0 < sizeof( $order->get_items() ) ) ) {
869 869
 
870
-                continue;
870
+				continue;
871 871
 
872
-            }
872
+			}
873 873
 
874
-            foreach( $order->get_items() as $item ) {
874
+			foreach( $order->get_items() as $item ) {
875 875
 
876
-                // Check if user has bought product
877
-                if ( $item['product_id'] == $product_id || $item['variation_id'] == $product_id ) {
876
+				// Check if user has bought product
877
+				if ( $item['product_id'] == $product_id || $item['variation_id'] == $product_id ) {
878 878
 
879
-                    // Check if user has an active subscription for product
880
-                    if( class_exists( 'WC_Subscriptions_Manager' ) ) {
881
-                        $sub_key = wcs_get_subscription( $order );
882
-                        if( $sub_key ) {
883
-                            $sub = wcs_get_subscription( $sub_key );
884
-                            if( $sub && isset( $sub['status'] ) ) {
885
-                                if( 'active' == $sub['status'] ) {
886
-                                    return true;
887
-                                } else {
888
-                                    return false;
889
-                                }
890
-                            }
891
-                        }
892
-                    }
879
+					// Check if user has an active subscription for product
880
+					if( class_exists( 'WC_Subscriptions_Manager' ) ) {
881
+						$sub_key = wcs_get_subscription( $order );
882
+						if( $sub_key ) {
883
+							$sub = wcs_get_subscription( $sub_key );
884
+							if( $sub && isset( $sub['status'] ) ) {
885
+								if( 'active' == $sub['status'] ) {
886
+									return true;
887
+								} else {
888
+									return false;
889
+								}
890
+							}
891
+						}
892
+					}
893 893
 
894
-                    // Customer has bought product
895
-                    return true;
896
-                } // End If Statement
894
+					// Customer has bought product
895
+					return true;
896
+				} // End If Statement
897 897
 
898
-            } // End For each item
898
+			} // End For each item
899 899
 
900
-        } // End For each order
900
+		} // End For each order
901 901
 
902
-    } // end has customer bought product
902
+	} // end has customer bought product
903 903
 
904
-    /**
905
-     * Return the product id for the given course
906
-     *
907
-     * @since 1.9.0
908
-     *
909
-     * @param int $course_id
910
-     *
911
-     * @return string $woocommerce_product_id or false if none exist
912
-     *
913
-     */
914
-    public static function get_course_product_id( $course_id ){
904
+	/**
905
+	 * Return the product id for the given course
906
+	 *
907
+	 * @since 1.9.0
908
+	 *
909
+	 * @param int $course_id
910
+	 *
911
+	 * @return string $woocommerce_product_id or false if none exist
912
+	 *
913
+	 */
914
+	public static function get_course_product_id( $course_id ){
915 915
 
916
-        $product_id =  get_post_meta( $course_id, '_course_woocommerce_product', true );
916
+		$product_id =  get_post_meta( $course_id, '_course_woocommerce_product', true );
917 917
 
918
-        if( empty( $product_id ) || 'product' != get_post_type( $product_id ) ){
919
-            return false;
920
-        }
918
+		if( empty( $product_id ) || 'product' != get_post_type( $product_id ) ){
919
+			return false;
920
+		}
921 921
 
922
-        return $product_id;
922
+		return $product_id;
923 923
 
924
-    }
924
+	}
925 925
 
926
-    /**
927
-     * Alter the body classes adding WooCommerce to the body
928
-     *
929
-     * Speciall cases where this is needed is template no-permissions.php
930
-     *
931
-     * @param array $classes
932
-     * @return array
933
-     */
934
-    public static function add_woocommerce_body_class( $classes ){
926
+	/**
927
+	 * Alter the body classes adding WooCommerce to the body
928
+	 *
929
+	 * Speciall cases where this is needed is template no-permissions.php
930
+	 *
931
+	 * @param array $classes
932
+	 * @return array
933
+	 */
934
+	public static function add_woocommerce_body_class( $classes ){
935 935
 
936
-        if( ! in_array( 'woocommerce', $classes ) && defined( 'SENSEI_NO_PERMISSION' ) && SENSEI_NO_PERMISSION ){
936
+		if( ! in_array( 'woocommerce', $classes ) && defined( 'SENSEI_NO_PERMISSION' ) && SENSEI_NO_PERMISSION ){
937 937
 
938
-            $classes[] ='woocommerce';
938
+			$classes[] ='woocommerce';
939 939
 
940
-        }
940
+		}
941 941
 
942
-        return $classes;
942
+		return $classes;
943 943
 
944
-    }
944
+	}
945 945
 
946
-    /**
947
-     * Responds to when a subscription product is purchased
948
-     *
949
-     * @since   1.2.0
950
-     * @since  1.9.0 move to class Sensei_WC
951
-     *
952
-     * @param   WC_Order $order
953
-     *
954
-     * @return  void
955
-     */
956
-    public static function activate_subscription(  $order ) {
946
+	/**
947
+	 * Responds to when a subscription product is purchased
948
+	 *
949
+	 * @since   1.2.0
950
+	 * @since  1.9.0 move to class Sensei_WC
951
+	 *
952
+	 * @param   WC_Order $order
953
+	 *
954
+	 * @return  void
955
+	 */
956
+	public static function activate_subscription(  $order ) {
957 957
 
958
-        $order_user = get_user_by('id', $order->user_id);
959
-        $user['ID'] = $order_user->ID;
960
-        $user['user_login'] = $order_user->user_login;
961
-        $user['user_email'] = $order_user->user_email;
962
-        $user['user_url'] = $order_user->user_url;
958
+		$order_user = get_user_by('id', $order->user_id);
959
+		$user['ID'] = $order_user->ID;
960
+		$user['user_login'] = $order_user->user_login;
961
+		$user['user_email'] = $order_user->user_email;
962
+		$user['user_url'] = $order_user->user_url;
963 963
 
964
-        // Run through each product ordered
965
-        if ( ! sizeof($order->get_items() )>0 ) {
964
+		// Run through each product ordered
965
+		if ( ! sizeof($order->get_items() )>0 ) {
966 966
 
967
-            return;
967
+			return;
968 968
 
969
-        }
969
+		}
970 970
 
971
-        foreach($order->get_items() as $item) {
971
+		foreach($order->get_items() as $item) {
972 972
 
973
-            $product_type = '';
973
+			$product_type = '';
974 974
 
975
-            if (isset($item['variation_id']) && $item['variation_id'] > 0) {
975
+			if (isset($item['variation_id']) && $item['variation_id'] > 0) {
976 976
 
977
-                $item_id = $item['variation_id'];
978
-                $product_type = 'subscription_variation';
977
+				$item_id = $item['variation_id'];
978
+				$product_type = 'subscription_variation';
979 979
 
980
-            } else {
980
+			} else {
981 981
 
982
-                $item_id = $item['product_id'];
982
+				$item_id = $item['product_id'];
983 983
 
984
-            } // End If Statement
984
+			} // End If Statement
985 985
 
986
-            $_product = self::get_product_object( $item_id, $product_type );
986
+			$_product = self::get_product_object( $item_id, $product_type );
987 987
 
988
-            // Get courses that use the WC product
989
-            $courses = array();
988
+			// Get courses that use the WC product
989
+			$courses = array();
990 990
 
991
-            if ( ! in_array( $product_type, self::get_subscription_types() ) ) {
991
+			if ( ! in_array( $product_type, self::get_subscription_types() ) ) {
992 992
 
993
-                $courses = Sensei()->course->get_product_courses( $item_id );
993
+				$courses = Sensei()->course->get_product_courses( $item_id );
994 994
 
995
-            } // End If Statement
995
+			} // End If Statement
996 996
 
997
-            // Loop and add the user to the course.
998
-            foreach ( $courses as $course_item ){
997
+			// Loop and add the user to the course.
998
+			foreach ( $courses as $course_item ){
999 999
 
1000
-                Sensei_Utils::user_start_course( intval( $user['ID'] ), $course_item->ID  );
1000
+				Sensei_Utils::user_start_course( intval( $user['ID'] ), $course_item->ID  );
1001 1001
 
1002
-            } // End For Loop
1002
+			} // End For Loop
1003 1003
 
1004
-        } // End For Loop
1004
+		} // End For Loop
1005 1005
 
1006
-    } // End activate_subscription()
1006
+	} // End activate_subscription()
1007 1007
 
1008
-    /**
1009
-     * Adds detail to to the WooCommerce order
1010
-     *
1011
-     * @since   1.4.5
1012
-     * @since 1.9.0 function moved to class Sensei_WC and renamed from sensei_woocommerce_email_course_details to email_course_details
1013
-     *
1014
-     * @param   WC_Order $order
1015
-     *
1016
-     * @return  void
1017
-     */
1018
-    public static function email_course_details(  $order ){
1008
+	/**
1009
+	 * Adds detail to to the WooCommerce order
1010
+	 *
1011
+	 * @since   1.4.5
1012
+	 * @since 1.9.0 function moved to class Sensei_WC and renamed from sensei_woocommerce_email_course_details to email_course_details
1013
+	 *
1014
+	 * @param   WC_Order $order
1015
+	 *
1016
+	 * @return  void
1017
+	 */
1018
+	public static function email_course_details(  $order ){
1019 1019
 
1020
-        global $woocommerce;
1020
+		global $woocommerce;
1021 1021
 
1022
-        // exit early if not wc-completed or wc-processing
1023
-        if( 'wc-completed' != $order->post_status
1024
-            && 'wc-processing' != $order->post_status  ) {
1025
-            return;
1026
-        }
1022
+		// exit early if not wc-completed or wc-processing
1023
+		if( 'wc-completed' != $order->post_status
1024
+			&& 'wc-processing' != $order->post_status  ) {
1025
+			return;
1026
+		}
1027 1027
 
1028
-        $order_items = $order->get_items();
1029
-        $order_id = $order->id;
1028
+		$order_items = $order->get_items();
1029
+		$order_id = $order->id;
1030 1030
 
1031
-        //If object have items go through them all to find course
1032
-        if ( 0 < sizeof( $order_items ) ) {
1031
+		//If object have items go through them all to find course
1032
+		if ( 0 < sizeof( $order_items ) ) {
1033 1033
 
1034
-            $course_details_html =  '<h2>' . __( 'Course details', 'woothemes-sensei' ) . '</h2>';
1035
-            $order_contains_courses = false;
1034
+			$course_details_html =  '<h2>' . __( 'Course details', 'woothemes-sensei' ) . '</h2>';
1035
+			$order_contains_courses = false;
1036 1036
 
1037 1037
 
1038
-            foreach ( $order_items as $item ) {
1038
+			foreach ( $order_items as $item ) {
1039 1039
 
1040
-                $product_type = '';
1041
-                if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
1042
-                    // If item has variation_id then its from variation
1043
-                    $item_id = $item['variation_id'];
1044
-                    $product_type = 'variation';
1045
-                } else {
1046
-                    // If not its real product set its id to item_id
1047
-                    $item_id = $item['product_id'];
1048
-                } // End If Statement
1040
+				$product_type = '';
1041
+				if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
1042
+					// If item has variation_id then its from variation
1043
+					$item_id = $item['variation_id'];
1044
+					$product_type = 'variation';
1045
+				} else {
1046
+					// If not its real product set its id to item_id
1047
+					$item_id = $item['product_id'];
1048
+				} // End If Statement
1049 1049
 
1050
-                $user_id = get_post_meta( $order_id, '_customer_user', true );
1050
+				$user_id = get_post_meta( $order_id, '_customer_user', true );
1051 1051
 
1052
-                if( $user_id ) {
1052
+				if( $user_id ) {
1053 1053
 
1054
-                    // Get all courses for product
1055
-                    $args = array(
1056
-                        'posts_per_page' => -1,
1057
-                        'post_type' => 'course',
1058
-                        'meta_query' => array(
1059
-                            array(
1060
-                                'key' => '_course_woocommerce_product',
1061
-                                'value' => $item_id
1062
-                            )
1063
-                        ),
1064
-                        'orderby' => 'menu_order date',
1065
-                        'order' => 'ASC',
1066
-                    );
1067
-                    $courses = get_posts( $args );
1054
+					// Get all courses for product
1055
+					$args = array(
1056
+						'posts_per_page' => -1,
1057
+						'post_type' => 'course',
1058
+						'meta_query' => array(
1059
+							array(
1060
+								'key' => '_course_woocommerce_product',
1061
+								'value' => $item_id
1062
+							)
1063
+						),
1064
+						'orderby' => 'menu_order date',
1065
+						'order' => 'ASC',
1066
+					);
1067
+					$courses = get_posts( $args );
1068 1068
 
1069
-                    if( $courses && count( $courses ) > 0 ) {
1069
+					if( $courses && count( $courses ) > 0 ) {
1070 1070
 
1071
-                        foreach( $courses as $course ) {
1071
+						foreach( $courses as $course ) {
1072 1072
 
1073
-                            $title = $course->post_title;
1074
-                            $permalink = get_permalink( $course->ID );
1075
-                            $order_contains_courses = true;
1076
-                            $course_details_html .=  '<p><strong>' . sprintf( __( 'View course: %1$s', 'woothemes-sensei' ), '</strong><a href="' . esc_url( $permalink ) . '">' . $title . '</a>' ) . '</p>';
1077
-                        }
1073
+							$title = $course->post_title;
1074
+							$permalink = get_permalink( $course->ID );
1075
+							$order_contains_courses = true;
1076
+							$course_details_html .=  '<p><strong>' . sprintf( __( 'View course: %1$s', 'woothemes-sensei' ), '</strong><a href="' . esc_url( $permalink ) . '">' . $title . '</a>' ) . '</p>';
1077
+						}
1078 1078
 
1079 1079
 
1080
-                    } // end if has courses
1080
+					} // end if has courses
1081 1081
 
1082
-                } // end if $userPid
1082
+				} // end if $userPid
1083 1083
 
1084
-            } // end for each order item
1084
+			} // end for each order item
1085 1085
 
1086
-            // Output Course details
1087
-            if( $order_contains_courses ){
1086
+			// Output Course details
1087
+			if( $order_contains_courses ){
1088 1088
 
1089
-                echo $course_details_html;
1089
+				echo $course_details_html;
1090 1090
 
1091
-            }
1091
+			}
1092 1092
 
1093 1093
 
1094
-        } // end if  order items not empty
1094
+		} // end if  order items not empty
1095 1095
 
1096
-    }// end email_course_details
1096
+	}// end email_course_details
1097 1097
 
1098
-    /**
1099
-     * sensei_woocommerce_complete_order description
1100
-     * @since   1.0.3
1101
-     * @access  public
1102
-     * @param   int $order_id WC order ID
1103
-     * @return  void
1104
-     */
1105
-    public static function complete_order ( $order_id = 0 ) {
1098
+	/**
1099
+	 * sensei_woocommerce_complete_order description
1100
+	 * @since   1.0.3
1101
+	 * @access  public
1102
+	 * @param   int $order_id WC order ID
1103
+	 * @return  void
1104
+	 */
1105
+	public static function complete_order ( $order_id = 0 ) {
1106 1106
 
1107
-        $order_user = array();
1107
+		$order_user = array();
1108 1108
 
1109
-        // Check for WooCommerce
1110
-        if ( Sensei_WC::is_woocommerce_active() && ( 0 < $order_id ) ) {
1111
-            // Get order object
1112
-            $order = new WC_Order( $order_id );
1113
-            $user = get_user_by( 'id', $order->get_user_id() );
1114
-            $order_user['ID'] = $user->ID;
1115
-            $order_user['user_login'] = $user->user_login;
1116
-            $order_user['user_email'] = $user->user_email;
1117
-            $order_user['user_url'] = $user->user_url;
1118
-            // Run through each product ordered
1119
-            if ( 0 < sizeof( $order->get_items() ) ) {
1109
+		// Check for WooCommerce
1110
+		if ( Sensei_WC::is_woocommerce_active() && ( 0 < $order_id ) ) {
1111
+			// Get order object
1112
+			$order = new WC_Order( $order_id );
1113
+			$user = get_user_by( 'id', $order->get_user_id() );
1114
+			$order_user['ID'] = $user->ID;
1115
+			$order_user['user_login'] = $user->user_login;
1116
+			$order_user['user_email'] = $user->user_email;
1117
+			$order_user['user_url'] = $user->user_url;
1118
+			// Run through each product ordered
1119
+			if ( 0 < sizeof( $order->get_items() ) ) {
1120 1120
 
1121
-                foreach( $order->get_items() as $item ) {
1121
+				foreach( $order->get_items() as $item ) {
1122 1122
 
1123
-                    $product_type = '';
1124
-                    if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
1123
+					$product_type = '';
1124
+					if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
1125 1125
 
1126
-                        $item_id = $item['variation_id'];
1127
-                        $product_type = 'variation';
1126
+						$item_id = $item['variation_id'];
1127
+						$product_type = 'variation';
1128 1128
 
1129
-                    } else {
1129
+					} else {
1130 1130
 
1131
-                        $item_id = $item['product_id'];
1131
+						$item_id = $item['product_id'];
1132 1132
 
1133
-                    } // End If Statement
1133
+					} // End If Statement
1134 1134
 
1135
-                    $_product = Sensei_WC::get_product_object( $item_id, $product_type );
1135
+					$_product = Sensei_WC::get_product_object( $item_id, $product_type );
1136 1136
 
1137
-                    // Get courses that use the WC product
1138
-                    $courses = Sensei()->course->get_product_courses( $_product->id );
1137
+					// Get courses that use the WC product
1138
+					$courses = Sensei()->course->get_product_courses( $_product->id );
1139 1139
 
1140
-                    // Loop and update those courses
1141
-                    foreach ( $courses as $course_item ) {
1140
+					// Loop and update those courses
1141
+					foreach ( $courses as $course_item ) {
1142 1142
 
1143
-                        $update_course = Sensei()->woocommerce_course_update( $course_item->ID, $order_user );
1143
+						$update_course = Sensei()->woocommerce_course_update( $course_item->ID, $order_user );
1144 1144
 
1145
-                    } // End For Loop
1145
+					} // End For Loop
1146 1146
 
1147
-                } // End For Loop
1147
+				} // End For Loop
1148 1148
 
1149
-            } // End If Statement
1150
-            // Add meta to indicate that payment has been completed successfully
1151
-            update_post_meta( $order_id, 'sensei_payment_complete', '1' );
1149
+			} // End If Statement
1150
+			// Add meta to indicate that payment has been completed successfully
1151
+			update_post_meta( $order_id, 'sensei_payment_complete', '1' );
1152 1152
 
1153
-        } // End If Statement
1153
+		} // End If Statement
1154 1154
 
1155
-    } // End sensei_woocommerce_complete_order()
1155
+	} // End sensei_woocommerce_complete_order()
1156 1156
 
1157
-    /**
1158
-     * Responds to when an order is cancelled.
1159
-     *
1160
-     * @since   1.2.0
1161
-     * @since   1.9.0 Move function to the Sensei_WC class
1162
-     * @param   integer| WC_Order $order_id order ID
1163
-     * @return  void
1164
-     */
1165
-    public static function cancel_order ( $order_id ) {
1157
+	/**
1158
+	 * Responds to when an order is cancelled.
1159
+	 *
1160
+	 * @since   1.2.0
1161
+	 * @since   1.9.0 Move function to the Sensei_WC class
1162
+	 * @param   integer| WC_Order $order_id order ID
1163
+	 * @return  void
1164
+	 */
1165
+	public static function cancel_order ( $order_id ) {
1166 1166
 
1167
-        // Get order object
1168
-        if( is_object( $order_id ) ){
1167
+		// Get order object
1168
+		if( is_object( $order_id ) ){
1169 1169
 
1170
-            $order = $order_id;
1170
+			$order = $order_id;
1171 1171
 
1172
-        }else{
1172
+		}else{
1173 1173
 
1174
-            $order = new WC_Order( $order_id );
1175
-        }
1174
+			$order = new WC_Order( $order_id );
1175
+		}
1176 1176
 
1177
-        // Run through each product ordered
1178
-        if ( 0 < sizeof( $order->get_items() ) ) {
1177
+		// Run through each product ordered
1178
+		if ( 0 < sizeof( $order->get_items() ) ) {
1179 1179
 
1180
-            // Get order user
1181
-            $user_id = $order->__get( 'user_id' );
1180
+			// Get order user
1181
+			$user_id = $order->__get( 'user_id' );
1182 1182
 
1183
-            foreach( $order->get_items() as $item ) {
1183
+			foreach( $order->get_items() as $item ) {
1184 1184
 
1185
-                $product_type = '';
1186
-                if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
1185
+				$product_type = '';
1186
+				if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
1187 1187
 
1188
-                    $item_id = $item['variation_id'];
1189
-                    $product_type = 'variation';
1188
+					$item_id = $item['variation_id'];
1189
+					$product_type = 'variation';
1190 1190
 
1191
-                } else {
1191
+				} else {
1192 1192
 
1193
-                    $item_id = $item['product_id'];
1193
+					$item_id = $item['product_id'];
1194 1194
 
1195
-                } // End If Statement
1195
+				} // End If Statement
1196 1196
 
1197
-                $_product = Sensei_WC::get_product_object( $item_id, $product_type );
1197
+				$_product = Sensei_WC::get_product_object( $item_id, $product_type );
1198 1198
 
1199
-                // Get courses that use the WC product
1200
-                $courses = array();
1201
-                $courses = Sensei()->course->get_product_courses( $item_id );
1199
+				// Get courses that use the WC product
1200
+				$courses = array();
1201
+				$courses = Sensei()->course->get_product_courses( $item_id );
1202 1202
 
1203
-                // Loop and update those courses
1204
-                foreach ($courses as $course_item){
1203
+				// Loop and update those courses
1204
+				foreach ($courses as $course_item){
1205 1205
 
1206
-                    // Check and Remove course from courses user meta
1207
-                    $dataset_changes = Sensei_Utils::sensei_remove_user_from_course( $course_item->ID, $user_id );
1206
+					// Check and Remove course from courses user meta
1207
+					$dataset_changes = Sensei_Utils::sensei_remove_user_from_course( $course_item->ID, $user_id );
1208 1208
 
1209
-                } // End For Loop
1209
+				} // End For Loop
1210 1210
 
1211
-            } // End For Loop
1211
+			} // End For Loop
1212 1212
 
1213
-        } // End If Statement
1213
+		} // End If Statement
1214 1214
 
1215
-    } // End sensei_woocommerce_cancel_order()
1215
+	} // End sensei_woocommerce_cancel_order()
1216 1216
 
1217
-    /**
1218
-     * Returns the WooCommerce Product Object
1219
-     *
1220
-     * The code caters for pre and post WooCommerce 2.2 installations.
1221
-     *
1222
-     * @since   1.1.1
1223
-     * @access  public
1224
-     * @param   integer $wc_product_id Product ID or Variation ID
1225
-     * @param   string  $product_type  '' or 'variation'
1226
-     * @return   WC_Product $wc_product_object
1227
-     */
1228
-    public static function get_product_object ( $wc_product_id = 0, $product_type = '' ) {
1217
+	/**
1218
+	 * Returns the WooCommerce Product Object
1219
+	 *
1220
+	 * The code caters for pre and post WooCommerce 2.2 installations.
1221
+	 *
1222
+	 * @since   1.1.1
1223
+	 * @access  public
1224
+	 * @param   integer $wc_product_id Product ID or Variation ID
1225
+	 * @param   string  $product_type  '' or 'variation'
1226
+	 * @return   WC_Product $wc_product_object
1227
+	 */
1228
+	public static function get_product_object ( $wc_product_id = 0, $product_type = '' ) {
1229 1229
 
1230
-        $wc_product_object = false;
1231
-        if ( 0 < intval( $wc_product_id ) ) {
1230
+		$wc_product_object = false;
1231
+		if ( 0 < intval( $wc_product_id ) ) {
1232 1232
 
1233
-            // Get the product
1234
-            if ( function_exists( 'wc_get_product' ) ) {
1233
+			// Get the product
1234
+			if ( function_exists( 'wc_get_product' ) ) {
1235 1235
 
1236
-                $wc_product_object = wc_get_product( $wc_product_id ); // Post WC 2.3
1236
+				$wc_product_object = wc_get_product( $wc_product_id ); // Post WC 2.3
1237 1237
 
1238
-            } elseif ( function_exists( 'get_product' ) ) {
1238
+			} elseif ( function_exists( 'get_product' ) ) {
1239 1239
 
1240
-                $wc_product_object = get_product( $wc_product_id ); // Post WC 2.0
1240
+				$wc_product_object = get_product( $wc_product_id ); // Post WC 2.0
1241 1241
 
1242
-            } else {
1242
+			} else {
1243 1243
 
1244
-                // Pre WC 2.0
1245
-                if ( 'variation' == $product_type || 'subscription_variation' == $product_type ) {
1244
+				// Pre WC 2.0
1245
+				if ( 'variation' == $product_type || 'subscription_variation' == $product_type ) {
1246 1246
 
1247
-                    $wc_product_object = new WC_Product_Variation( $wc_product_id );
1247
+					$wc_product_object = new WC_Product_Variation( $wc_product_id );
1248 1248
 
1249
-                } else {
1249
+				} else {
1250 1250
 
1251
-                    $wc_product_object = new WC_Product( $wc_product_id );
1251
+					$wc_product_object = new WC_Product( $wc_product_id );
1252 1252
 
1253
-                } // End If Statement
1253
+				} // End If Statement
1254 1254
 
1255
-            } // End If Statement
1255
+			} // End If Statement
1256 1256
 
1257
-        } // End If Statement
1257
+		} // End If Statement
1258 1258
 
1259
-        return $wc_product_object;
1259
+		return $wc_product_object;
1260 1260
 
1261
-    } // End sensei_get_woocommerce_product_object()
1261
+	} // End sensei_get_woocommerce_product_object()
1262 1262
 
1263
-    /**
1264
-     * If customer has purchased the course, update Sensei to indicate that they are taking the course.
1265
-     *
1266
-     * @since  1.0.0
1267
-     * @since 1.9.0 move to class Sensei_WC
1268
-     *
1269
-     * @param  int 			$course_id  (default: 0)
1270
-     * @param  array/Object $order_user (default: array()) Specific user's data.
1271
-     *
1272
-     * @return bool|int
1273
-     */
1274
-    public static function course_update ( $course_id = 0, $order_user = array()  ) {
1263
+	/**
1264
+	 * If customer has purchased the course, update Sensei to indicate that they are taking the course.
1265
+	 *
1266
+	 * @since  1.0.0
1267
+	 * @since 1.9.0 move to class Sensei_WC
1268
+	 *
1269
+	 * @param  int 			$course_id  (default: 0)
1270
+	 * @param  array/Object $order_user (default: array()) Specific user's data.
1271
+	 *
1272
+	 * @return bool|int
1273
+	 */
1274
+	public static function course_update ( $course_id = 0, $order_user = array()  ) {
1275 1275
 
1276
-        global $current_user;
1276
+		global $current_user;
1277 1277
 
1278
-        if ( ! isset( $current_user ) || !$current_user->ID > 0 ) return false;
1278
+		if ( ! isset( $current_user ) || !$current_user->ID > 0 ) return false;
1279 1279
 
1280
-        $data_update = false;
1280
+		$data_update = false;
1281 1281
 
1282
-        // Get the product ID
1283
-        $wc_post_id = get_post_meta( intval( $course_id ), '_course_woocommerce_product', true );
1282
+		// Get the product ID
1283
+		$wc_post_id = get_post_meta( intval( $course_id ), '_course_woocommerce_product', true );
1284 1284
 
1285
-        // Check if in the admin
1286
-        if ( is_admin() ) {
1285
+		// Check if in the admin
1286
+		if ( is_admin() ) {
1287 1287
 
1288
-            $user_login = $order_user['user_login'];
1289
-            $user_email = $order_user['user_email'];
1290
-            $user_url = $order_user['user_url'];
1291
-            $user_id = $order_user['ID'];
1288
+			$user_login = $order_user['user_login'];
1289
+			$user_email = $order_user['user_email'];
1290
+			$user_url = $order_user['user_url'];
1291
+			$user_id = $order_user['ID'];
1292 1292
 
1293
-        } else {
1293
+		} else {
1294 1294
 
1295
-            $user_login = $current_user->user_login;
1296
-            $user_email = $current_user->user_email;
1297
-            $user_url = $current_user->user_url;
1298
-            $user_id = $current_user->ID;
1295
+			$user_login = $current_user->user_login;
1296
+			$user_email = $current_user->user_email;
1297
+			$user_url = $current_user->user_url;
1298
+			$user_id = $current_user->ID;
1299 1299
 
1300
-        } // End If Statement
1300
+		} // End If Statement
1301 1301
 
1302
-        // This doesn't appear to be purely WooCommerce related. Should it be in a separate function?
1303
-        $course_prerequisite_id = (int) get_post_meta( $course_id, '_course_prerequisite', true );
1304
-        if( 0 < absint( $course_prerequisite_id ) ) {
1302
+		// This doesn't appear to be purely WooCommerce related. Should it be in a separate function?
1303
+		$course_prerequisite_id = (int) get_post_meta( $course_id, '_course_prerequisite', true );
1304
+		if( 0 < absint( $course_prerequisite_id ) ) {
1305 1305
 
1306
-            $prereq_course_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, intval( $user_id ) );
1307
-            if ( ! $prereq_course_complete ) {
1306
+			$prereq_course_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, intval( $user_id ) );
1307
+			if ( ! $prereq_course_complete ) {
1308 1308
 
1309
-                // Remove all course user meta
1310
-                return Sensei_Utils::sensei_remove_user_from_course( $course_id, $user_id );
1309
+				// Remove all course user meta
1310
+				return Sensei_Utils::sensei_remove_user_from_course( $course_id, $user_id );
1311 1311
 
1312
-            }
1313
-        }
1312
+			}
1313
+		}
1314 1314
 
1315
-        $is_user_taking_course = Sensei_Utils::user_started_course( intval( $course_id ), intval( $user_id ) );
1315
+		$is_user_taking_course = Sensei_Utils::user_started_course( intval( $course_id ), intval( $user_id ) );
1316 1316
 
1317
-        if( ! $is_user_taking_course ) {
1317
+		if( ! $is_user_taking_course ) {
1318 1318
 
1319
-            if ( Sensei_WC::is_woocommerce_active() && Sensei_WC::has_customer_bought_product( $user_id, $wc_post_id ) && ( 0 < $wc_post_id ) ) {
1319
+			if ( Sensei_WC::is_woocommerce_active() && Sensei_WC::has_customer_bought_product( $user_id, $wc_post_id ) && ( 0 < $wc_post_id ) ) {
1320 1320
 
1321
-                $activity_logged = Sensei_Utils::user_start_course( intval( $user_id), intval( $course_id ) );
1321
+				$activity_logged = Sensei_Utils::user_start_course( intval( $user_id), intval( $course_id ) );
1322 1322
 
1323
-                $is_user_taking_course = false;
1324
-                if ( true == $activity_logged ) {
1323
+				$is_user_taking_course = false;
1324
+				if ( true == $activity_logged ) {
1325 1325
 
1326
-                    $is_user_taking_course = true;
1326
+					$is_user_taking_course = true;
1327 1327
 
1328
-                } // End If Statement
1328
+				} // End If Statement
1329 1329
 
1330
-            } // End If Statement
1331
-        }// end if is user taking course
1330
+			} // End If Statement
1331
+		}// end if is user taking course
1332 1332
 
1333
-        return $is_user_taking_course;
1333
+		return $is_user_taking_course;
1334 1334
 
1335
-    } // End course_update()
1335
+	} // End course_update()
1336 1336
 
1337
-    /**
1338
-     * Disable guest checkout if a course product is in the cart
1339
-     *
1340
-     * @since 1.1.0
1341
-     * @since 1.9.0 move to class Sensei_WC
1342
-     *
1343
-     * @param  boolean $guest_checkout Current guest checkout setting
1344
-     *
1345
-     * @return boolean                 Modified guest checkout setting
1346
-     */
1347
-    public static function disable_guest_checkout( $guest_checkout ) {
1337
+	/**
1338
+	 * Disable guest checkout if a course product is in the cart
1339
+	 *
1340
+	 * @since 1.1.0
1341
+	 * @since 1.9.0 move to class Sensei_WC
1342
+	 *
1343
+	 * @param  boolean $guest_checkout Current guest checkout setting
1344
+	 *
1345
+	 * @return boolean                 Modified guest checkout setting
1346
+	 */
1347
+	public static function disable_guest_checkout( $guest_checkout ) {
1348 1348
 
1349
-        if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
1349
+		if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
1350 1350
 
1351
-            if( isset( WC()->cart->cart_contents ) && count( WC()->cart->cart_contents ) > 0 ) {
1351
+			if( isset( WC()->cart->cart_contents ) && count( WC()->cart->cart_contents ) > 0 ) {
1352 1352
 
1353
-                foreach( WC()->cart->cart_contents as $cart_key => $product ) {
1354
-                    if( isset( $product['product_id'] ) ) {
1353
+				foreach( WC()->cart->cart_contents as $cart_key => $product ) {
1354
+					if( isset( $product['product_id'] ) ) {
1355 1355
 
1356
-                        $args = array(
1357
-                            'posts_per_page' => -1,
1358
-                            'post_type' => 'course',
1359
-                            'meta_query' => array(
1360
-                                array(
1361
-                                    'key' => '_course_woocommerce_product',
1362
-                                    'value' => $product['product_id']
1363
-                                )
1364
-                            )
1365
-                        );
1356
+						$args = array(
1357
+							'posts_per_page' => -1,
1358
+							'post_type' => 'course',
1359
+							'meta_query' => array(
1360
+								array(
1361
+									'key' => '_course_woocommerce_product',
1362
+									'value' => $product['product_id']
1363
+								)
1364
+							)
1365
+						);
1366 1366
 
1367
-                        $posts = get_posts( $args );
1367
+						$posts = get_posts( $args );
1368 1368
 
1369
-                        if( $posts && count( $posts ) > 0 ) {
1369
+						if( $posts && count( $posts ) > 0 ) {
1370 1370
 
1371
-                            foreach( $posts as $course ) {
1372
-                                $guest_checkout = '';
1373
-                                break;
1371
+							foreach( $posts as $course ) {
1372
+								$guest_checkout = '';
1373
+								break;
1374 1374
 
1375
-                            }
1376
-                        }
1375
+							}
1376
+						}
1377 1377
 
1378
-                    }
1378
+					}
1379 1379
 
1380
-                }
1380
+				}
1381 1381
 
1382
-            }
1383
-        }
1382
+			}
1383
+		}
1384 1384
 
1385
-        return $guest_checkout;
1385
+		return $guest_checkout;
1386 1386
 
1387
-    }// end disable_guest_checkout
1387
+	}// end disable_guest_checkout
1388 1388
 
1389
-    /**
1390
-     * Change order status with virtual products to completed
1391
-     *
1392
-     * @since  1.1.0
1393
-     * @since 1.9.0 move to class Sensei_WC
1394
-     *
1395
-     * @param string $order_status
1396
-     * @param int $order_id
1397
-     *
1398
-     * @return string
1399
-     **/
1400
-    public static function virtual_order_payment_complete( $order_status, $order_id ) {
1389
+	/**
1390
+	 * Change order status with virtual products to completed
1391
+	 *
1392
+	 * @since  1.1.0
1393
+	 * @since 1.9.0 move to class Sensei_WC
1394
+	 *
1395
+	 * @param string $order_status
1396
+	 * @param int $order_id
1397
+	 *
1398
+	 * @return string
1399
+	 **/
1400
+	public static function virtual_order_payment_complete( $order_status, $order_id ) {
1401 1401
 
1402
-        $order = new WC_Order( $order_id );
1402
+		$order = new WC_Order( $order_id );
1403 1403
 
1404
-        if ( ! isset ( $order ) ) return '';
1404
+		if ( ! isset ( $order ) ) return '';
1405 1405
 
1406
-        if ( $order_status == 'wc-processing' && ( $order->post_status == 'wc-on-hold' || $order->post_status == 'wc-pending' || $order->post_status == 'wc-failed' ) ) {
1406
+		if ( $order_status == 'wc-processing' && ( $order->post_status == 'wc-on-hold' || $order->post_status == 'wc-pending' || $order->post_status == 'wc-failed' ) ) {
1407 1407
 
1408
-            $virtual_order = true;
1408
+			$virtual_order = true;
1409 1409
 
1410
-            if ( count( $order->get_items() ) > 0 ) {
1410
+			if ( count( $order->get_items() ) > 0 ) {
1411 1411
 
1412
-                foreach( $order->get_items() as $item ) {
1412
+				foreach( $order->get_items() as $item ) {
1413 1413
 
1414
-                    if ( $item['product_id'] > 0 ) {
1415
-                        $_product = $order->get_product_from_item( $item );
1416
-                        if ( ! $_product->is_virtual() ) {
1414
+					if ( $item['product_id'] > 0 ) {
1415
+						$_product = $order->get_product_from_item( $item );
1416
+						if ( ! $_product->is_virtual() ) {
1417 1417
 
1418
-                            $virtual_order = false;
1419
-                            break;
1418
+							$virtual_order = false;
1419
+							break;
1420 1420
 
1421
-                        } // End If Statement
1421
+						} // End If Statement
1422 1422
 
1423
-                    } // End If Statement
1423
+					} // End If Statement
1424 1424
 
1425
-                } // End For Loop
1425
+				} // End For Loop
1426 1426
 
1427
-            } // End If Statement
1427
+			} // End If Statement
1428 1428
 
1429
-            // virtual order, mark as completed
1430
-            if ( $virtual_order ) {
1429
+			// virtual order, mark as completed
1430
+			if ( $virtual_order ) {
1431 1431
 
1432
-                return 'completed';
1432
+				return 'completed';
1433 1433
 
1434
-            } // End If Statement
1434
+			} // End If Statement
1435 1435
 
1436
-        } // End If Statement
1436
+		} // End If Statement
1437 1437
 
1438
-        return $order_status;
1438
+		return $order_status;
1439 1439
 
1440
-    }// end virtual_order_payment_complete
1440
+	}// end virtual_order_payment_complete
1441 1441
 
1442 1442
 
1443
-    /**
1444
-     * Determine if the user has and active subscription to give them access
1445
-     * to the requested resource.
1446
-     *
1447
-     * @since 1.9.0
1448
-     *
1449
-     * @param  boolean$user_access_permission
1450
-     * @param  integer $user_id
1451
-     * @return boolean $user_access_permission
1452
-     */
1453
-    public static function get_subscription_permission( $user_access_permission, $user_id ){
1443
+	/**
1444
+	 * Determine if the user has and active subscription to give them access
1445
+	 * to the requested resource.
1446
+	 *
1447
+	 * @since 1.9.0
1448
+	 *
1449
+	 * @param  boolean$user_access_permission
1450
+	 * @param  integer $user_id
1451
+	 * @return boolean $user_access_permission
1452
+	 */
1453
+	public static function get_subscription_permission( $user_access_permission, $user_id ){
1454 1454
 
1455
-        global $post;
1455
+		global $post;
1456 1456
 
1457
-        // ignore the current case if the following conditions are met
1458
-        if ( ! class_exists( 'WC_Subscriptions' ) || empty( $user_id )
1459
-            || ! in_array( $post->post_type, array( 'course','lesson','quiz' ) )
1460
-            || ! wcs_user_has_subscription( $user_id) ){
1457
+		// ignore the current case if the following conditions are met
1458
+		if ( ! class_exists( 'WC_Subscriptions' ) || empty( $user_id )
1459
+			|| ! in_array( $post->post_type, array( 'course','lesson','quiz' ) )
1460
+			|| ! wcs_user_has_subscription( $user_id) ){
1461 1461
 
1462
-            return $user_access_permission;
1462
+			return $user_access_permission;
1463 1463
 
1464
-        }
1464
+		}
1465 1465
 
1466
-        // at this user has a subscription
1467
-        // is the subscription on the the current course?
1466
+		// at this user has a subscription
1467
+		// is the subscription on the the current course?
1468 1468
 
1469
-        $course_id = 0;
1470
-        if ( 'course' == $post->post_type ){
1469
+		$course_id = 0;
1470
+		if ( 'course' == $post->post_type ){
1471 1471
 
1472
-            $course_id = $post->ID;
1472
+			$course_id = $post->ID;
1473 1473
 
1474
-        } elseif ( 'lesson' == $post->post_type ) {
1474
+		} elseif ( 'lesson' == $post->post_type ) {
1475 1475
 
1476
-            $course_id = Sensei()->lesson->get_course_id( $post->ID );
1476
+			$course_id = Sensei()->lesson->get_course_id( $post->ID );
1477 1477
 
1478
-        } else {
1478
+		} else {
1479 1479
 
1480
-            $lesson_id =  Sensei()->quiz->get_lesson_id( $post->ID );
1481
-            $course_id = Sensei()->lesson->get_course_id( $lesson_id );
1480
+			$lesson_id =  Sensei()->quiz->get_lesson_id( $post->ID );
1481
+			$course_id = Sensei()->lesson->get_course_id( $lesson_id );
1482 1482
 
1483
-        }
1483
+		}
1484 1484
 
1485
-        // if the course has no subscription WooCommerce product attached to return the permissions as is
1486
-        $product_id = Sensei_WC::get_course_product_id( $course_id );
1487
-        $product = wc_get_product( $product_id );
1488
-        if( ! in_array( $product->get_type(), self::get_subscription_types() ) ){
1485
+		// if the course has no subscription WooCommerce product attached to return the permissions as is
1486
+		$product_id = Sensei_WC::get_course_product_id( $course_id );
1487
+		$product = wc_get_product( $product_id );
1488
+		if( ! in_array( $product->get_type(), self::get_subscription_types() ) ){
1489 1489
 
1490
-            return $user_access_permission;
1490
+			return $user_access_permission;
1491 1491
 
1492
-        }
1492
+		}
1493 1493
 
1494
-        // give access if user has active subscription on the product otherwise restrict it.
1495
-        // also check if the user was added to the course directly after the subscription started.
1496
-        if( wcs_user_has_subscription( $user_id, $product_id, 'active'  )
1497
-            || wcs_user_has_subscription( $user_id, $product_id, 'pending-cancel'  )
1498
-            || self::was_user_added_without_subscription( $user_id, $product_id, $course_id  ) ){
1494
+		// give access if user has active subscription on the product otherwise restrict it.
1495
+		// also check if the user was added to the course directly after the subscription started.
1496
+		if( wcs_user_has_subscription( $user_id, $product_id, 'active'  )
1497
+			|| wcs_user_has_subscription( $user_id, $product_id, 'pending-cancel'  )
1498
+			|| self::was_user_added_without_subscription( $user_id, $product_id, $course_id  ) ){
1499 1499
 
1500
-            $user_access_permission = true;
1500
+			$user_access_permission = true;
1501 1501
 
1502
-        }else{
1502
+		}else{
1503 1503
 
1504
-            $user_access_permission = false;
1505
-            // do not show the WC permissions message
1506
-            remove_filter( 'sensei_the_no_permissions_message', array( 'Sensei_WC', 'alter_no_permissions_message' ), 20, 2 );
1507
-            Sensei()->permissions_message['title'] = __( 'No active subscription', 'woothemes-sensei' );
1508
-            Sensei()->permissions_message['message'] = __( 'Sorry, you do not have an access to this content without an active subscription.', 'woothemes-sensei' );
1509
-        }
1504
+			$user_access_permission = false;
1505
+			// do not show the WC permissions message
1506
+			remove_filter( 'sensei_the_no_permissions_message', array( 'Sensei_WC', 'alter_no_permissions_message' ), 20, 2 );
1507
+			Sensei()->permissions_message['title'] = __( 'No active subscription', 'woothemes-sensei' );
1508
+			Sensei()->permissions_message['message'] = __( 'Sorry, you do not have an access to this content without an active subscription.', 'woothemes-sensei' );
1509
+		}
1510 1510
 
1511
-        return $user_access_permission;
1511
+		return $user_access_permission;
1512 1512
 
1513
-    } // end get_subscription_permission
1513
+	} // end get_subscription_permission
1514 1514
 
1515
-    /**
1516
-     * Get all the valid subscription types.
1517
-     *
1518
-     * @since 1.9.0
1519
-     * @return array
1520
-     */
1521
-    public static function get_subscription_types(){
1515
+	/**
1516
+	 * Get all the valid subscription types.
1517
+	 *
1518
+	 * @since 1.9.0
1519
+	 * @return array
1520
+	 */
1521
+	public static function get_subscription_types(){
1522 1522
 
1523
-        return array( 'subscription','subscription_variation','variable-subscription' );
1523
+		return array( 'subscription','subscription_variation','variable-subscription' );
1524 1524
 
1525
-    }
1525
+	}
1526 1526
 
1527
-    /**
1528
-     * Compare the user's subscriptions end date with the date
1529
-     * the user was added to the course. If the user was added after
1530
-     * the subscription ended they were manually added and this will return
1531
-     * true.
1532
-     *
1533
-     * Important to note that all subscriptions for the user is compared.
1534
-     *
1535
-     * @since 1.9.0
1536
-     *
1537
-     * @param $user_id
1538
-     * @param $product_id
1539
-     * @param $course_id
1540
-     *
1541
-     * @return bool
1542
-     */
1543
-    public static function was_user_added_without_subscription($user_id, $product_id, $course_id ){
1527
+	/**
1528
+	 * Compare the user's subscriptions end date with the date
1529
+	 * the user was added to the course. If the user was added after
1530
+	 * the subscription ended they were manually added and this will return
1531
+	 * true.
1532
+	 *
1533
+	 * Important to note that all subscriptions for the user is compared.
1534
+	 *
1535
+	 * @since 1.9.0
1536
+	 *
1537
+	 * @param $user_id
1538
+	 * @param $product_id
1539
+	 * @param $course_id
1540
+	 *
1541
+	 * @return bool
1542
+	 */
1543
+	public static function was_user_added_without_subscription($user_id, $product_id, $course_id ){
1544 1544
 
1545
-        $course_start_date = '';
1546
-        $subscription_start_date = '';
1547
-        $is_a_subscription ='';
1548
-        $was_user_added_without_subscription = true;
1545
+		$course_start_date = '';
1546
+		$subscription_start_date = '';
1547
+		$is_a_subscription ='';
1548
+		$was_user_added_without_subscription = true;
1549 1549
 
1550
-        // if user is not on the course they were not added
1551
-        if( ! Sensei_Utils::user_started_course( $course_id, $user_id ) ){
1550
+		// if user is not on the course they were not added
1551
+		if( ! Sensei_Utils::user_started_course( $course_id, $user_id ) ){
1552 1552
 
1553
-            return false;
1553
+			return false;
1554 1554
 
1555
-        }
1555
+		}
1556 1556
 
1557
-        // if user doesn't have a subscription and is taking the course
1558
-        // they were added manually
1559
-        if ( ! wcs_user_has_subscription($user_id, $product_id)
1560
-            && Sensei_Utils::user_started_course( $course_id, get_current_user_id() )  ){
1557
+		// if user doesn't have a subscription and is taking the course
1558
+		// they were added manually
1559
+		if ( ! wcs_user_has_subscription($user_id, $product_id)
1560
+			&& Sensei_Utils::user_started_course( $course_id, get_current_user_id() )  ){
1561 1561
 
1562
-            return true;
1562
+			return true;
1563 1563
 
1564
-        }
1564
+		}
1565 1565
 
1566
-        $course_status =  Sensei_Utils::user_course_status( $course_id, $user_id );
1566
+		$course_status =  Sensei_Utils::user_course_status( $course_id, $user_id );
1567 1567
 
1568
-        // comparing dates setup data
1569
-        $course_start_date = date_create( $course_status->comment_date );
1570
-        $subscriptions = wcs_get_users_subscriptions( $user_id );
1568
+		// comparing dates setup data
1569
+		$course_start_date = date_create( $course_status->comment_date );
1570
+		$subscriptions = wcs_get_users_subscriptions( $user_id );
1571 1571
 
1572
-        // comparing every subscription
1573
-        foreach( $subscriptions as $subscription ){
1572
+		// comparing every subscription
1573
+		foreach( $subscriptions as $subscription ){
1574 1574
 
1575
-            // for the following statuses we know the user was not added
1576
-            // manually
1577
-            $status = $subscription->get_status();
1578
-            if ( in_array( $status, array( 'pending-canceled', 'active', 'on-hold', 'pending' ) ) ) {
1575
+			// for the following statuses we know the user was not added
1576
+			// manually
1577
+			$status = $subscription->get_status();
1578
+			if ( in_array( $status, array( 'pending-canceled', 'active', 'on-hold', 'pending' ) ) ) {
1579 1579
 
1580
-                continue;
1580
+				continue;
1581 1581
 
1582
-            }
1582
+			}
1583 1583
 
1584
-            $current_subscription_start_date = date_create( $subscription->modified_date );
1584
+			$current_subscription_start_date = date_create( $subscription->modified_date );
1585 1585
 
1586
-            // is the last updated subscription date newer than course start date
1587
-            if (  $current_subscription_start_date > $course_start_date   ) {
1586
+			// is the last updated subscription date newer than course start date
1587
+			if (  $current_subscription_start_date > $course_start_date   ) {
1588 1588
 
1589
-                return false;
1589
+				return false;
1590 1590
 
1591
-            }
1591
+			}
1592 1592
 
1593
-        }
1593
+		}
1594 1594
 
1595
-        return $was_user_added_without_subscription;
1596
-    }
1595
+		return $was_user_added_without_subscription;
1596
+	}
1597 1597
 
1598 1598
 }// end Sensei_WC
Please login to merge, or discard this patch.
Spacing   +285 added lines, -285 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // security check, don't load file outside WP
2
+if ( ! defined('ABSPATH')) exit; // security check, don't load file outside WP
3 3
 
4 4
 /**
5 5
  * Sensei WooCommerce class
@@ -11,16 +11,16 @@  discard block
 block discarded – undo
11 11
  * @since 1.9.0
12 12
  */
13 13
 
14
-Class Sensei_WC{
14
+Class Sensei_WC {
15 15
     /**
16 16
      * Load the files needed for the woocommerce integration.
17 17
      *
18 18
      * @since 1.9.0
19 19
      */
20
-    public static function load_woocommerce_integration_hooks(){
20
+    public static function load_woocommerce_integration_hooks() {
21 21
 
22
-	    $woocommerce_hooks_file_path = Sensei()->plugin_path() . 'includes/hooks/woocommerce.php';
23
-        require_once( $woocommerce_hooks_file_path );
22
+	    $woocommerce_hooks_file_path = Sensei()->plugin_path().'includes/hooks/woocommerce.php';
23
+        require_once($woocommerce_hooks_file_path);
24 24
 
25 25
     }
26 26
     /**
@@ -29,9 +29,9 @@  discard block
 block discarded – undo
29 29
      * @since 1.9.0
30 30
      * @return bool
31 31
      */
32
-    public static function is_woocommerce_active(){
32
+    public static function is_woocommerce_active() {
33 33
 
34
-        $is_woocommerce_enabled_in_settings = isset( Sensei()->settings->settings['woocommerce_enabled'] ) && Sensei()->settings->settings['woocommerce_enabled'];
34
+        $is_woocommerce_enabled_in_settings = isset(Sensei()->settings->settings['woocommerce_enabled']) && Sensei()->settings->settings['woocommerce_enabled'];
35 35
         return self::is_woocommerce_present() && $is_woocommerce_enabled_in_settings;
36 36
 
37 37
     } // end is_woocommerce_active
@@ -46,19 +46,19 @@  discard block
 block discarded – undo
46 46
      *
47 47
      * @return bool
48 48
      */
49
-    public static function is_woocommerce_present(){
49
+    public static function is_woocommerce_present() {
50 50
 
51
-        $active_plugins = (array) get_option( 'active_plugins', array() );
51
+        $active_plugins = (array) get_option('active_plugins', array());
52 52
 
53
-        if ( is_multisite() ){
53
+        if (is_multisite()) {
54 54
 
55
-            $active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) );
55
+            $active_plugins = array_merge($active_plugins, get_site_option('active_sitewide_plugins', array()));
56 56
 
57 57
         }
58 58
 
59
-        $is_woocommerce_plugin_present_and_activated = in_array( 'woocommerce/woocommerce.php', $active_plugins ) || array_key_exists( 'woocommerce/woocommerce.php', $active_plugins );
59
+        $is_woocommerce_plugin_present_and_activated = in_array('woocommerce/woocommerce.php', $active_plugins) || array_key_exists('woocommerce/woocommerce.php', $active_plugins);
60 60
 
61
-        return class_exists( 'Woocommerce' ) || $is_woocommerce_plugin_present_and_activated;
61
+        return class_exists('Woocommerce') || $is_woocommerce_plugin_present_and_activated;
62 62
 
63 63
     }// end is_woocommerce_present
64 64
 
@@ -71,48 +71,48 @@  discard block
 block discarded – undo
71 71
      * @param $course_id
72 72
      * @return array $user_course_orders
73 73
      */
74
-    public static function get_learner_course_active_order_id( $user_id, $course_id ){
74
+    public static function get_learner_course_active_order_id($user_id, $course_id) {
75 75
 
76
-        $course_product_id = get_post_meta( $course_id, '_course_woocommerce_product', true );
76
+        $course_product_id = get_post_meta($course_id, '_course_woocommerce_product', true);
77 77
 
78
-        $orders_query = new WP_Query( array(
78
+        $orders_query = new WP_Query(array(
79 79
             'post_type'   => 'shop_order',
80 80
             'posts_per_page' => -1,
81
-            'post_status' => array( 'wc-processing', 'wc-completed' ),
81
+            'post_status' => array('wc-processing', 'wc-completed'),
82 82
             'meta_key'=> '_customer_user',
83 83
             'meta_value'=> $user_id,
84
-        ) );
84
+        ));
85 85
 
86
-        if( $orders_query->post_count == 0 ){
86
+        if ($orders_query->post_count == 0) {
87 87
 
88 88
             return false;
89 89
 
90 90
         }
91 91
 
92
-        foreach( $orders_query->get_posts() as $order ){
92
+        foreach ($orders_query->get_posts() as $order) {
93 93
 
94
-            $order = new WC_Order( $order->ID );
94
+            $order = new WC_Order($order->ID);
95 95
             $items = $order->get_items();
96 96
 
97
-            $user_orders =  array();
97
+            $user_orders = array();
98 98
 
99
-            foreach( $items as $item ){
99
+            foreach ($items as $item) {
100 100
 
101 101
                 // if the product id on the order and the one given to this function
102 102
                 // this order has been placed by the given user on the given course.
103
-                $product = wc_get_product( $item['product_id'] );
103
+                $product = wc_get_product($item['product_id']);
104 104
 
105
-                if ( is_object( $product ) && $product->is_type( 'variable' )) {
105
+                if (is_object($product) && $product->is_type('variable')) {
106 106
 
107 107
                     $item_product_id = $item['variation_id'];
108 108
 
109 109
                 } else {
110 110
 
111
-                    $item_product_id =  $item['product_id'];
111
+                    $item_product_id = $item['product_id'];
112 112
 
113 113
                 }
114 114
 
115
-                if( $course_product_id == $item_product_id ){
115
+                if ($course_product_id == $item_product_id) {
116 116
 
117 117
                     return $order->id;
118 118
 
@@ -136,12 +136,12 @@  discard block
 block discarded – undo
136 136
      * @param $filter_links
137 137
      * @return mixed
138 138
      */
139
-    public static function add_course_archive_wc_filter_links( $filter_links ){
139
+    public static function add_course_archive_wc_filter_links($filter_links) {
140 140
 
141 141
         $free_courses = self::get_free_courses();
142 142
         $paid_courses = self::get_paid_courses();
143 143
 
144
-        if ( empty( $free_courses ) || empty( $paid_courses )  ){
144
+        if (empty($free_courses) || empty($paid_courses)) {
145 145
             // do not show any WooCommerce filters if all courses are
146 146
             // free or if all courses are paid
147 147
             return $filter_links;
@@ -149,15 +149,15 @@  discard block
 block discarded – undo
149 149
         }
150 150
 
151 151
         $filter_links[] = array(
152
-            'id'=>'paid' ,
153
-            'url'=> add_query_arg( array( 'course_filter'=>'paid'), Sensei_Course::get_courses_page_url() ),
154
-            'title'=>__( 'Paid', 'woothemes-sensei' )
152
+            'id'=>'paid',
153
+            'url'=> add_query_arg(array('course_filter'=>'paid'), Sensei_Course::get_courses_page_url()),
154
+            'title'=>__('Paid', 'woothemes-sensei')
155 155
         );
156 156
 
157 157
         $filter_links[] = array(
158 158
             'id'=>'free',
159
-            'url'=> add_query_arg( array( 'course_filter'=>'free'), Sensei_Course::get_courses_page_url() ),
160
-            'title'=>__( 'Free', 'woothemes-sensei' )
159
+            'url'=> add_query_arg(array('course_filter'=>'free'), Sensei_Course::get_courses_page_url()),
160
+            'title'=>__('Free', 'woothemes-sensei')
161 161
         );
162 162
 
163 163
         return $filter_links;
@@ -174,24 +174,24 @@  discard block
 block discarded – undo
174 174
      * @param WP_Query $query
175 175
      * @return WP_Query $query
176 176
      */
177
-    public static function course_archive_wc_filter_free( $query ){
177
+    public static function course_archive_wc_filter_free($query) {
178 178
 
179
-        if( isset( $_GET['course_filter'] ) && 'free' == $_GET['course_filter']
180
-            && 'course' == $query->get( 'post_type') && $query->is_main_query()  ){
179
+        if (isset($_GET['course_filter']) && 'free' == $_GET['course_filter']
180
+            && 'course' == $query->get('post_type') && $query->is_main_query()) {
181 181
 
182 182
             // setup the course meta query
183 183
             $meta_query = self::get_free_courses_meta_query_args();
184 184
 
185 185
             // manipulate the query to return free courses
186
-            $query->set('meta_query', $meta_query );
186
+            $query->set('meta_query', $meta_query);
187 187
 
188 188
             // don't show any paid courses
189 189
             $courses = self::get_paid_courses();
190 190
             $ids = array();
191
-            foreach( $courses as $course ){
191
+            foreach ($courses as $course) {
192 192
                 $ids[] = $course->ID;
193 193
             }
194
-            $query->set( 'post__not_in', $ids );
194
+            $query->set('post__not_in', $ids);
195 195
 
196 196
         }// end if course_filter
197 197
 
@@ -210,16 +210,16 @@  discard block
 block discarded – undo
210 210
      * @param WP_Query $query
211 211
      * @return WP_Query $query
212 212
      */
213
-    public static function course_archive_wc_filter_paid( $query ){
213
+    public static function course_archive_wc_filter_paid($query) {
214 214
 
215
-        if( isset( $_GET['course_filter'] ) && 'paid' == $_GET['course_filter']
216
-            && 'course' == $query->get( 'post_type') && $query->is_main_query() ){
215
+        if (isset($_GET['course_filter']) && 'paid' == $_GET['course_filter']
216
+            && 'course' == $query->get('post_type') && $query->is_main_query()) {
217 217
 
218 218
             // setup the course meta query
219 219
             $meta_query = self::get_paid_courses_meta_query_args();
220 220
 
221 221
             // manipulate the query to return free courses
222
-            $query->set('meta_query', $meta_query );
222
+            $query->set('meta_query', $meta_query);
223 223
 
224 224
         }
225 225
 
@@ -232,14 +232,14 @@  discard block
 block discarded – undo
232 232
      * single courses if woocommerce is active allowing purchase
233 233
      * information and actions to be hooked from WooCommerce.
234 234
      */
235
-    public static function do_single_course_wc_single_product_action(){
235
+    public static function do_single_course_wc_single_product_action() {
236 236
 
237 237
         /**
238 238
          * this hooks is documented within the WooCommerce plugin.
239 239
          */
240
-        if ( Sensei_WC::is_woocommerce_active() ) {
240
+        if (Sensei_WC::is_woocommerce_active()) {
241 241
 
242
-            do_action( 'woocommerce_before_single_product' );
242
+            do_action('woocommerce_before_single_product');
243 243
 
244 244
         } // End If Statement
245 245
 
@@ -260,28 +260,28 @@  discard block
 block discarded – undo
260 260
      * @param $user_id
261 261
      * @return bool
262 262
      */
263
-    public static function alter_can_user_view_lesson ( $can_user_view_lesson, $lesson_id, $user_id  ){
263
+    public static function alter_can_user_view_lesson($can_user_view_lesson, $lesson_id, $user_id) {
264 264
 
265 265
 	    // do not override access to admins
266
-	    if( sensei_all_access() || Sensei_Utils::is_preview_lesson( $lesson_id ) ){
266
+	    if (sensei_all_access() || Sensei_Utils::is_preview_lesson($lesson_id)) {
267 267
 		    return true;
268 268
 	    }
269 269
 
270 270
         // check if the course has a valid product attached to it
271 271
         // which the user should have purchased if they want to access
272 272
         // the current lesson
273
-        $course_id = get_post_meta( $lesson_id , '_lesson_course', true);
274
-        $wc_post_id = get_post_meta( $course_id, '_course_woocommerce_product', true );
273
+        $course_id = get_post_meta($lesson_id, '_lesson_course', true);
274
+        $wc_post_id = get_post_meta($course_id, '_course_woocommerce_product', true);
275 275
         $product = Sensei()->sensei_get_woocommerce_product_object($wc_post_id);
276
-        if( isset ($product) && is_object($product) ){
276
+        if (isset ($product) && is_object($product)) {
277 277
 
278 278
             // valid product found
279
-            $order_id = self::get_learner_course_active_order_id( $user_id, $course_id );
279
+            $order_id = self::get_learner_course_active_order_id($user_id, $course_id);
280 280
 
281 281
             // product has a successful order so this user may access the content
282 282
             // this function may only return false or the default
283 283
             // returning true may override other negatives which we don't want
284
-            if( ! $order_id ){
284
+            if ( ! $order_id) {
285 285
 
286 286
                 return false;
287 287
 
@@ -304,23 +304,23 @@  discard block
 block discarded – undo
304 304
      */
305 305
     public static function course_link_from_order( ) {
306 306
 
307
-        if( ! is_order_received_page() ){
307
+        if ( ! is_order_received_page()) {
308 308
             return;
309 309
         }
310 310
 
311
-        $order_id = get_query_var( 'order-received' );
312
-		$order = new WC_Order( $order_id );
311
+        $order_id = get_query_var('order-received');
312
+		$order = new WC_Order($order_id);
313 313
 
314 314
 		// exit early if not wc-completed or wc-processing
315
-		if( 'wc-completed' != $order->post_status
316
-            && 'wc-processing' != $order->post_status  ) {
315
+		if ('wc-completed' != $order->post_status
316
+            && 'wc-processing' != $order->post_status) {
317 317
             return;
318 318
         }
319 319
 
320 320
         $course_links = array(); // store the for links for courses purchased
321
-		foreach ( $order->get_items() as $item ) {
321
+		foreach ($order->get_items() as $item) {
322 322
 
323
-            if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
323
+            if (isset($item['variation_id']) && (0 < $item['variation_id'])) {
324 324
 
325 325
                 // If item has variation_id then its a variation of the product
326 326
                 $item_id = $item['variation_id'];
@@ -332,28 +332,28 @@  discard block
 block discarded – undo
332 332
 
333 333
             } // End If Statement
334 334
 
335
-            $user_id = get_post_meta( $order->id, '_customer_user', true );
335
+            $user_id = get_post_meta($order->id, '_customer_user', true);
336 336
 
337
-            if( $user_id ) {
337
+            if ($user_id) {
338 338
 
339 339
                 // Get all courses for product
340 340
                 $args = Sensei_Course::get_default_query_args();
341
-                $args['meta_query'] = array( array(
341
+                $args['meta_query'] = array(array(
342 342
                             'key' => '_course_woocommerce_product',
343 343
                             'value' => $item_id
344
-                        ) );
344
+                        ));
345 345
                 $args['orderby'] = 'menu_order date';
346 346
                 $args['order'] = 'ASC';
347 347
 
348 348
                 // loop through courses
349
-                $courses = get_posts( $args );
350
-                if( $courses && count( $courses ) > 0 ) {
349
+                $courses = get_posts($args);
350
+                if ($courses && count($courses) > 0) {
351 351
 
352
-                    foreach( $courses as $course ) {
352
+                    foreach ($courses as $course) {
353 353
 
354 354
                         $title = $course->post_title;
355
-                        $permalink = get_permalink( $course->ID );
356
-                        $course_links[] .= '<a href="' . esc_url( $permalink ) . '" >' . $title . '</a> ';
355
+                        $permalink = get_permalink($course->ID);
356
+                        $course_links[] .= '<a href="'.esc_url($permalink).'" >'.$title.'</a> ';
357 357
 
358 358
                     } // end for each
359 359
 
@@ -364,24 +364,24 @@  discard block
 block discarded – undo
364 364
         }// end loop through orders
365 365
 
366 366
         // add the courses to the WooCommerce notice
367
-        if( ! empty( $course_links) ){
367
+        if ( ! empty($course_links)) {
368 368
 
369 369
             $courses_html = _nx(
370 370
                 'You have purchased the following course:',
371 371
                 'You have purchased the following courses:',
372
-                count( $course_links ),
372
+                count($course_links),
373 373
                 'Purchase thank you note on Checkout page. The course link(s) will be show', 'woothemes-sensei'
374 374
             );
375 375
 
376
-            foreach( $course_links as $link ){
376
+            foreach ($course_links as $link) {
377 377
 
378
-                $courses_html .= '<li>' . $link . '</li>';
378
+                $courses_html .= '<li>'.$link.'</li>';
379 379
 
380 380
             }
381 381
 
382 382
             $courses_html .= ' </ul>';
383 383
 
384
-            wc_add_notice( $courses_html, 'success' );
384
+            wc_add_notice($courses_html, 'success');
385 385
         }
386 386
 
387 387
 	} // end course_link_order_form
@@ -394,20 +394,20 @@  discard block
 block discarded – undo
394 394
      *
395 395
      * @since 1.9.0
396 396
      */
397
-    public static function course_in_cart_message(){
397
+    public static function course_in_cart_message() {
398 398
 
399 399
         global $post;
400 400
 
401
-        if( self::is_course_in_cart( $post->ID ) ){ ?>
401
+        if (self::is_course_in_cart($post->ID)) { ?>
402 402
 
403 403
             <div class="sensei-message info">
404 404
                 <?php
405 405
 
406
-                $cart_link =  '<a class="cart-complete" href="' . WC()->cart->get_checkout_url()
407
-                              . '" title="' . __('complete purchase', 'woothemes-sensei') . '">'
408
-                              . __('complete the purchase', 'woothemes-sensei') . '</a>';
406
+                $cart_link = '<a class="cart-complete" href="'.WC()->cart->get_checkout_url()
407
+                              . '" title="'.__('complete purchase', 'woothemes-sensei').'">'
408
+                              . __('complete the purchase', 'woothemes-sensei').'</a>';
409 409
 
410
-                echo sprintf(  __('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei'), $cart_link );
410
+                echo sprintf(__('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei'), $cart_link);
411 411
 
412 412
                 ?>
413 413
             </div>
@@ -421,14 +421,14 @@  discard block
 block discarded – undo
421 421
      * @param $course_id
422 422
      * @return bool
423 423
      */
424
-    public static function is_course_in_cart( $course_id ){
424
+    public static function is_course_in_cart($course_id) {
425 425
 
426
-        $wc_post_id = absint( get_post_meta( $course_id, '_course_woocommerce_product', true ) );
427
-        $user_course_status_id = Sensei_Utils::user_started_course( $course_id , get_current_user_id() );
426
+        $wc_post_id = absint(get_post_meta($course_id, '_course_woocommerce_product', true));
427
+        $user_course_status_id = Sensei_Utils::user_started_course($course_id, get_current_user_id());
428 428
 
429
-        if ( 0 < intval( $wc_post_id ) && ! $user_course_status_id ) {
429
+        if (0 < intval($wc_post_id) && ! $user_course_status_id) {
430 430
 
431
-            if ( self::is_product_in_cart( $wc_post_id ) ) {
431
+            if (self::is_product_in_cart($wc_post_id)) {
432 432
 
433 433
                 return true;
434 434
 
@@ -446,20 +446,20 @@  discard block
 block discarded – undo
446 446
      * @param $product_id
447 447
      * @return bool
448 448
      */
449
-    public static function is_product_in_cart( $product_id ){
449
+    public static function is_product_in_cart($product_id) {
450 450
 
451
-        if ( 0 < $product_id ) {
451
+        if (0 < $product_id) {
452 452
 
453
-            $product = wc_get_product( $product_id );
453
+            $product = wc_get_product($product_id);
454 454
 
455 455
             $parent_id = '';
456
-            if( isset( $product->variation_id ) && 0 < intval( $product->variation_id ) ) {
456
+            if (isset($product->variation_id) && 0 < intval($product->variation_id)) {
457 457
                 $wc_product_id = $product->parent->id;
458 458
             }
459
-            foreach( WC()->cart->get_cart() as $cart_item_key => $values ) {
459
+            foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
460 460
 
461 461
                 $cart_product = $values['data'];
462
-                if( $product_id == $cart_product->id ) {
462
+                if ($product_id == $cart_product->id) {
463 463
 
464 464
                     return true;
465 465
 
@@ -481,9 +481,9 @@  discard block
 block discarded – undo
481 481
      *  @type int $wp_post_id
482 482
      * }
483 483
      */
484
-    public static function get_free_product_ids(){
484
+    public static function get_free_product_ids() {
485 485
 
486
-        return  get_posts( array(
486
+        return  get_posts(array(
487 487
             'post_type' => 'product',
488 488
             'posts_per_page' => '1000',
489 489
             'fields' => 'ids',
@@ -508,7 +508,7 @@  discard block
 block discarded – undo
508 508
      * @since 1.9.0
509 509
      * @return array $wp_meta_query_param
510 510
      */
511
-    public static function get_free_courses_meta_query_args(){
511
+    public static function get_free_courses_meta_query_args() {
512 512
 
513 513
         return array(
514 514
             'relation' => 'OR',
@@ -532,7 +532,7 @@  discard block
 block discarded – undo
532 532
      * @since 1.9.0
533 533
      * @return array $wp_query_meta_query_args_param
534 534
      */
535
-    public static function get_paid_courses_meta_query_args(){
535
+    public static function get_paid_courses_meta_query_args() {
536 536
 
537 537
         $paid_product_ids = self::get_paid_product_ids();
538 538
 
@@ -541,7 +541,7 @@  discard block
 block discarded – undo
541 541
                 'key'     => '_course_woocommerce_product',
542 542
                 // when empty we give a false post_id to ensure the caller doesn't get any courses for their
543 543
                 // query
544
-                'value' => empty( $paid_product_ids  )? '-1000' : $paid_product_ids,
544
+                'value' => empty($paid_product_ids) ? '-1000' : $paid_product_ids,
545 545
                 'compare' => 'IN',
546 546
             ),
547 547
         );
@@ -555,7 +555,7 @@  discard block
 block discarded – undo
555 555
      * @since 1.9.0
556 556
      * @return array $product_query_args
557 557
      */
558
-    public static function get_paid_products_on_sale_query_args(){
558
+    public static function get_paid_products_on_sale_query_args() {
559 559
 
560 560
         $args = array(
561 561
                    'post_type' 		=> 'product',
@@ -565,9 +565,9 @@  discard block
 block discarded – undo
565 565
                    'suppress_filters' 	=> 0
566 566
         );
567 567
 
568
-        $args[ 'fields' ]     = 'ids';
568
+        $args['fields']     = 'ids';
569 569
 
570
-        $args[ 'meta_query' ] = array(
570
+        $args['meta_query'] = array(
571 571
             'relation' => 'AND',
572 572
             array(
573 573
                 'key'=> '_regular_price',
@@ -594,7 +594,7 @@  discard block
 block discarded – undo
594 594
      *
595 595
      * @return array
596 596
      */
597
-    public static function get_paid_products_not_on_sale_query_args(){
597
+    public static function get_paid_products_not_on_sale_query_args() {
598 598
 
599 599
         $args = array(
600 600
             'post_type' 		=> 'product',
@@ -604,8 +604,8 @@  discard block
 block discarded – undo
604 604
             'suppress_filters' 	=> 0
605 605
         );
606 606
 
607
-        $args[ 'fields' ]     = 'ids';
608
-        $args[ 'meta_query' ] = array(
607
+        $args['fields']     = 'ids';
608
+        $args['meta_query'] = array(
609 609
             'relation' => 'AND',
610 610
             array(
611 611
                 'key'=> '_regular_price',
@@ -631,24 +631,24 @@  discard block
 block discarded – undo
631 631
      *
632 632
      * @return array $woocommerce_paid_product_ids
633 633
      */
634
-    public static function get_paid_product_ids(){
634
+    public static function get_paid_product_ids() {
635 635
 
636 636
         // get all the paid WooCommerce products that has regular
637 637
         // and sale price greater than 0
638 638
         // will be used later to check for course with the id as meta
639
-        $paid_product_ids_with_sale =  get_posts( self::get_paid_products_on_sale_query_args() );
639
+        $paid_product_ids_with_sale = get_posts(self::get_paid_products_on_sale_query_args());
640 640
 
641 641
         // get all the paid WooCommerce products that has regular price
642 642
         // greater than 0 without a sale price
643 643
         // will be used later to check for course with the id as meta
644
-        $paid_product_ids_without_sale = get_posts( self::get_paid_products_not_on_sale_query_args() );
644
+        $paid_product_ids_without_sale = get_posts(self::get_paid_products_not_on_sale_query_args());
645 645
 
646 646
         // combine products ID's with regular and sale price grater than zero and those without
647 647
         // sale but regular price greater than zero
648
-        $woocommerce_paid_product_ids = array_merge( $paid_product_ids_with_sale, $paid_product_ids_without_sale );
648
+        $woocommerce_paid_product_ids = array_merge($paid_product_ids_with_sale, $paid_product_ids_without_sale);
649 649
 
650 650
         // if
651
-        if( empty($woocommerce_paid_product_ids) ){
651
+        if (empty($woocommerce_paid_product_ids)) {
652 652
             return array( );
653 653
         }
654 654
         return $woocommerce_paid_product_ids;
@@ -667,20 +667,20 @@  discard block
 block discarded – undo
667 667
      *
668 668
      * @return array
669 669
      */
670
-    public static function get_free_courses(){
670
+    public static function get_free_courses() {
671 671
 
672 672
         $free_course_query_args = Sensei_Course::get_default_query_args();
673
-        $free_course_query_args[ 'meta_query' ] = self::get_free_courses_meta_query_args();
673
+        $free_course_query_args['meta_query'] = self::get_free_courses_meta_query_args();
674 674
 
675 675
         // don't show any paid courses
676 676
         $courses = self::get_paid_courses();
677 677
         $ids = array();
678
-        foreach( $courses as $course ){
678
+        foreach ($courses as $course) {
679 679
             $ids[] = $course->ID;
680 680
         }
681
-        $free_course_query_args[ 'post__not_in' ] =  $ids;
681
+        $free_course_query_args['post__not_in'] = $ids;
682 682
 
683
-        return get_posts( $free_course_query_args );
683
+        return get_posts($free_course_query_args);
684 684
 
685 685
     }
686 686
 
@@ -690,13 +690,13 @@  discard block
 block discarded – undo
690 690
      * @since 1.9.0
691 691
      * @return array
692 692
      */
693
-    public static function get_paid_courses(){
693
+    public static function get_paid_courses() {
694 694
 
695 695
         $paid_course_query_args = Sensei_Course::get_default_query_args();
696 696
 
697
-        $paid_course_query_args[ 'meta_query' ] = self::get_paid_courses_meta_query_args();
697
+        $paid_course_query_args['meta_query'] = self::get_paid_courses_meta_query_args();
698 698
 
699
-        return get_posts(  $paid_course_query_args );
699
+        return get_posts($paid_course_query_args);
700 700
     }
701 701
 
702 702
     /**
@@ -711,17 +711,17 @@  discard block
 block discarded – undo
711 711
      * @param int $course_id
712 712
      * @return string $html markup for the button or nothing if user not allowed to buy
713 713
      */
714
-    public static function the_add_to_cart_button_html( $course_id ){
714
+    public static function the_add_to_cart_button_html($course_id) {
715 715
 
716
-        if ( ! Sensei_Course::is_prerequisite_complete( $course_id )) {
716
+        if ( ! Sensei_Course::is_prerequisite_complete($course_id)) {
717 717
             return '';
718 718
         }
719 719
 
720
-        $wc_post_id = self::get_course_product_id( $course_id );
720
+        $wc_post_id = self::get_course_product_id($course_id);
721 721
 
722 722
         // Check if customer purchased the product
723
-        if ( self::has_customer_bought_product(  get_current_user_id(), $wc_post_id )
724
-            || empty( $wc_post_id ) ) {
723
+        if (self::has_customer_bought_product(get_current_user_id(), $wc_post_id)
724
+            || empty($wc_post_id)) {
725 725
 
726 726
             return '';
727 727
 
@@ -729,15 +729,15 @@  discard block
 block discarded – undo
729 729
 
730 730
         // based on simple.php in WC templates/single-product/add-to-cart/
731 731
         // Get the product
732
-        $product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id );
732
+        $product = Sensei()->sensei_get_woocommerce_product_object($wc_post_id);
733 733
 
734 734
         // do not show the button for invalid products, non purchasable products, out
735 735
         // of stock product or if course is already in cart
736
-        if ( ! isset ( $product )
737
-            || ! is_object( $product )
736
+        if ( ! isset ($product)
737
+            || ! is_object($product)
738 738
             || ! $product->is_purchasable()
739 739
             || ! $product->is_in_stock()
740
-            || self::is_course_in_cart( $wc_post_id ) ) {
740
+            || self::is_course_in_cart($wc_post_id)) {
741 741
 
742 742
             return '';
743 743
 
@@ -748,23 +748,23 @@  discard block
 block discarded – undo
748 748
         //
749 749
         ?>
750 750
 
751
-        <form action="<?php echo esc_url( $product->add_to_cart_url() ); ?>"
751
+        <form action="<?php echo esc_url($product->add_to_cart_url()); ?>"
752 752
               class="cart"
753 753
               method="post"
754 754
               enctype="multipart/form-data">
755 755
 
756
-            <input type="hidden" name="product_id" value="<?php echo esc_attr( $product->id ); ?>" />
756
+            <input type="hidden" name="product_id" value="<?php echo esc_attr($product->id); ?>" />
757 757
 
758 758
             <input type="hidden" name="quantity" value="1" />
759 759
 
760
-            <?php if ( isset( $product->variation_id ) && 0 < intval( $product->variation_id ) ) { ?>
760
+            <?php if (isset($product->variation_id) && 0 < intval($product->variation_id)) { ?>
761 761
 
762 762
                 <input type="hidden" name="variation_id" value="<?php echo $product->variation_id; ?>" />
763
-                <?php if( isset( $product->variation_data ) && is_array( $product->variation_data ) && count( $product->variation_data ) > 0 ) { ?>
763
+                <?php if (isset($product->variation_data) && is_array($product->variation_data) && count($product->variation_data) > 0) { ?>
764 764
 
765
-                    <?php foreach( $product->variation_data as $att => $val ) { ?>
765
+                    <?php foreach ($product->variation_data as $att => $val) { ?>
766 766
 
767
-                        <input type="hidden" name="<?php echo esc_attr( $att ); ?>" id="<?php echo esc_attr( str_replace( 'attribute_', '', $att ) ); ?>" value="<?php echo esc_attr( $val ); ?>" />
767
+                        <input type="hidden" name="<?php echo esc_attr($att); ?>" id="<?php echo esc_attr(str_replace('attribute_', '', $att)); ?>" value="<?php echo esc_attr($val); ?>" />
768 768
 
769 769
                     <?php } ?>
770 770
 
@@ -792,26 +792,26 @@  discard block
 block discarded – undo
792 792
      *
793 793
      * @return string $message
794 794
      */
795
-    public static function alter_no_permissions_message( $message, $post_id ){
795
+    public static function alter_no_permissions_message($message, $post_id) {
796 796
 
797
-        if( empty( $post_id ) || 'course'!=get_post_type( $post_id ) ){
797
+        if (empty($post_id) || 'course' != get_post_type($post_id)) {
798 798
             return  $message;
799 799
         }
800 800
 
801
-        $product_id = self::get_course_product_id( $post_id );
801
+        $product_id = self::get_course_product_id($post_id);
802 802
 
803
-        if( ! $product_id
804
-            || self::has_customer_bought_product( get_current_user_id(),$product_id ) ){
803
+        if ( ! $product_id
804
+            || self::has_customer_bought_product(get_current_user_id(), $product_id)) {
805 805
 
806 806
             return $message;
807 807
 
808 808
         }
809 809
 
810 810
         ob_start();
811
-        self::the_course_no_permissions_message( $post_id );
811
+        self::the_course_no_permissions_message($post_id);
812 812
         $woocommerce_course_no_permissions_message = ob_get_clean();
813 813
 
814
-        return $woocommerce_course_no_permissions_message ;
814
+        return $woocommerce_course_no_permissions_message;
815 815
 
816 816
     }
817 817
     /**
@@ -820,16 +820,16 @@  discard block
 block discarded – undo
820 820
      *
821 821
      * @since 1.9.0
822 822
      */
823
-    public static function the_course_no_permissions_message( $course_id ){
823
+    public static function the_course_no_permissions_message($course_id) {
824 824
 
825 825
         // login link
826
-        $my_courses_page_id = intval( Sensei()->settings->settings[ 'my_course_page' ] );
827
-        $login_link =  '<a href="' . esc_url( get_permalink( $my_courses_page_id ) ) . '">' . __( 'log in', 'woothemes-sensei' ) . '</a>';
826
+        $my_courses_page_id = intval(Sensei()->settings->settings['my_course_page']);
827
+        $login_link = '<a href="'.esc_url(get_permalink($my_courses_page_id)).'">'.__('log in', 'woothemes-sensei').'</a>';
828 828
 
829 829
         ?>
830 830
 
831 831
         <span class="add-to-cart-login">
832
-            <?php echo sprintf( __( 'Or %1$s to access your purchased courses', 'woothemes-sensei' ), $login_link ); ?>
832
+            <?php echo sprintf(__('Or %1$s to access your purchased courses', 'woothemes-sensei'), $login_link); ?>
833 833
         </span>
834 834
 
835 835
     <?php }
@@ -844,45 +844,45 @@  discard block
 block discarded – undo
844 844
      *
845 845
      * @return bool
846 846
      */
847
-    public static function has_customer_bought_product ( $user_id, $product_id ){
847
+    public static function has_customer_bought_product($user_id, $product_id) {
848 848
 
849
-        $orders = get_posts( array(
849
+        $orders = get_posts(array(
850 850
             'numberposts' => -1,
851 851
             'post_type' => 'shope_order',
852 852
             'meta_key'    => '_customer_user',
853
-            'meta_value'  => intval( $user_id ),
854
-            'post_status' => array( 'wc-complete','wc-processing' ),
855
-        ) );
853
+            'meta_value'  => intval($user_id),
854
+            'post_status' => array('wc-complete', 'wc-processing'),
855
+        ));
856 856
 
857
-        foreach ( $orders as $order_id ) {
857
+        foreach ($orders as $order_id) {
858 858
 
859
-            $order = new WC_Order( $order_id->ID );
859
+            $order = new WC_Order($order_id->ID);
860 860
 
861 861
             // wc-active is the subscriptions complete status
862
-            if ( ! in_array( $order->post_status, array( 'wc-complete','wc-processing' ) ) ){
862
+            if ( ! in_array($order->post_status, array('wc-complete', 'wc-processing'))) {
863 863
 
864 864
                 continue;
865 865
 
866 866
             }
867 867
 
868
-            if ( ! ( 0 < sizeof( $order->get_items() ) ) ) {
868
+            if ( ! (0 < sizeof($order->get_items()))) {
869 869
 
870 870
                 continue;
871 871
 
872 872
             }
873 873
 
874
-            foreach( $order->get_items() as $item ) {
874
+            foreach ($order->get_items() as $item) {
875 875
 
876 876
                 // Check if user has bought product
877
-                if ( $item['product_id'] == $product_id || $item['variation_id'] == $product_id ) {
877
+                if ($item['product_id'] == $product_id || $item['variation_id'] == $product_id) {
878 878
 
879 879
                     // Check if user has an active subscription for product
880
-                    if( class_exists( 'WC_Subscriptions_Manager' ) ) {
881
-                        $sub_key = wcs_get_subscription( $order );
882
-                        if( $sub_key ) {
883
-                            $sub = wcs_get_subscription( $sub_key );
884
-                            if( $sub && isset( $sub['status'] ) ) {
885
-                                if( 'active' == $sub['status'] ) {
880
+                    if (class_exists('WC_Subscriptions_Manager')) {
881
+                        $sub_key = wcs_get_subscription($order);
882
+                        if ($sub_key) {
883
+                            $sub = wcs_get_subscription($sub_key);
884
+                            if ($sub && isset($sub['status'])) {
885
+                                if ('active' == $sub['status']) {
886 886
                                     return true;
887 887
                                 } else {
888 888
                                     return false;
@@ -911,11 +911,11 @@  discard block
 block discarded – undo
911 911
      * @return string $woocommerce_product_id or false if none exist
912 912
      *
913 913
      */
914
-    public static function get_course_product_id( $course_id ){
914
+    public static function get_course_product_id($course_id) {
915 915
 
916
-        $product_id =  get_post_meta( $course_id, '_course_woocommerce_product', true );
916
+        $product_id = get_post_meta($course_id, '_course_woocommerce_product', true);
917 917
 
918
-        if( empty( $product_id ) || 'product' != get_post_type( $product_id ) ){
918
+        if (empty($product_id) || 'product' != get_post_type($product_id)) {
919 919
             return false;
920 920
         }
921 921
 
@@ -931,11 +931,11 @@  discard block
 block discarded – undo
931 931
      * @param array $classes
932 932
      * @return array
933 933
      */
934
-    public static function add_woocommerce_body_class( $classes ){
934
+    public static function add_woocommerce_body_class($classes) {
935 935
 
936
-        if( ! in_array( 'woocommerce', $classes ) && defined( 'SENSEI_NO_PERMISSION' ) && SENSEI_NO_PERMISSION ){
936
+        if ( ! in_array('woocommerce', $classes) && defined('SENSEI_NO_PERMISSION') && SENSEI_NO_PERMISSION) {
937 937
 
938
-            $classes[] ='woocommerce';
938
+            $classes[] = 'woocommerce';
939 939
 
940 940
         }
941 941
 
@@ -953,7 +953,7 @@  discard block
 block discarded – undo
953 953
      *
954 954
      * @return  void
955 955
      */
956
-    public static function activate_subscription(  $order ) {
956
+    public static function activate_subscription($order) {
957 957
 
958 958
         $order_user = get_user_by('id', $order->user_id);
959 959
         $user['ID'] = $order_user->ID;
@@ -962,13 +962,13 @@  discard block
 block discarded – undo
962 962
         $user['user_url'] = $order_user->user_url;
963 963
 
964 964
         // Run through each product ordered
965
-        if ( ! sizeof($order->get_items() )>0 ) {
965
+        if ( ! sizeof($order->get_items()) > 0) {
966 966
 
967 967
             return;
968 968
 
969 969
         }
970 970
 
971
-        foreach($order->get_items() as $item) {
971
+        foreach ($order->get_items() as $item) {
972 972
 
973 973
             $product_type = '';
974 974
 
@@ -983,21 +983,21 @@  discard block
 block discarded – undo
983 983
 
984 984
             } // End If Statement
985 985
 
986
-            $_product = self::get_product_object( $item_id, $product_type );
986
+            $_product = self::get_product_object($item_id, $product_type);
987 987
 
988 988
             // Get courses that use the WC product
989 989
             $courses = array();
990 990
 
991
-            if ( ! in_array( $product_type, self::get_subscription_types() ) ) {
991
+            if ( ! in_array($product_type, self::get_subscription_types())) {
992 992
 
993
-                $courses = Sensei()->course->get_product_courses( $item_id );
993
+                $courses = Sensei()->course->get_product_courses($item_id);
994 994
 
995 995
             } // End If Statement
996 996
 
997 997
             // Loop and add the user to the course.
998
-            foreach ( $courses as $course_item ){
998
+            foreach ($courses as $course_item) {
999 999
 
1000
-                Sensei_Utils::user_start_course( intval( $user['ID'] ), $course_item->ID  );
1000
+                Sensei_Utils::user_start_course(intval($user['ID']), $course_item->ID);
1001 1001
 
1002 1002
             } // End For Loop
1003 1003
 
@@ -1015,13 +1015,13 @@  discard block
 block discarded – undo
1015 1015
      *
1016 1016
      * @return  void
1017 1017
      */
1018
-    public static function email_course_details(  $order ){
1018
+    public static function email_course_details($order) {
1019 1019
 
1020 1020
         global $woocommerce;
1021 1021
 
1022 1022
         // exit early if not wc-completed or wc-processing
1023
-        if( 'wc-completed' != $order->post_status
1024
-            && 'wc-processing' != $order->post_status  ) {
1023
+        if ('wc-completed' != $order->post_status
1024
+            && 'wc-processing' != $order->post_status) {
1025 1025
             return;
1026 1026
         }
1027 1027
 
@@ -1029,16 +1029,16 @@  discard block
 block discarded – undo
1029 1029
         $order_id = $order->id;
1030 1030
 
1031 1031
         //If object have items go through them all to find course
1032
-        if ( 0 < sizeof( $order_items ) ) {
1032
+        if (0 < sizeof($order_items)) {
1033 1033
 
1034
-            $course_details_html =  '<h2>' . __( 'Course details', 'woothemes-sensei' ) . '</h2>';
1034
+            $course_details_html = '<h2>'.__('Course details', 'woothemes-sensei').'</h2>';
1035 1035
             $order_contains_courses = false;
1036 1036
 
1037 1037
 
1038
-            foreach ( $order_items as $item ) {
1038
+            foreach ($order_items as $item) {
1039 1039
 
1040 1040
                 $product_type = '';
1041
-                if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
1041
+                if (isset($item['variation_id']) && (0 < $item['variation_id'])) {
1042 1042
                     // If item has variation_id then its from variation
1043 1043
                     $item_id = $item['variation_id'];
1044 1044
                     $product_type = 'variation';
@@ -1047,9 +1047,9 @@  discard block
 block discarded – undo
1047 1047
                     $item_id = $item['product_id'];
1048 1048
                 } // End If Statement
1049 1049
 
1050
-                $user_id = get_post_meta( $order_id, '_customer_user', true );
1050
+                $user_id = get_post_meta($order_id, '_customer_user', true);
1051 1051
 
1052
-                if( $user_id ) {
1052
+                if ($user_id) {
1053 1053
 
1054 1054
                     // Get all courses for product
1055 1055
                     $args = array(
@@ -1064,16 +1064,16 @@  discard block
 block discarded – undo
1064 1064
                         'orderby' => 'menu_order date',
1065 1065
                         'order' => 'ASC',
1066 1066
                     );
1067
-                    $courses = get_posts( $args );
1067
+                    $courses = get_posts($args);
1068 1068
 
1069
-                    if( $courses && count( $courses ) > 0 ) {
1069
+                    if ($courses && count($courses) > 0) {
1070 1070
 
1071
-                        foreach( $courses as $course ) {
1071
+                        foreach ($courses as $course) {
1072 1072
 
1073 1073
                             $title = $course->post_title;
1074
-                            $permalink = get_permalink( $course->ID );
1074
+                            $permalink = get_permalink($course->ID);
1075 1075
                             $order_contains_courses = true;
1076
-                            $course_details_html .=  '<p><strong>' . sprintf( __( 'View course: %1$s', 'woothemes-sensei' ), '</strong><a href="' . esc_url( $permalink ) . '">' . $title . '</a>' ) . '</p>';
1076
+                            $course_details_html .= '<p><strong>'.sprintf(__('View course: %1$s', 'woothemes-sensei'), '</strong><a href="'.esc_url($permalink).'">'.$title.'</a>').'</p>';
1077 1077
                         }
1078 1078
 
1079 1079
 
@@ -1084,7 +1084,7 @@  discard block
 block discarded – undo
1084 1084
             } // end for each order item
1085 1085
 
1086 1086
             // Output Course details
1087
-            if( $order_contains_courses ){
1087
+            if ($order_contains_courses) {
1088 1088
 
1089 1089
                 echo $course_details_html;
1090 1090
 
@@ -1102,26 +1102,26 @@  discard block
 block discarded – undo
1102 1102
      * @param   int $order_id WC order ID
1103 1103
      * @return  void
1104 1104
      */
1105
-    public static function complete_order ( $order_id = 0 ) {
1105
+    public static function complete_order($order_id = 0) {
1106 1106
 
1107 1107
         $order_user = array();
1108 1108
 
1109 1109
         // Check for WooCommerce
1110
-        if ( Sensei_WC::is_woocommerce_active() && ( 0 < $order_id ) ) {
1110
+        if (Sensei_WC::is_woocommerce_active() && (0 < $order_id)) {
1111 1111
             // Get order object
1112
-            $order = new WC_Order( $order_id );
1113
-            $user = get_user_by( 'id', $order->get_user_id() );
1112
+            $order = new WC_Order($order_id);
1113
+            $user = get_user_by('id', $order->get_user_id());
1114 1114
             $order_user['ID'] = $user->ID;
1115 1115
             $order_user['user_login'] = $user->user_login;
1116 1116
             $order_user['user_email'] = $user->user_email;
1117 1117
             $order_user['user_url'] = $user->user_url;
1118 1118
             // Run through each product ordered
1119
-            if ( 0 < sizeof( $order->get_items() ) ) {
1119
+            if (0 < sizeof($order->get_items())) {
1120 1120
 
1121
-                foreach( $order->get_items() as $item ) {
1121
+                foreach ($order->get_items() as $item) {
1122 1122
 
1123 1123
                     $product_type = '';
1124
-                    if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
1124
+                    if (isset($item['variation_id']) && (0 < $item['variation_id'])) {
1125 1125
 
1126 1126
                         $item_id = $item['variation_id'];
1127 1127
                         $product_type = 'variation';
@@ -1132,15 +1132,15 @@  discard block
 block discarded – undo
1132 1132
 
1133 1133
                     } // End If Statement
1134 1134
 
1135
-                    $_product = Sensei_WC::get_product_object( $item_id, $product_type );
1135
+                    $_product = Sensei_WC::get_product_object($item_id, $product_type);
1136 1136
 
1137 1137
                     // Get courses that use the WC product
1138
-                    $courses = Sensei()->course->get_product_courses( $_product->id );
1138
+                    $courses = Sensei()->course->get_product_courses($_product->id);
1139 1139
 
1140 1140
                     // Loop and update those courses
1141
-                    foreach ( $courses as $course_item ) {
1141
+                    foreach ($courses as $course_item) {
1142 1142
 
1143
-                        $update_course = Sensei()->woocommerce_course_update( $course_item->ID, $order_user );
1143
+                        $update_course = Sensei()->woocommerce_course_update($course_item->ID, $order_user);
1144 1144
 
1145 1145
                     } // End For Loop
1146 1146
 
@@ -1148,7 +1148,7 @@  discard block
 block discarded – undo
1148 1148
 
1149 1149
             } // End If Statement
1150 1150
             // Add meta to indicate that payment has been completed successfully
1151
-            update_post_meta( $order_id, 'sensei_payment_complete', '1' );
1151
+            update_post_meta($order_id, 'sensei_payment_complete', '1');
1152 1152
 
1153 1153
         } // End If Statement
1154 1154
 
@@ -1162,28 +1162,28 @@  discard block
 block discarded – undo
1162 1162
      * @param   integer| WC_Order $order_id order ID
1163 1163
      * @return  void
1164 1164
      */
1165
-    public static function cancel_order ( $order_id ) {
1165
+    public static function cancel_order($order_id) {
1166 1166
 
1167 1167
         // Get order object
1168
-        if( is_object( $order_id ) ){
1168
+        if (is_object($order_id)) {
1169 1169
 
1170 1170
             $order = $order_id;
1171 1171
 
1172
-        }else{
1172
+        } else {
1173 1173
 
1174
-            $order = new WC_Order( $order_id );
1174
+            $order = new WC_Order($order_id);
1175 1175
         }
1176 1176
 
1177 1177
         // Run through each product ordered
1178
-        if ( 0 < sizeof( $order->get_items() ) ) {
1178
+        if (0 < sizeof($order->get_items())) {
1179 1179
 
1180 1180
             // Get order user
1181
-            $user_id = $order->__get( 'user_id' );
1181
+            $user_id = $order->__get('user_id');
1182 1182
 
1183
-            foreach( $order->get_items() as $item ) {
1183
+            foreach ($order->get_items() as $item) {
1184 1184
 
1185 1185
                 $product_type = '';
1186
-                if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
1186
+                if (isset($item['variation_id']) && (0 < $item['variation_id'])) {
1187 1187
 
1188 1188
                     $item_id = $item['variation_id'];
1189 1189
                     $product_type = 'variation';
@@ -1194,17 +1194,17 @@  discard block
 block discarded – undo
1194 1194
 
1195 1195
                 } // End If Statement
1196 1196
 
1197
-                $_product = Sensei_WC::get_product_object( $item_id, $product_type );
1197
+                $_product = Sensei_WC::get_product_object($item_id, $product_type);
1198 1198
 
1199 1199
                 // Get courses that use the WC product
1200 1200
                 $courses = array();
1201
-                $courses = Sensei()->course->get_product_courses( $item_id );
1201
+                $courses = Sensei()->course->get_product_courses($item_id);
1202 1202
 
1203 1203
                 // Loop and update those courses
1204
-                foreach ($courses as $course_item){
1204
+                foreach ($courses as $course_item) {
1205 1205
 
1206 1206
                     // Check and Remove course from courses user meta
1207
-                    $dataset_changes = Sensei_Utils::sensei_remove_user_from_course( $course_item->ID, $user_id );
1207
+                    $dataset_changes = Sensei_Utils::sensei_remove_user_from_course($course_item->ID, $user_id);
1208 1208
 
1209 1209
                 } // End For Loop
1210 1210
 
@@ -1225,30 +1225,30 @@  discard block
 block discarded – undo
1225 1225
      * @param   string  $product_type  '' or 'variation'
1226 1226
      * @return   WC_Product $wc_product_object
1227 1227
      */
1228
-    public static function get_product_object ( $wc_product_id = 0, $product_type = '' ) {
1228
+    public static function get_product_object($wc_product_id = 0, $product_type = '') {
1229 1229
 
1230 1230
         $wc_product_object = false;
1231
-        if ( 0 < intval( $wc_product_id ) ) {
1231
+        if (0 < intval($wc_product_id)) {
1232 1232
 
1233 1233
             // Get the product
1234
-            if ( function_exists( 'wc_get_product' ) ) {
1234
+            if (function_exists('wc_get_product')) {
1235 1235
 
1236
-                $wc_product_object = wc_get_product( $wc_product_id ); // Post WC 2.3
1236
+                $wc_product_object = wc_get_product($wc_product_id); // Post WC 2.3
1237 1237
 
1238
-            } elseif ( function_exists( 'get_product' ) ) {
1238
+            } elseif (function_exists('get_product')) {
1239 1239
 
1240
-                $wc_product_object = get_product( $wc_product_id ); // Post WC 2.0
1240
+                $wc_product_object = get_product($wc_product_id); // Post WC 2.0
1241 1241
 
1242 1242
             } else {
1243 1243
 
1244 1244
                 // Pre WC 2.0
1245
-                if ( 'variation' == $product_type || 'subscription_variation' == $product_type ) {
1245
+                if ('variation' == $product_type || 'subscription_variation' == $product_type) {
1246 1246
 
1247
-                    $wc_product_object = new WC_Product_Variation( $wc_product_id );
1247
+                    $wc_product_object = new WC_Product_Variation($wc_product_id);
1248 1248
 
1249 1249
                 } else {
1250 1250
 
1251
-                    $wc_product_object = new WC_Product( $wc_product_id );
1251
+                    $wc_product_object = new WC_Product($wc_product_id);
1252 1252
 
1253 1253
                 } // End If Statement
1254 1254
 
@@ -1271,19 +1271,19 @@  discard block
 block discarded – undo
1271 1271
      *
1272 1272
      * @return bool|int
1273 1273
      */
1274
-    public static function course_update ( $course_id = 0, $order_user = array()  ) {
1274
+    public static function course_update($course_id = 0, $order_user = array()) {
1275 1275
 
1276 1276
         global $current_user;
1277 1277
 
1278
-        if ( ! isset( $current_user ) || !$current_user->ID > 0 ) return false;
1278
+        if ( ! isset($current_user) || ! $current_user->ID > 0) return false;
1279 1279
 
1280 1280
         $data_update = false;
1281 1281
 
1282 1282
         // Get the product ID
1283
-        $wc_post_id = get_post_meta( intval( $course_id ), '_course_woocommerce_product', true );
1283
+        $wc_post_id = get_post_meta(intval($course_id), '_course_woocommerce_product', true);
1284 1284
 
1285 1285
         // Check if in the admin
1286
-        if ( is_admin() ) {
1286
+        if (is_admin()) {
1287 1287
 
1288 1288
             $user_login = $order_user['user_login'];
1289 1289
             $user_email = $order_user['user_email'];
@@ -1300,28 +1300,28 @@  discard block
 block discarded – undo
1300 1300
         } // End If Statement
1301 1301
 
1302 1302
         // This doesn't appear to be purely WooCommerce related. Should it be in a separate function?
1303
-        $course_prerequisite_id = (int) get_post_meta( $course_id, '_course_prerequisite', true );
1304
-        if( 0 < absint( $course_prerequisite_id ) ) {
1303
+        $course_prerequisite_id = (int) get_post_meta($course_id, '_course_prerequisite', true);
1304
+        if (0 < absint($course_prerequisite_id)) {
1305 1305
 
1306
-            $prereq_course_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, intval( $user_id ) );
1307
-            if ( ! $prereq_course_complete ) {
1306
+            $prereq_course_complete = Sensei_Utils::user_completed_course($course_prerequisite_id, intval($user_id));
1307
+            if ( ! $prereq_course_complete) {
1308 1308
 
1309 1309
                 // Remove all course user meta
1310
-                return Sensei_Utils::sensei_remove_user_from_course( $course_id, $user_id );
1310
+                return Sensei_Utils::sensei_remove_user_from_course($course_id, $user_id);
1311 1311
 
1312 1312
             }
1313 1313
         }
1314 1314
 
1315
-        $is_user_taking_course = Sensei_Utils::user_started_course( intval( $course_id ), intval( $user_id ) );
1315
+        $is_user_taking_course = Sensei_Utils::user_started_course(intval($course_id), intval($user_id));
1316 1316
 
1317
-        if( ! $is_user_taking_course ) {
1317
+        if ( ! $is_user_taking_course) {
1318 1318
 
1319
-            if ( Sensei_WC::is_woocommerce_active() && Sensei_WC::has_customer_bought_product( $user_id, $wc_post_id ) && ( 0 < $wc_post_id ) ) {
1319
+            if (Sensei_WC::is_woocommerce_active() && Sensei_WC::has_customer_bought_product($user_id, $wc_post_id) && (0 < $wc_post_id)) {
1320 1320
 
1321
-                $activity_logged = Sensei_Utils::user_start_course( intval( $user_id), intval( $course_id ) );
1321
+                $activity_logged = Sensei_Utils::user_start_course(intval($user_id), intval($course_id));
1322 1322
 
1323 1323
                 $is_user_taking_course = false;
1324
-                if ( true == $activity_logged ) {
1324
+                if (true == $activity_logged) {
1325 1325
 
1326 1326
                     $is_user_taking_course = true;
1327 1327
 
@@ -1344,14 +1344,14 @@  discard block
 block discarded – undo
1344 1344
      *
1345 1345
      * @return boolean                 Modified guest checkout setting
1346 1346
      */
1347
-    public static function disable_guest_checkout( $guest_checkout ) {
1347
+    public static function disable_guest_checkout($guest_checkout) {
1348 1348
 
1349
-        if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
1349
+        if ( ! is_admin() || (defined('DOING_AJAX') && DOING_AJAX)) {
1350 1350
 
1351
-            if( isset( WC()->cart->cart_contents ) && count( WC()->cart->cart_contents ) > 0 ) {
1351
+            if (isset(WC()->cart->cart_contents) && count(WC()->cart->cart_contents) > 0) {
1352 1352
 
1353
-                foreach( WC()->cart->cart_contents as $cart_key => $product ) {
1354
-                    if( isset( $product['product_id'] ) ) {
1353
+                foreach (WC()->cart->cart_contents as $cart_key => $product) {
1354
+                    if (isset($product['product_id'])) {
1355 1355
 
1356 1356
                         $args = array(
1357 1357
                             'posts_per_page' => -1,
@@ -1364,11 +1364,11 @@  discard block
 block discarded – undo
1364 1364
                             )
1365 1365
                         );
1366 1366
 
1367
-                        $posts = get_posts( $args );
1367
+                        $posts = get_posts($args);
1368 1368
 
1369
-                        if( $posts && count( $posts ) > 0 ) {
1369
+                        if ($posts && count($posts) > 0) {
1370 1370
 
1371
-                            foreach( $posts as $course ) {
1371
+                            foreach ($posts as $course) {
1372 1372
                                 $guest_checkout = '';
1373 1373
                                 break;
1374 1374
 
@@ -1397,23 +1397,23 @@  discard block
 block discarded – undo
1397 1397
      *
1398 1398
      * @return string
1399 1399
      **/
1400
-    public static function virtual_order_payment_complete( $order_status, $order_id ) {
1400
+    public static function virtual_order_payment_complete($order_status, $order_id) {
1401 1401
 
1402
-        $order = new WC_Order( $order_id );
1402
+        $order = new WC_Order($order_id);
1403 1403
 
1404
-        if ( ! isset ( $order ) ) return '';
1404
+        if ( ! isset ($order)) return '';
1405 1405
 
1406
-        if ( $order_status == 'wc-processing' && ( $order->post_status == 'wc-on-hold' || $order->post_status == 'wc-pending' || $order->post_status == 'wc-failed' ) ) {
1406
+        if ($order_status == 'wc-processing' && ($order->post_status == 'wc-on-hold' || $order->post_status == 'wc-pending' || $order->post_status == 'wc-failed')) {
1407 1407
 
1408 1408
             $virtual_order = true;
1409 1409
 
1410
-            if ( count( $order->get_items() ) > 0 ) {
1410
+            if (count($order->get_items()) > 0) {
1411 1411
 
1412
-                foreach( $order->get_items() as $item ) {
1412
+                foreach ($order->get_items() as $item) {
1413 1413
 
1414
-                    if ( $item['product_id'] > 0 ) {
1415
-                        $_product = $order->get_product_from_item( $item );
1416
-                        if ( ! $_product->is_virtual() ) {
1414
+                    if ($item['product_id'] > 0) {
1415
+                        $_product = $order->get_product_from_item($item);
1416
+                        if ( ! $_product->is_virtual()) {
1417 1417
 
1418 1418
                             $virtual_order = false;
1419 1419
                             break;
@@ -1427,7 +1427,7 @@  discard block
 block discarded – undo
1427 1427
             } // End If Statement
1428 1428
 
1429 1429
             // virtual order, mark as completed
1430
-            if ( $virtual_order ) {
1430
+            if ($virtual_order) {
1431 1431
 
1432 1432
                 return 'completed';
1433 1433
 
@@ -1450,14 +1450,14 @@  discard block
 block discarded – undo
1450 1450
      * @param  integer $user_id
1451 1451
      * @return boolean $user_access_permission
1452 1452
      */
1453
-    public static function get_subscription_permission( $user_access_permission, $user_id ){
1453
+    public static function get_subscription_permission($user_access_permission, $user_id) {
1454 1454
 
1455 1455
         global $post;
1456 1456
 
1457 1457
         // ignore the current case if the following conditions are met
1458
-        if ( ! class_exists( 'WC_Subscriptions' ) || empty( $user_id )
1459
-            || ! in_array( $post->post_type, array( 'course','lesson','quiz' ) )
1460
-            || ! wcs_user_has_subscription( $user_id) ){
1458
+        if ( ! class_exists('WC_Subscriptions') || empty($user_id)
1459
+            || ! in_array($post->post_type, array('course', 'lesson', 'quiz'))
1460
+            || ! wcs_user_has_subscription($user_id)) {
1461 1461
 
1462 1462
             return $user_access_permission;
1463 1463
 
@@ -1467,25 +1467,25 @@  discard block
 block discarded – undo
1467 1467
         // is the subscription on the the current course?
1468 1468
 
1469 1469
         $course_id = 0;
1470
-        if ( 'course' == $post->post_type ){
1470
+        if ('course' == $post->post_type) {
1471 1471
 
1472 1472
             $course_id = $post->ID;
1473 1473
 
1474
-        } elseif ( 'lesson' == $post->post_type ) {
1474
+        } elseif ('lesson' == $post->post_type) {
1475 1475
 
1476
-            $course_id = Sensei()->lesson->get_course_id( $post->ID );
1476
+            $course_id = Sensei()->lesson->get_course_id($post->ID);
1477 1477
 
1478 1478
         } else {
1479 1479
 
1480
-            $lesson_id =  Sensei()->quiz->get_lesson_id( $post->ID );
1481
-            $course_id = Sensei()->lesson->get_course_id( $lesson_id );
1480
+            $lesson_id = Sensei()->quiz->get_lesson_id($post->ID);
1481
+            $course_id = Sensei()->lesson->get_course_id($lesson_id);
1482 1482
 
1483 1483
         }
1484 1484
 
1485 1485
         // if the course has no subscription WooCommerce product attached to return the permissions as is
1486
-        $product_id = Sensei_WC::get_course_product_id( $course_id );
1487
-        $product = wc_get_product( $product_id );
1488
-        if( ! in_array( $product->get_type(), self::get_subscription_types() ) ){
1486
+        $product_id = Sensei_WC::get_course_product_id($course_id);
1487
+        $product = wc_get_product($product_id);
1488
+        if ( ! in_array($product->get_type(), self::get_subscription_types())) {
1489 1489
 
1490 1490
             return $user_access_permission;
1491 1491
 
@@ -1493,19 +1493,19 @@  discard block
 block discarded – undo
1493 1493
 
1494 1494
         // give access if user has active subscription on the product otherwise restrict it.
1495 1495
         // also check if the user was added to the course directly after the subscription started.
1496
-        if( wcs_user_has_subscription( $user_id, $product_id, 'active'  )
1497
-            || wcs_user_has_subscription( $user_id, $product_id, 'pending-cancel'  )
1498
-            || self::was_user_added_without_subscription( $user_id, $product_id, $course_id  ) ){
1496
+        if (wcs_user_has_subscription($user_id, $product_id, 'active')
1497
+            || wcs_user_has_subscription($user_id, $product_id, 'pending-cancel')
1498
+            || self::was_user_added_without_subscription($user_id, $product_id, $course_id)) {
1499 1499
 
1500 1500
             $user_access_permission = true;
1501 1501
 
1502
-        }else{
1502
+        } else {
1503 1503
 
1504 1504
             $user_access_permission = false;
1505 1505
             // do not show the WC permissions message
1506
-            remove_filter( 'sensei_the_no_permissions_message', array( 'Sensei_WC', 'alter_no_permissions_message' ), 20, 2 );
1507
-            Sensei()->permissions_message['title'] = __( 'No active subscription', 'woothemes-sensei' );
1508
-            Sensei()->permissions_message['message'] = __( 'Sorry, you do not have an access to this content without an active subscription.', 'woothemes-sensei' );
1506
+            remove_filter('sensei_the_no_permissions_message', array('Sensei_WC', 'alter_no_permissions_message'), 20, 2);
1507
+            Sensei()->permissions_message['title'] = __('No active subscription', 'woothemes-sensei');
1508
+            Sensei()->permissions_message['message'] = __('Sorry, you do not have an access to this content without an active subscription.', 'woothemes-sensei');
1509 1509
         }
1510 1510
 
1511 1511
         return $user_access_permission;
@@ -1518,9 +1518,9 @@  discard block
 block discarded – undo
1518 1518
      * @since 1.9.0
1519 1519
      * @return array
1520 1520
      */
1521
-    public static function get_subscription_types(){
1521
+    public static function get_subscription_types() {
1522 1522
 
1523
-        return array( 'subscription','subscription_variation','variable-subscription' );
1523
+        return array('subscription', 'subscription_variation', 'variable-subscription');
1524 1524
 
1525 1525
     }
1526 1526
 
@@ -1540,15 +1540,15 @@  discard block
 block discarded – undo
1540 1540
      *
1541 1541
      * @return bool
1542 1542
      */
1543
-    public static function was_user_added_without_subscription($user_id, $product_id, $course_id ){
1543
+    public static function was_user_added_without_subscription($user_id, $product_id, $course_id) {
1544 1544
 
1545 1545
         $course_start_date = '';
1546 1546
         $subscription_start_date = '';
1547
-        $is_a_subscription ='';
1547
+        $is_a_subscription = '';
1548 1548
         $was_user_added_without_subscription = true;
1549 1549
 
1550 1550
         // if user is not on the course they were not added
1551
-        if( ! Sensei_Utils::user_started_course( $course_id, $user_id ) ){
1551
+        if ( ! Sensei_Utils::user_started_course($course_id, $user_id)) {
1552 1552
 
1553 1553
             return false;
1554 1554
 
@@ -1557,34 +1557,34 @@  discard block
 block discarded – undo
1557 1557
         // if user doesn't have a subscription and is taking the course
1558 1558
         // they were added manually
1559 1559
         if ( ! wcs_user_has_subscription($user_id, $product_id)
1560
-            && Sensei_Utils::user_started_course( $course_id, get_current_user_id() )  ){
1560
+            && Sensei_Utils::user_started_course($course_id, get_current_user_id())) {
1561 1561
 
1562 1562
             return true;
1563 1563
 
1564 1564
         }
1565 1565
 
1566
-        $course_status =  Sensei_Utils::user_course_status( $course_id, $user_id );
1566
+        $course_status = Sensei_Utils::user_course_status($course_id, $user_id);
1567 1567
 
1568 1568
         // comparing dates setup data
1569
-        $course_start_date = date_create( $course_status->comment_date );
1570
-        $subscriptions = wcs_get_users_subscriptions( $user_id );
1569
+        $course_start_date = date_create($course_status->comment_date);
1570
+        $subscriptions = wcs_get_users_subscriptions($user_id);
1571 1571
 
1572 1572
         // comparing every subscription
1573
-        foreach( $subscriptions as $subscription ){
1573
+        foreach ($subscriptions as $subscription) {
1574 1574
 
1575 1575
             // for the following statuses we know the user was not added
1576 1576
             // manually
1577 1577
             $status = $subscription->get_status();
1578
-            if ( in_array( $status, array( 'pending-canceled', 'active', 'on-hold', 'pending' ) ) ) {
1578
+            if (in_array($status, array('pending-canceled', 'active', 'on-hold', 'pending'))) {
1579 1579
 
1580 1580
                 continue;
1581 1581
 
1582 1582
             }
1583 1583
 
1584
-            $current_subscription_start_date = date_create( $subscription->modified_date );
1584
+            $current_subscription_start_date = date_create($subscription->modified_date);
1585 1585
 
1586 1586
             // is the last updated subscription date newer than course start date
1587
-            if (  $current_subscription_start_date > $course_start_date   ) {
1587
+            if ($current_subscription_start_date > $course_start_date) {
1588 1588
 
1589 1589
                 return false;
1590 1590
 
Please login to merge, or discard this patch.
includes/hooks/woocommerce.php 1 patch
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -7,20 +7,20 @@  discard block
 block discarded – undo
7 7
  * show the WooCommerce course filter links above the courses
8 8
  * @since 1.9.0
9 9
  */
10
-add_filter( 'sensei_archive_course_filter_by_options', array( 'Sensei_WC', 'add_course_archive_wc_filter_links' ) );
10
+add_filter('sensei_archive_course_filter_by_options', array('Sensei_WC', 'add_course_archive_wc_filter_links'));
11 11
 
12 12
 /**
13 13
  * filter the queries for paid and free course based on the users selection.
14 14
  * @since 1.9.0
15 15
  */
16
-add_filter('pre_get_posts', array( 'Sensei_WC', 'course_archive_wc_filter_free'));
17
-add_filter('pre_get_posts', array( 'Sensei_WC', 'course_archive_wc_filter_paid'));
16
+add_filter('pre_get_posts', array('Sensei_WC', 'course_archive_wc_filter_free'));
17
+add_filter('pre_get_posts', array('Sensei_WC', 'course_archive_wc_filter_paid'));
18 18
 
19 19
 /**
20 20
  * Add woocommerce action above single course the action
21 21
  * @since 1.9.0
22 22
  */
23
-add_action('sensei_before_main_content', array('Sensei_WC', 'do_single_course_wc_single_product_action') ,50) ;
23
+add_action('sensei_before_main_content', array('Sensei_WC', 'do_single_course_wc_single_product_action'), 50);
24 24
 
25 25
 
26 26
 /******************************
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
  * Single Lesson Hooks
29 29
  *
30 30
  ******************************/
31
-add_filter( 'sensei_can_user_view_lesson', array( 'Sensei_WC','alter_can_user_view_lesson' ), 20, 3 );
31
+add_filter('sensei_can_user_view_lesson', array('Sensei_WC', 'alter_can_user_view_lesson'), 20, 3);
32 32
 
33 33
 /******************************
34 34
  *
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
  *
37 37
  ******************************/
38 38
 // add a notice on the checkout page to tell users about the course they've purchase
39
-add_action( 'template_redirect', array( 'Sensei_WC','course_link_from_order' ) );
39
+add_action('template_redirect', array('Sensei_WC', 'course_link_from_order'));
40 40
 
41 41
 /******************************
42 42
  *
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
  ******************************/
46 46
 //@since 1.9.0
47 47
 //show a notice if the user has already added the current course to their cart
48
-add_action( 'sensei_single_course_content_inside_before', array( 'Sensei_WC', 'course_in_cart_message' ), 20 );
48
+add_action('sensei_single_course_content_inside_before', array('Sensei_WC', 'course_in_cart_message'), 20);
49 49
 
50 50
 /******************************
51 51
  *
@@ -54,15 +54,15 @@  discard block
 block discarded – undo
54 54
  ******************************/
55 55
 //@since 1.9.0
56 56
 // alter the no permissions message to show the woocommerce message instead
57
-add_filter( 'sensei_the_no_permissions_message', array( 'Sensei_WC', 'alter_no_permissions_message' ), 20, 2 );
57
+add_filter('sensei_the_no_permissions_message', array('Sensei_WC', 'alter_no_permissions_message'), 20, 2);
58 58
 
59 59
 //@since 1.9.0
60 60
 // add the add to cart button for a valid purchasable course
61
-add_action( 'sensei_no_permissions_inside_before_content', array( 'Sensei_WC', 'the_add_to_cart_button_html' ), 20, 1);
61
+add_action('sensei_no_permissions_inside_before_content', array('Sensei_WC', 'the_add_to_cart_button_html'), 20, 1);
62 62
 
63 63
 // @since 1.9.0
64 64
 // add  woocommerce class to the the no permission body class to ensure WooCommerce elements are styled
65
-add_filter( 'body_class', array( 'Sensei_WC', 'add_woocommerce_body_class' ), 20, 1);
65
+add_filter('body_class', array('Sensei_WC', 'add_woocommerce_body_class'), 20, 1);
66 66
 
67 67
 
68 68
 /************************************
@@ -71,29 +71,29 @@  discard block
 block discarded – undo
71 71
  *
72 72
  ************************************/
73 73
 // Add Email link to course orders
74
-add_action( 'woocommerce_email_after_order_table', array( 'Sensei_WC', 'email_course_details' ), 10, 1 );
74
+add_action('woocommerce_email_after_order_table', array('Sensei_WC', 'email_course_details'), 10, 1);
75 75
 
76 76
 /************************************
77 77
  *
78 78
  * Checkout
79 79
  *
80 80
  ************************************/
81
-add_action( 'woocommerce_payment_complete',                 array( 'Sensei_WC', 'complete_order' ) );
82
-add_action( 'woocommerce_thankyou' ,                        array( 'Sensei_WC', 'complete_order' ) );
83
-add_action( 'woocommerce_order_status_completed',           array( 'Sensei_WC', 'complete_order' ) );
84
-add_action( 'woocommerce_order_status_processing',          array( 'Sensei_WC', 'complete_order' ) );
85
-add_action( 'woocommerce_order_status_cancelled',           array( 'Sensei_WC', 'cancel_order' ) );
86
-add_action( 'woocommerce_order_status_refunded',            array( 'Sensei_WC', 'cancel_order' ) );
81
+add_action('woocommerce_payment_complete', array('Sensei_WC', 'complete_order'));
82
+add_action('woocommerce_thankyou', array('Sensei_WC', 'complete_order'));
83
+add_action('woocommerce_order_status_completed', array('Sensei_WC', 'complete_order'));
84
+add_action('woocommerce_order_status_processing', array('Sensei_WC', 'complete_order'));
85
+add_action('woocommerce_order_status_cancelled', array('Sensei_WC', 'cancel_order'));
86
+add_action('woocommerce_order_status_refunded', array('Sensei_WC', 'cancel_order'));
87 87
 // Disable guest checkout if a course is in the cart as we need a valid user to store data for
88
-add_filter( 'pre_option_woocommerce_enable_guest_checkout', array( 'Sensei_WC', 'disable_guest_checkout' ) );
88
+add_filter('pre_option_woocommerce_enable_guest_checkout', array('Sensei_WC', 'disable_guest_checkout'));
89 89
 // Mark orders with virtual products as complete rather then stay processing
90
-add_filter( 'woocommerce_payment_complete_order_status',    array( 'Sensei_WC', 'virtual_order_payment_complete' ), 10, 2 );
90
+add_filter('woocommerce_payment_complete_order_status', array('Sensei_WC', 'virtual_order_payment_complete'), 10, 2);
91 91
 
92 92
 /************************************
93 93
  *
94 94
  * WooCommerce Subscriptions
95 95
  *
96 96
  ************************************/
97
-add_action( 'woocommerce_subscription_status_pending_to_active', array( 'Sensei_WC', 'activate_subscription' ), 50, 3 );
97
+add_action('woocommerce_subscription_status_pending_to_active', array('Sensei_WC', 'activate_subscription'), 50, 3);
98 98
 // filter the user permission of the subscription is not valid
99
-add_filter( 'sensei_access_permissions',               array( 'Sensei_WC', 'get_subscription_permission' ), 10, 2 );
99
+add_filter('sensei_access_permissions', array('Sensei_WC', 'get_subscription_permission'), 10, 2);
Please login to merge, or discard this patch.
includes/hooks/template.php 1 patch
Spacing   +99 added lines, -99 removed lines patch added patch discarded remove patch
@@ -18,10 +18,10 @@  discard block
 block discarded – undo
18 18
  *
19 19
  ***************************/
20 20
 //This hook allow us to change the template WordPress loads for a given page/post_type @since 1.9.0
21
-add_filter( 'template_include', array ( 'Sensei_Templates', 'template_loader' ), 10, 1 );
21
+add_filter('template_include', array('Sensei_Templates', 'template_loader'), 10, 1);
22 22
 
23 23
 //This hook adds the sensei pagination to the pagination hook
24
-add_action( 'sensei_pagination', array( 'Sensei_Frontend', 'load_content_pagination' ), 30 );
24
+add_action('sensei_pagination', array('Sensei_Frontend', 'load_content_pagination'), 30);
25 25
 
26 26
 
27 27
 /***************************
@@ -32,16 +32,16 @@  discard block
 block discarded – undo
32 32
  *
33 33
  ***************************/
34 34
 // deprecate the archive content hook @since 1.9.0
35
-add_action( 'sensei_archive_before_course_loop', array ( 'Sensei_Templates', 'deprecated_archive_course_content_hook' ), 10, 1 );
35
+add_action('sensei_archive_before_course_loop', array('Sensei_Templates', 'deprecated_archive_course_content_hook'), 10, 1);
36 36
 
37 37
 // Course archive title hook @since 1.9.0
38
-add_action('sensei_archive_before_course_loop', array( 'Sensei_Course', 'archive_header' ), 10, 0 );
38
+add_action('sensei_archive_before_course_loop', array('Sensei_Course', 'archive_header'), 10, 0);
39 39
 
40 40
 // add the course image above the content
41
-add_action('sensei_course_content_inside_before', array( Sensei()->course, 'course_image' ) ,10, 1 );
41
+add_action('sensei_course_content_inside_before', array(Sensei()->course, 'course_image'), 10, 1);
42 42
 
43 43
 // add course content title to the courses on the archive page
44
-add_action('sensei_course_content_inside_before', array( 'Sensei_Templates', 'the_title' ) ,5, 1 );
44
+add_action('sensei_course_content_inside_before', array('Sensei_Templates', 'the_title'), 5, 1);
45 45
 
46 46
 /***************************
47 47
  *
@@ -53,33 +53,33 @@  discard block
 block discarded – undo
53 53
 // @1.9.0
54 54
 // add deprecated action hooks for backwards compatibility sake
55 55
 // hooks on single course page: sensei_course_image , sensei_course_single_title, sensei_course_single_meta
56
-add_action('sensei_single_course_content_inside_before', array( 'Sensei_Templates', 'deprecated_single_course_inside_before_hooks' ), 80);
56
+add_action('sensei_single_course_content_inside_before', array('Sensei_Templates', 'deprecated_single_course_inside_before_hooks'), 80);
57 57
 
58 58
 // @1.9.0
59 59
 // hook the single course title on the single course page
60
-add_action( 'sensei_single_course_content_inside_before',array( 'Sensei_Course', 'the_title'), 10 );
60
+add_action('sensei_single_course_content_inside_before', array('Sensei_Course', 'the_title'), 10);
61 61
 
62 62
 // @1.9.0
63 63
 // hook the single course title on the single course page
64
-add_action( 'sensei_single_course_content_inside_before', array( Sensei()->course , 'course_image'), 20 );
64
+add_action('sensei_single_course_content_inside_before', array(Sensei()->course, 'course_image'), 20);
65 65
 
66 66
 
67 67
 // @1.9.0
68 68
 //Add legacy hooks deprecated in 1.9.0
69
-add_action( 'sensei_single_course_content_inside_before', array( 'Sensei_Templates','deprecate_course_single_meta_hooks'), 10 );
69
+add_action('sensei_single_course_content_inside_before', array('Sensei_Templates', 'deprecate_course_single_meta_hooks'), 10);
70 70
 
71 71
 // @1.9.0
72 72
 // Filter the content and replace it with the excerpt if the user doesn't have full access
73
-add_filter( 'the_content', array( 'Sensei_Course', 'single_course_content' ) );
73
+add_filter('the_content', array('Sensei_Course', 'single_course_content'));
74 74
 
75 75
 // @1.9.0
76 76
 // Deprecate lessons specific single course hooks
77
-add_action( 'sensei_single_course_content_inside_after', array( 'Sensei_Templates','deprecate_sensei_course_single_lessons_hook' ) );
77
+add_action('sensei_single_course_content_inside_after', array('Sensei_Templates', 'deprecate_sensei_course_single_lessons_hook'));
78 78
 
79 79
 // @1.9.0
80 80
 // Deprecate single main content hooks
81
-add_action( 'sensei_single_course_content_inside_after', array( 'Sensei_Templates', 'deprecated_single_main_content_hook') );
82
-add_action( 'sensei_single_message_content_inside_after', array( 'Sensei_Templates', 'deprecated_single_main_content_hook') );
81
+add_action('sensei_single_course_content_inside_after', array('Sensei_Templates', 'deprecated_single_main_content_hook'));
82
+add_action('sensei_single_message_content_inside_after', array('Sensei_Templates', 'deprecated_single_main_content_hook'));
83 83
 
84 84
 /**
85 85
  * Deprecate all the post type single titile hooks in favor of before content and after content hooks
@@ -87,74 +87,74 @@  discard block
 block discarded – undo
87 87
  * @deprecate 1.9.0
88 88
  * @1.9.0
89 89
  */
90
-add_action('sensei_single_message_content_inside_before', array( 'Sensei_Templates', 'deprecate_all_post_type_single_title_hooks' ) );
90
+add_action('sensei_single_message_content_inside_before', array('Sensei_Templates', 'deprecate_all_post_type_single_title_hooks'));
91 91
 
92 92
 /**
93 93
  * Deprecate hooks into the single course modules
94 94
  * @deprecated since 1.9.0
95 95
  */
96
-add_action('sensei_single_course_modules_before', array('Sensei_Templates','deprecate_module_before_hook' ) );
97
-add_action('sensei_single_course_modules_after', array('Sensei_Templates','deprecate_module_after_hook' ) );
96
+add_action('sensei_single_course_modules_before', array('Sensei_Templates', 'deprecate_module_before_hook'));
97
+add_action('sensei_single_course_modules_after', array('Sensei_Templates', 'deprecate_module_after_hook'));
98 98
 
99 99
 // @since 1.9.0
100 100
 // add the single course lessons title
101
-add_action( 'sensei_single_course_content_inside_after' , array( 'Sensei_Course','the_course_lessons_title'), 9 );
101
+add_action('sensei_single_course_content_inside_after', array('Sensei_Course', 'the_course_lessons_title'), 9);
102 102
 
103 103
 // @since 1.9.0
104 104
 // hooks in the course lessons query and remove it at the end
105 105
 // also loading the course lessons template in the middle
106
-add_action( 'sensei_single_course_lessons_before', array('Sensei_Course','load_single_course_lessons_query' ) );
107
-add_action( 'sensei_single_course_content_inside_after', 'course_single_lessons', 10 );
108
-add_action( 'sensei_single_course_lessons_after', array( 'Sensei_Utils','restore_wp_query' ));
106
+add_action('sensei_single_course_lessons_before', array('Sensei_Course', 'load_single_course_lessons_query'));
107
+add_action('sensei_single_course_content_inside_after', 'course_single_lessons', 10);
108
+add_action('sensei_single_course_lessons_after', array('Sensei_Utils', 'restore_wp_query'));
109 109
 
110 110
 // @since 1.9.0
111 111
 // add post classes to the lessons on the single course page
112
-add_filter( 'post_class', array( 'Sensei_Lesson', 'single_course_lessons_classes' ) );
112
+add_filter('post_class', array('Sensei_Lesson', 'single_course_lessons_classes'));
113 113
 
114 114
 // @since 1.9.0
115 115
 // lesson meta information on the single course page
116
-add_action( 'sensei_single_course_inside_before_lesson', array('Sensei_Lesson','the_lesson_meta') , 5);
116
+add_action('sensei_single_course_inside_before_lesson', array('Sensei_Lesson', 'the_lesson_meta'), 5);
117 117
 
118 118
 //@since 1.9.0
119 119
 // lesson image
120
-add_action( 'sensei_single_course_inside_before_lesson', array('Sensei_Lesson','the_lesson_thumbnail') , 8);
120
+add_action('sensei_single_course_inside_before_lesson', array('Sensei_Lesson', 'the_lesson_thumbnail'), 8);
121 121
 
122 122
 //@since 1.9.0
123 123
 // lesson custom excerpts
124
-add_filter( 'get_the_excerpt', array( 'Sensei_Lesson', 'alter_the_lesson_excerpt' ) );
124
+add_filter('get_the_excerpt', array('Sensei_Lesson', 'alter_the_lesson_excerpt'));
125 125
 
126 126
 // @since 1.9.0
127 127
 // run a deprecated hook for backwards compatibility sake
128
-add_action( 'sensei_single_course_modules_before', array( 'Sensei_Core_Modules', 'deprecate_sensei_single_course_modules_content'  ) );
128
+add_action('sensei_single_course_modules_before', array('Sensei_Core_Modules', 'deprecate_sensei_single_course_modules_content'));
129 129
 
130 130
 // @since 1.9.0
131 131
 // hook in the module loop intialization functionality
132
-add_action( 'sensei_single_course_modules_before', array( 'Sensei_Core_Modules', 'setup_single_course_module_loop' ) );
132
+add_action('sensei_single_course_modules_before', array('Sensei_Core_Modules', 'setup_single_course_module_loop'));
133 133
 
134 134
 // @since 1.9.0
135 135
 // hook in the module loop destructor functionality
136
-add_action( 'sensei_single_course_modules_after', array( 'Sensei_Core_Modules', 'teardown_single_course_module_loop' ) );
136
+add_action('sensei_single_course_modules_after', array('Sensei_Core_Modules', 'teardown_single_course_module_loop'));
137 137
 
138 138
 // @since 1.9.0
139 139
 // hook in the possible full content override to show instead of excerpt
140
-add_filter('get_the_excerpt', array( 'Sensei_Course', 'full_content_excerpt_override' ) );
140
+add_filter('get_the_excerpt', array('Sensei_Course', 'full_content_excerpt_override'));
141 141
 
142 142
 //@since 1.9.0
143 143
 //Course meta
144
-add_action( 'sensei_single_course_content_inside_before', array( 'Sensei_Course', 'the_course_enrolment_actions' ), 30 );
145
-add_action( 'sensei_single_course_content_inside_before', array( 'Sensei_Course' , 'the_course_video' ), 40 );
144
+add_action('sensei_single_course_content_inside_before', array('Sensei_Course', 'the_course_enrolment_actions'), 30);
145
+add_action('sensei_single_course_content_inside_before', array('Sensei_Course', 'the_course_video'), 40);
146 146
 
147 147
 //
148 148
 //// no permissions template for the single course
149 149
 //
150
-add_action( 'sensei_no_permissions_inside_before_content', array( 'Sensei_Course', 'the_title'), 20 );
151
-add_action( 'sensei_no_permissions_inside_before_content', array( Sensei()->course , 'course_image'), 25 );
152
-add_action( 'sensei_no_permissions_inside_before_content', array( 'Sensei_Course' , 'the_course_video' ), 40 );
153
-add_action( 'sensei_no_permissions_inside_after_content', array( Sensei()->modules, 'load_course_module_content_template') , 43 );
154
-add_action( 'sensei_no_permissions_inside_after_content' , array( 'Sensei_Course','the_course_lessons_title'), 45 );
155
-add_action( 'sensei_no_permissions_inside_after_content', array('Sensei_Course','load_single_course_lessons_query' ),50 );
156
-add_action( 'sensei_no_permissions_inside_after_content', 'course_single_lessons', 60 );
157
-add_action( 'sensei_no_permissions_inside_after_content', array( 'Sensei_Utils','restore_wp_query' ), 70);
150
+add_action('sensei_no_permissions_inside_before_content', array('Sensei_Course', 'the_title'), 20);
151
+add_action('sensei_no_permissions_inside_before_content', array(Sensei()->course, 'course_image'), 25);
152
+add_action('sensei_no_permissions_inside_before_content', array('Sensei_Course', 'the_course_video'), 40);
153
+add_action('sensei_no_permissions_inside_after_content', array(Sensei()->modules, 'load_course_module_content_template'), 43);
154
+add_action('sensei_no_permissions_inside_after_content', array('Sensei_Course', 'the_course_lessons_title'), 45);
155
+add_action('sensei_no_permissions_inside_after_content', array('Sensei_Course', 'load_single_course_lessons_query'), 50);
156
+add_action('sensei_no_permissions_inside_after_content', 'course_single_lessons', 60);
157
+add_action('sensei_no_permissions_inside_after_content', array('Sensei_Utils', 'restore_wp_query'), 70);
158 158
 
159 159
 /***************************
160 160
  *
@@ -165,54 +165,54 @@  discard block
 block discarded – undo
165 165
  ***************************/
166 166
 //@since 1.9.0
167 167
 // deprecate hooks no longer needed
168
-add_action( 'sensei_single_quiz_content_inside_before', array('Sensei_Quiz', 'deprecate_quiz_sensei_single_main_content_hook' ) );
169
-add_action( 'sensei_single_quiz_content_inside_before', array('Sensei_Quiz', 'deprecate_quiz_sensei_quiz_single_title_hook' ) );
168
+add_action('sensei_single_quiz_content_inside_before', array('Sensei_Quiz', 'deprecate_quiz_sensei_single_main_content_hook'));
169
+add_action('sensei_single_quiz_content_inside_before', array('Sensei_Quiz', 'deprecate_quiz_sensei_quiz_single_title_hook'));
170 170
 
171 171
 //@since 1.9.0
172 172
 // Single quiz title
173
-add_filter( 'the_title', array( 'Sensei_Quiz' , 'single_quiz_title' ), 20 , 2 ); // append Quiz
174
-add_action( 'sensei_single_quiz_content_inside_before', array( 'Sensei_Quiz', 'the_title' ), 20 ); //output single quiz
173
+add_filter('the_title', array('Sensei_Quiz', 'single_quiz_title'), 20, 2); // append Quiz
174
+add_action('sensei_single_quiz_content_inside_before', array('Sensei_Quiz', 'the_title'), 20); //output single quiz
175 175
 
176 176
 // since 1.9.0
177 177
 // initialize the quiz questions loop
178
-add_action( 'sensei_single_quiz_content_inside_before', array( 'Sensei_Quiz', 'start_quiz_questions_loop') );
178
+add_action('sensei_single_quiz_content_inside_before', array('Sensei_Quiz', 'start_quiz_questions_loop'));
179 179
 
180 180
 // since 1.9.0
181 181
 // hook in the quiz user message
182
-add_action( 'sensei_single_quiz_content_inside_before', array( 'Sensei_Quiz', 'the_user_status_message' ), 40 );
182
+add_action('sensei_single_quiz_content_inside_before', array('Sensei_Quiz', 'the_user_status_message'), 40);
183 183
 
184 184
 //@since 1.9.0
185 185
 // hook in the question title, description and quesiton media
186
-add_action( 'sensei_quiz_question_inside_before', array( 'Sensei_Question','the_question_title' ), 10 );
187
-add_action( 'sensei_quiz_question_inside_before', array( 'Sensei_Question','the_question_description' ), 20 );
188
-add_action( 'sensei_quiz_question_inside_before', array( 'Sensei_Question','the_question_media' ), 30 );
189
-add_action( 'sensei_quiz_question_inside_before', array( 'Sensei_Question','the_question_hidden_fields' ), 40 );
186
+add_action('sensei_quiz_question_inside_before', array('Sensei_Question', 'the_question_title'), 10);
187
+add_action('sensei_quiz_question_inside_before', array('Sensei_Question', 'the_question_description'), 20);
188
+add_action('sensei_quiz_question_inside_before', array('Sensei_Question', 'the_question_media'), 30);
189
+add_action('sensei_quiz_question_inside_before', array('Sensei_Question', 'the_question_hidden_fields'), 40);
190 190
 
191 191
 //@since 1.9.0
192 192
 // hook in incorrect / correct message above questions if the quiz has been graded
193
-add_action( 'sensei_quiz_question_inside_before', array( 'Sensei_Question', 'the_answer_result_indication' ), 50 );
193
+add_action('sensei_quiz_question_inside_before', array('Sensei_Question', 'the_answer_result_indication'), 50);
194 194
 
195 195
 //@since 1.9.0
196 196
 // add answer grading feedback at the bottom of the question
197
-add_action( 'sensei_quiz_question_inside_after', array( 'Sensei_Question', 'answer_feedback_notes' ) );
197
+add_action('sensei_quiz_question_inside_after', array('Sensei_Question', 'answer_feedback_notes'));
198 198
 
199 199
 //@since 1.9.0
200 200
 // add extra question data for different quesiton types when get_question_template_data_is_called.
201
-add_filter( 'sensei_get_question_template_data', array( 'Sensei_Question','multiple_choice_load_question_data'), 10, 3);
202
-add_filter( 'sensei_get_question_template_data', array( 'Sensei_Question','gap_fill_load_question_data'), 10, 3);
203
-add_filter( 'sensei_get_question_template_data', array( 'Sensei_Question','file_upload_load_question_data'), 10, 3);
201
+add_filter('sensei_get_question_template_data', array('Sensei_Question', 'multiple_choice_load_question_data'), 10, 3);
202
+add_filter('sensei_get_question_template_data', array('Sensei_Question', 'gap_fill_load_question_data'), 10, 3);
203
+add_filter('sensei_get_question_template_data', array('Sensei_Question', 'file_upload_load_question_data'), 10, 3);
204 204
 
205 205
 //@since 1.9.0
206 206
 // deprecate the quiz button action
207
-add_action( 'sensei_single_quiz_questions_after', array( 'Sensei_Quiz', 'action_buttons' ), 10, 0 );
207
+add_action('sensei_single_quiz_questions_after', array('Sensei_Quiz', 'action_buttons'), 10, 0);
208 208
 
209 209
 //@since 1.9.0
210 210
 // deprecate the sensei_complete_quiz hook
211
-add_action( 'sensei_single_quiz_content_inside_before', array( 'Sensei_Templates', 'deprecate_sensei_complete_quiz_action' ));
211
+add_action('sensei_single_quiz_content_inside_before', array('Sensei_Templates', 'deprecate_sensei_complete_quiz_action'));
212 212
 
213 213
 //@since 1.9.0
214 214
 // deprecate the sensei_quiz_question_type hook
215
-add_action( 'sensei_quiz_question_inside_after', array( 'Sensei_Templates', 'deprecate_sensei_quiz_question_type_action' ));
215
+add_action('sensei_quiz_question_inside_after', array('Sensei_Templates', 'deprecate_sensei_quiz_question_type_action'));
216 216
 
217 217
 /***************************
218 218
  *
@@ -223,63 +223,63 @@  discard block
 block discarded – undo
223 223
  ***************************/
224 224
 //@since 1.9.0
225 225
 // deprecate the main content hook on the single lesson page
226
-add_action( 'sensei_single_lesson_content_inside_before', array( 'Sensei_Templates', 'deprecate_lesson_single_main_content_hook' ), 20);
226
+add_action('sensei_single_lesson_content_inside_before', array('Sensei_Templates', 'deprecate_lesson_single_main_content_hook'), 20);
227 227
 
228 228
 //@since 1.9.0
229 229
 // hook in the lesson image on the single lesson
230
-add_action( 'sensei_single_lesson_content_inside_before', array( 'Sensei_Lesson', 'the_lesson_image' ), 17 );
230
+add_action('sensei_single_lesson_content_inside_before', array('Sensei_Lesson', 'the_lesson_image'), 17);
231 231
 
232 232
 //@since 1.9.0
233 233
 // hook in the lesson image on the single lesson deprecated hook function
234
-add_action( 'sensei_single_lesson_content_inside_before', array( 'Sensei_Templates','deprecate_lesson_image_hook' ), 10 );
234
+add_action('sensei_single_lesson_content_inside_before', array('Sensei_Templates', 'deprecate_lesson_image_hook'), 10);
235 235
 
236 236
 //@since 1.9.0
237 237
 // hook in the lesson single title deprecated function
238
-add_action( 'sensei_single_lesson_content_inside_before', array( 'Sensei_Templates', 'deprecate_sensei_lesson_single_title' ), 15 );
238
+add_action('sensei_single_lesson_content_inside_before', array('Sensei_Templates', 'deprecate_sensei_lesson_single_title'), 15);
239 239
 
240 240
 // @since 1.9.0
241 241
 // hook in the sensei lesson user notices
242
-add_action( 'sensei_single_lesson_content_inside_before', array( 'Sensei_Lesson', 'user_not_taking_course_message' ), 15 );
242
+add_action('sensei_single_lesson_content_inside_before', array('Sensei_Lesson', 'user_not_taking_course_message'), 15);
243 243
 
244 244
 // @since 1.9.0
245 245
 // attach the lesson title
246
-add_action( 'sensei_single_lesson_content_inside_before', array( 'Sensei_Lesson', 'the_title' ), 15 );
246
+add_action('sensei_single_lesson_content_inside_before', array('Sensei_Lesson', 'the_title'), 15);
247 247
 
248 248
 //@since 1.9.0
249 249
 // hook in the lesson image on the single lesson
250
-add_action( 'sensei_single_lesson_content_inside_before', array( 'Sensei_Lesson', 'user_lesson_quiz_status_message' ), 20 );
250
+add_action('sensei_single_lesson_content_inside_before', array('Sensei_Lesson', 'user_lesson_quiz_status_message'), 20);
251 251
 
252 252
 // @since 1.9.0
253 253
 // add the single lesson meta
254
-add_action( 'sensei_single_lesson_content_inside_after', 'sensei_the_single_lesson_meta', 10 );
254
+add_action('sensei_single_lesson_content_inside_after', 'sensei_the_single_lesson_meta', 10);
255 255
 
256 256
 // @since 1.9.0
257 257
 // deprecate the sensei_lesson_single_meta hook
258
-add_action( 'sensei_single_lesson_content_inside_after', array( 'Sensei_Templates', 'deprecate_sensei_lesson_single_meta_hook' ), 15 );
258
+add_action('sensei_single_lesson_content_inside_after', array('Sensei_Templates', 'deprecate_sensei_lesson_single_meta_hook'), 15);
259 259
 
260 260
 // @since 1.9.0
261 261
 // deprecate the sensei_lesson_course_signup hook
262
-add_action( 'sensei_single_lesson_content_inside_after', array( 'Sensei_Templates','deprecate_sensei_lesson_course_signup_hook' ), 20 );
262
+add_action('sensei_single_lesson_content_inside_after', array('Sensei_Templates', 'deprecate_sensei_lesson_course_signup_hook'), 20);
263 263
 
264 264
 // @since 1.9.0
265 265
 // hook in the lesson prerequisite completion message
266
-add_action( 'sensei_single_lesson_content_inside_after', array( 'Sensei_Lesson', 'prerequisite_complete_message' ), 20 );
266
+add_action('sensei_single_lesson_content_inside_after', array('Sensei_Lesson', 'prerequisite_complete_message'), 20);
267 267
 
268 268
 // @since 1.9.0
269 269
 // hook the single lesson course_signup_link
270
-add_action( 'sensei_single_lesson_content_inside_before', array( 'Sensei_Lesson', 'course_signup_link' ), 30 );
270
+add_action('sensei_single_lesson_content_inside_before', array('Sensei_Lesson', 'course_signup_link'), 30);
271 271
 
272 272
 // @since 1.9.0
273 273
 // hook the deprecate breadcrumbs and comments hooks
274
-add_action( 'sensei_after_main_content', array( 'Sensei_Templates', 'deprecate_single_lesson_breadcrumbs_and_comments_hooks'), 5 );
274
+add_action('sensei_after_main_content', array('Sensei_Templates', 'deprecate_single_lesson_breadcrumbs_and_comments_hooks'), 5);
275 275
 
276 276
 // @since 1.9.0
277 277
 // Add the quiz specific buttons and notices to the lesson
278
-add_action( 'sensei_single_lesson_content_inside_after', array('Sensei_Lesson', 'footer_quiz_call_to_action' ));
278
+add_action('sensei_single_lesson_content_inside_after', array('Sensei_Lesson', 'footer_quiz_call_to_action'));
279 279
 
280 280
 // @since 1.9.0
281 281
 // hook in the comments on the single lessons page
282
-add_action( 'sensei_pagination', array( 'Sensei_Lesson', 'output_comments' ), 90 );
282
+add_action('sensei_pagination', array('Sensei_Lesson', 'output_comments'), 90);
283 283
 
284 284
 /**********************
285 285
  *
@@ -289,9 +289,9 @@  discard block
 block discarded – undo
289 289
  *
290 290
  ************************/
291 291
 
292
-add_action( 'sensei_single_message_content_inside_before', array( 'Sensei_Messages', 'the_title' ), 20 );
292
+add_action('sensei_single_message_content_inside_before', array('Sensei_Messages', 'the_title'), 20);
293 293
 
294
-add_action( 'sensei_single_message_content_inside_before', array( 'Sensei_Messages', 'the_message_sent_by_title' ), 40 );
294
+add_action('sensei_single_message_content_inside_before', array('Sensei_Messages', 'the_message_sent_by_title'), 40);
295 295
 
296 296
 /*************************
297 297
  *
@@ -303,19 +303,19 @@  discard block
 block discarded – undo
303 303
 
304 304
 // deprecate the sensei_lesson_archive_header hook
305 305
 // @deprecated since 1.9.0
306
-add_action( 'sensei_loop_lesson_inside_before', array( 'Sensei_Lesson', 'deprecate_sensei_lesson_archive_header_hook' ), 20 );
306
+add_action('sensei_loop_lesson_inside_before', array('Sensei_Lesson', 'deprecate_sensei_lesson_archive_header_hook'), 20);
307 307
 
308 308
 // @1.9.0
309 309
 //The archive title header on the lesson archive loop
310
-add_action( 'sensei_loop_lesson_inside_before', array( Sensei()->lesson, 'the_archive_header' ), 20 );
310
+add_action('sensei_loop_lesson_inside_before', array(Sensei()->lesson, 'the_archive_header'), 20);
311 311
 
312 312
 // @since 1.9.0
313 313
 //Output the lesson header on the content-lesson.php which runs inside the lessons loop
314
-add_action( 'sensei_content_lesson_inside_before', array( 'Sensei_Lesson', 'the_lesson_meta' ), 20 );
314
+add_action('sensei_content_lesson_inside_before', array('Sensei_Lesson', 'the_lesson_meta'), 20);
315 315
 
316 316
 // @since 1.9.0
317 317
 // output only part of the lesson on the archive
318
-add_filter('the_content', array( 'Sensei_Lesson','limit_archive_content' ) );
318
+add_filter('the_content', array('Sensei_Lesson', 'limit_archive_content'));
319 319
 
320 320
 /**************************
321 321
  *
@@ -326,15 +326,15 @@  discard block
 block discarded – undo
326 326
  **************************/
327 327
 // @since 1.9.0
328 328
 // deprecate the learner profile content hook as the markup code is added in the template directly.
329
-add_action('sensei_learner_profile_content_before', array( 'Sensei_Learner_Profiles', 'deprecate_sensei_learner_profile_content_hook' ) );
329
+add_action('sensei_learner_profile_content_before', array('Sensei_Learner_Profiles', 'deprecate_sensei_learner_profile_content_hook'));
330 330
 
331 331
 // @since 1.9.0
332 332
 // do the sensei complete course action on the learner profiles page.
333
-add_action('sensei_learner_profile_content_before', array( 'Sensei_Templates', 'fire_sensei_complete_course_hook' ) );
333
+add_action('sensei_learner_profile_content_before', array('Sensei_Templates', 'fire_sensei_complete_course_hook'));
334 334
 
335 335
 // @since 1.9.0
336 336
 // fire the frontend messages hook before the profile content
337
-add_action('sensei_learner_profile_inside_content_before', array( 'Sensei_Templates', 'fire_frontend_messages_hook' ) );
337
+add_action('sensei_learner_profile_inside_content_before', array('Sensei_Templates', 'fire_frontend_messages_hook'));
338 338
 
339 339
 
340 340
 /**********************************
@@ -347,26 +347,26 @@  discard block
 block discarded – undo
347 347
 
348 348
 // @since 1.9.0
349 349
 // fire the deprecated hook function within the course-result.php file
350
-add_action( 'sensei_course_results_content_before', array('Sensei_Course_Results','deprecate_sensei_course_results_content_hook') );
350
+add_action('sensei_course_results_content_before', array('Sensei_Course_Results', 'deprecate_sensei_course_results_content_hook'));
351 351
 
352 352
 // @since 1.9.0
353 353
 // fire the sensei message hooke inside the course-result.php file
354
-add_action( 'sensei_course_results_content_inside_before', array('Sensei_Course_Results','fire_sensei_message_hook') );
354
+add_action('sensei_course_results_content_inside_before', array('Sensei_Course_Results', 'fire_sensei_message_hook'));
355 355
 
356 356
 // @since 1.9.0
357 357
 // load the course information on the course results page
358
-add_action( 'sensei_course_results_content_inside_before_lessons', array( Sensei()->course_results,'course_info') );
358
+add_action('sensei_course_results_content_inside_before_lessons', array(Sensei()->course_results, 'course_info'));
359 359
 
360 360
 // @since 1.9.0
361
-add_action( 'sensei_course_results_content_inside_before', array( Sensei()->course,'course_image') );
361
+add_action('sensei_course_results_content_inside_before', array(Sensei()->course, 'course_image'));
362 362
 
363 363
 // @since 1.9.0
364 364
 // deprecate the course results top hook in favour of a new hook
365
-add_action( 'sensei_course_results_content_inside_before', array( 'Sensei_Course_Results', 'deprecate_course_results_top_hook') );
365
+add_action('sensei_course_results_content_inside_before', array('Sensei_Course_Results', 'deprecate_course_results_top_hook'));
366 366
 
367 367
 // @since 1.9.0
368 368
 // Fire the course image hook within the course results page
369
-add_action( 'sensei_course_results_content_inside_before', array( 'Sensei_Course_Results', 'fire_course_image_hook') );
369
+add_action('sensei_course_results_content_inside_before', array('Sensei_Course_Results', 'fire_course_image_hook'));
370 370
 
371 371
 
372 372
 /**********************************
@@ -378,19 +378,19 @@  discard block
 block discarded – undo
378 378
  ********************************/
379 379
 // @since 1.9.0
380 380
 // fire the sensei complete course action on the my courses template
381
-add_action( 'sensei_my_courses_before', array( 'Sensei_Templates', 'fire_sensei_complete_course_hook' ) );
381
+add_action('sensei_my_courses_before', array('Sensei_Templates', 'fire_sensei_complete_course_hook'));
382 382
 
383 383
 // @since 1.9.0
384 384
 // fire the sensei frontend messages hook before the my-courses content
385
-add_action('sensei_my_courses_content_inside_before', array( 'Sensei_Templates', 'fire_frontend_messages_hook' ) );
385
+add_action('sensei_my_courses_content_inside_before', array('Sensei_Templates', 'fire_frontend_messages_hook'));
386 386
 
387 387
 // @since 1.9.0
388 388
 // deprecate the sensei_before_user_course_content hook
389
-add_action('sensei_my_courses_content_inside_before', array( 'Sensei_Templates', 'deprecate_sensei_before_user_course_content_hook' ) );
389
+add_action('sensei_my_courses_content_inside_before', array('Sensei_Templates', 'deprecate_sensei_before_user_course_content_hook'));
390 390
 
391 391
 // @since 1.9.0
392 392
 // deprecate the sensei_after_user_course_content hook
393
-add_action('sensei_my_courses_content_inside_after', array( 'Sensei_Templates', 'deprecate_sensei_after_user_course_content_hook' ) );
393
+add_action('sensei_my_courses_content_inside_after', array('Sensei_Templates', 'deprecate_sensei_after_user_course_content_hook'));
394 394
 
395 395
 /**********************************
396 396
  *
@@ -402,7 +402,7 @@  discard block
 block discarded – undo
402 402
 // @since 1.9.0
403 403
 // deprecate the sensei_login_form hok which was use to load the login form.
404 404
 // This now loads independent of the my-courses template which helps keep templates free from logic
405
-add_action( 'sensei_login_form_before', array( 'Sensei_Templates', 'deprecate_sensei_login_form_hook' ) );
405
+add_action('sensei_login_form_before', array('Sensei_Templates', 'deprecate_sensei_login_form_hook'));
406 406
 
407 407
 /**********************************
408 408
  *
@@ -413,16 +413,16 @@  discard block
 block discarded – undo
413 413
  ********************************/
414 414
 // @since 1.9.0
415 415
 // Deprecate the archive messages hooks no longer supported
416
-add_action( 'sensei_archive_before_message_loop', array( 'Sensei_Templates', 'deprecated_archive_message_hooks' ) );
416
+add_action('sensei_archive_before_message_loop', array('Sensei_Templates', 'deprecated_archive_message_hooks'));
417 417
 
418 418
 // @since 1.9.0
419 419
 // Deprecate the archive messages hooks no longer supported
420
-add_action( 'sensei_archive_before_message_loop', array( 'Sensei_Messages', 'the_archive_header' ) );
420
+add_action('sensei_archive_before_message_loop', array('Sensei_Messages', 'the_archive_header'));
421 421
 
422 422
 // @since 1.9.0
423 423
 // output the message title and the message sensei
424
-add_action( 'sensei_content_message_before', array( 'Sensei_Messages', 'the_message_title' ), 10, 1 );
425
-add_action( 'sensei_content_message_before', array( 'Sensei_Messages', 'the_message_sender' ), 20 , 1 );
424
+add_action('sensei_content_message_before', array('Sensei_Messages', 'the_message_title'), 10, 1);
425
+add_action('sensei_content_message_before', array('Sensei_Messages', 'the_message_sender'), 20, 1);
426 426
 
427 427
 /**********************************
428 428
  *
@@ -431,7 +431,7 @@  discard block
 block discarded – undo
431 431
  *
432 432
  *
433 433
  **********************************/
434
-add_action( 'sensei_loop_course_before', array( 'Sensei_Course', 'course_category_title' ), 70 , 1 );
434
+add_action('sensei_loop_course_before', array('Sensei_Course', 'course_category_title'), 70, 1);
435 435
 
436 436
 /**********************************
437 437
  *
@@ -442,9 +442,9 @@  discard block
 block discarded – undo
442 442
  **********************************/
443 443
 //@since 1.9.0
444 444
 //add a title to the teacher archive page when viewn siteurl/author/{teacher-username}
445
-add_action( 'sensei_teacher_archive_course_loop_before', array( 'Sensei_Teacher', 'archive_title' ) );
445
+add_action('sensei_teacher_archive_course_loop_before', array('Sensei_Teacher', 'archive_title'));
446 446
 
447 447
 //@since 1.9.0
448 448
 // remove course meta from the teacher page until it can be refactored to allow only removing the
449 449
 // teacher name and not all lessons
450
-add_action( 'sensei_teacher_archive_course_loop_before', array( 'Sensei_Teacher', 'remove_course_meta_on_teacher_archive' ) );
450
+add_action('sensei_teacher_archive_course_loop_before', array('Sensei_Teacher', 'remove_course_meta_on_teacher_archive'));
Please login to merge, or discard this patch.