@@ -816,7 +816,7 @@ discard block |
||
816 | 816 | * |
817 | 817 | * @since 1.4.5 |
818 | 818 | * @access public |
819 | - * @param mixed $image_size |
|
819 | + * @param string $image_size |
|
820 | 820 | * @return string |
821 | 821 | */ |
822 | 822 | public function get_image_size( $image_size ) { |
@@ -1042,7 +1042,7 @@ discard block |
||
1042 | 1042 | * @since 1.0.0 |
1043 | 1043 | * @param int $course_id (default: 0) |
1044 | 1044 | * @param array/Object $order_user (default: array()) Specific user's data. |
1045 | - * @return bool|int |
|
1045 | + * @return boolean|string |
|
1046 | 1046 | */ |
1047 | 1047 | public function woocommerce_course_update ( $course_id = 0, $order_user = array() ) { |
1048 | 1048 | |
@@ -1085,7 +1085,7 @@ discard block |
||
1085 | 1085 | * Disable guest checkout if a course product is in the cart |
1086 | 1086 | * @deprecated since 1.9.0 |
1087 | 1087 | * @param boolean $guest_checkout Current guest checkout setting |
1088 | - * @return boolean Modified guest checkout setting |
|
1088 | + * @return string|boolean Modified guest checkout setting |
|
1089 | 1089 | */ |
1090 | 1090 | public function disable_guest_checkout( $guest_checkout ) { |
1091 | 1091 |
@@ -10,902 +10,902 @@ discard block |
||
10 | 10 | */ |
11 | 11 | class Sensei_Main { |
12 | 12 | |
13 | - /** |
|
14 | - * @var string |
|
15 | - * Reference to the main plugin file |
|
16 | - */ |
|
17 | - private $file; |
|
18 | - |
|
19 | - /** |
|
20 | - * @var Sensei_Main $_instance to the the main and only instance of the Sensei class. |
|
21 | - * @since 1.8.0 |
|
22 | - */ |
|
23 | - protected static $_instance = null; |
|
24 | - |
|
25 | - /** |
|
26 | - * Main reference to the plugins current version |
|
27 | - */ |
|
28 | - public $version; |
|
29 | - |
|
30 | - /** |
|
31 | - * Public token, referencing for the text domain. |
|
32 | - */ |
|
33 | - public $token = 'woothemes-sensei'; |
|
34 | - |
|
35 | - /** |
|
36 | - * Plugin url and path for use when access resources. |
|
37 | - */ |
|
38 | - public $plugin_url; |
|
39 | - public $plugin_path; |
|
40 | - public $template_url; |
|
41 | - |
|
42 | - /** |
|
43 | - * @var Sensei_PostTypes |
|
44 | - * All Sensei sub classes. Currently used to access functionality contained within |
|
45 | - * within Sensei sub classes e.g. Sensei()->course->all_courses() |
|
46 | - */ |
|
47 | - public $post_types; |
|
48 | - |
|
49 | - /** |
|
50 | - * @var WooThemes_Sensei_Settings |
|
51 | - */ |
|
52 | - public $settings; |
|
53 | - |
|
54 | - /** |
|
55 | - * @var WooThemes_Sensei_Course_Results |
|
56 | - */ |
|
57 | - public $course_results; |
|
58 | - |
|
59 | - /** |
|
60 | - * @var Sensei_Updates |
|
61 | - */ |
|
62 | - public $updates; |
|
63 | - /** |
|
64 | - * @var WooThemes_Sensei_Course |
|
65 | - */ |
|
66 | - public $course; |
|
67 | - |
|
68 | - /** |
|
69 | - * @var WooThemes_Sensei_Lesson |
|
70 | - */ |
|
71 | - public $lesson; |
|
72 | - |
|
73 | - /** |
|
74 | - * @var WooThemes_Sensei_Quiz |
|
75 | - */ |
|
76 | - public $quiz; |
|
77 | - |
|
78 | - /** |
|
79 | - * @var WooThemes_Sensei_Question |
|
80 | - */ |
|
81 | - public $question; |
|
82 | - |
|
83 | - /** |
|
84 | - * @var WooThemes_Sensei_Admin |
|
85 | - */ |
|
86 | - public $admin; |
|
87 | - |
|
88 | - /** |
|
89 | - * @var WooThemes_Sensei_Frontend |
|
90 | - */ |
|
91 | - public $frontend; |
|
92 | - |
|
93 | - /** |
|
94 | - * @var Sensei_Notices |
|
95 | - */ |
|
96 | - public $notices; |
|
97 | - |
|
98 | - /** |
|
99 | - * @var WooThemes_Sensei_Grading |
|
100 | - */ |
|
101 | - public $grading; |
|
102 | - |
|
103 | - /** |
|
104 | - * @var WooThemes_Sensei_Emails |
|
105 | - */ |
|
106 | - public $emails; |
|
107 | - |
|
108 | - /** |
|
109 | - * @var WooThemes_Sensei_Learner_Profiles |
|
110 | - */ |
|
111 | - public $learner_profiles; |
|
112 | - |
|
113 | - /** |
|
114 | - * @var Sensei_Teacher |
|
115 | - */ |
|
116 | - public $teacher; |
|
117 | - |
|
118 | - /** |
|
119 | - * @var WooThemes_Sensei_Learners |
|
120 | - */ |
|
121 | - public $learners; |
|
122 | - |
|
123 | - /** |
|
124 | - * @var array |
|
125 | - * Global instance for access to the permissions message shown |
|
126 | - * when users do not have the right privileges to access resources. |
|
127 | - */ |
|
128 | - public $permissions_message; |
|
129 | - |
|
130 | - /** |
|
131 | - * @var Sensei_Core_Modules Sensei Modules functionality |
|
132 | - */ |
|
133 | - public $modules; |
|
134 | - |
|
135 | - /** |
|
136 | - * @var Sensei_Analysis |
|
137 | - */ |
|
138 | - public $analysis; |
|
139 | - |
|
140 | - /** |
|
141 | - * Constructor method. |
|
142 | - * @param string $file The base file of the plugin. |
|
143 | - * @since 1.0.0 |
|
144 | - */ |
|
145 | - public function __construct ( $file ) { |
|
146 | - |
|
147 | - // Setup object data |
|
148 | - $this->file = $file; |
|
149 | - $this->plugin_url = trailingslashit( plugins_url( '', $plugin = $file ) ); |
|
150 | - $this->plugin_path = trailingslashit( dirname( $file ) ); |
|
151 | - $this->template_url = apply_filters( 'sensei_template_url', 'sensei/' ); |
|
152 | - $this->permissions_message = array( 'title' => __( 'Permission Denied', 'woothemes-sensei' ), 'message' => __( 'Unfortunately you do not have permissions to access this page.', 'woothemes-sensei' ) ); |
|
153 | - |
|
154 | - // Initialize the core Sensei functionality |
|
155 | - $this->init(); |
|
156 | - |
|
157 | - // Installation |
|
158 | - if ( is_admin() && ! defined( 'DOING_AJAX' ) ) $this->install(); |
|
159 | - |
|
160 | - // Run this on activation. |
|
161 | - register_activation_hook( $this->file, array( $this, 'activation' ) ); |
|
162 | - |
|
163 | - // Image Sizes |
|
164 | - $this->init_image_sizes(); |
|
165 | - |
|
166 | - // load all hooks |
|
167 | - $this->load_hooks(); |
|
168 | - |
|
169 | - } // End __construct() |
|
170 | - |
|
171 | - /** |
|
172 | - * Load the foundations of Sensei. |
|
173 | - * @since 1.9.0 |
|
174 | - */ |
|
175 | - protected function init(){ |
|
176 | - |
|
177 | - // Localisation |
|
178 | - $this->load_plugin_textdomain(); |
|
179 | - add_action( 'init', array( $this, 'load_localisation' ), 0 ); |
|
180 | - |
|
181 | - // Setup settings |
|
182 | - $this->settings = new Sensei_Settings(); |
|
183 | - |
|
184 | - // load the shortcode loader into memory, so as to listen to all for |
|
185 | - // all shortcodes on the front end |
|
186 | - new Sensei_Shortcode_Loader(); |
|
187 | - |
|
188 | - } |
|
189 | - |
|
190 | - /** |
|
191 | - * Global Sensei Instance |
|
192 | - * |
|
193 | - * Ensure that only one instance of the main Sensei class can be loaded. |
|
194 | - * |
|
195 | - * @since 1.8.0 |
|
196 | - * @static |
|
197 | - * @see WC() |
|
198 | - * @return WooThemes_Sensei Instance. |
|
199 | - */ |
|
200 | - public static function instance() { |
|
13 | + /** |
|
14 | + * @var string |
|
15 | + * Reference to the main plugin file |
|
16 | + */ |
|
17 | + private $file; |
|
18 | + |
|
19 | + /** |
|
20 | + * @var Sensei_Main $_instance to the the main and only instance of the Sensei class. |
|
21 | + * @since 1.8.0 |
|
22 | + */ |
|
23 | + protected static $_instance = null; |
|
24 | + |
|
25 | + /** |
|
26 | + * Main reference to the plugins current version |
|
27 | + */ |
|
28 | + public $version; |
|
29 | + |
|
30 | + /** |
|
31 | + * Public token, referencing for the text domain. |
|
32 | + */ |
|
33 | + public $token = 'woothemes-sensei'; |
|
34 | + |
|
35 | + /** |
|
36 | + * Plugin url and path for use when access resources. |
|
37 | + */ |
|
38 | + public $plugin_url; |
|
39 | + public $plugin_path; |
|
40 | + public $template_url; |
|
41 | + |
|
42 | + /** |
|
43 | + * @var Sensei_PostTypes |
|
44 | + * All Sensei sub classes. Currently used to access functionality contained within |
|
45 | + * within Sensei sub classes e.g. Sensei()->course->all_courses() |
|
46 | + */ |
|
47 | + public $post_types; |
|
48 | + |
|
49 | + /** |
|
50 | + * @var WooThemes_Sensei_Settings |
|
51 | + */ |
|
52 | + public $settings; |
|
53 | + |
|
54 | + /** |
|
55 | + * @var WooThemes_Sensei_Course_Results |
|
56 | + */ |
|
57 | + public $course_results; |
|
58 | + |
|
59 | + /** |
|
60 | + * @var Sensei_Updates |
|
61 | + */ |
|
62 | + public $updates; |
|
63 | + /** |
|
64 | + * @var WooThemes_Sensei_Course |
|
65 | + */ |
|
66 | + public $course; |
|
67 | + |
|
68 | + /** |
|
69 | + * @var WooThemes_Sensei_Lesson |
|
70 | + */ |
|
71 | + public $lesson; |
|
72 | + |
|
73 | + /** |
|
74 | + * @var WooThemes_Sensei_Quiz |
|
75 | + */ |
|
76 | + public $quiz; |
|
77 | + |
|
78 | + /** |
|
79 | + * @var WooThemes_Sensei_Question |
|
80 | + */ |
|
81 | + public $question; |
|
82 | + |
|
83 | + /** |
|
84 | + * @var WooThemes_Sensei_Admin |
|
85 | + */ |
|
86 | + public $admin; |
|
87 | + |
|
88 | + /** |
|
89 | + * @var WooThemes_Sensei_Frontend |
|
90 | + */ |
|
91 | + public $frontend; |
|
92 | + |
|
93 | + /** |
|
94 | + * @var Sensei_Notices |
|
95 | + */ |
|
96 | + public $notices; |
|
97 | + |
|
98 | + /** |
|
99 | + * @var WooThemes_Sensei_Grading |
|
100 | + */ |
|
101 | + public $grading; |
|
102 | + |
|
103 | + /** |
|
104 | + * @var WooThemes_Sensei_Emails |
|
105 | + */ |
|
106 | + public $emails; |
|
107 | + |
|
108 | + /** |
|
109 | + * @var WooThemes_Sensei_Learner_Profiles |
|
110 | + */ |
|
111 | + public $learner_profiles; |
|
112 | + |
|
113 | + /** |
|
114 | + * @var Sensei_Teacher |
|
115 | + */ |
|
116 | + public $teacher; |
|
117 | + |
|
118 | + /** |
|
119 | + * @var WooThemes_Sensei_Learners |
|
120 | + */ |
|
121 | + public $learners; |
|
122 | + |
|
123 | + /** |
|
124 | + * @var array |
|
125 | + * Global instance for access to the permissions message shown |
|
126 | + * when users do not have the right privileges to access resources. |
|
127 | + */ |
|
128 | + public $permissions_message; |
|
129 | + |
|
130 | + /** |
|
131 | + * @var Sensei_Core_Modules Sensei Modules functionality |
|
132 | + */ |
|
133 | + public $modules; |
|
134 | + |
|
135 | + /** |
|
136 | + * @var Sensei_Analysis |
|
137 | + */ |
|
138 | + public $analysis; |
|
139 | + |
|
140 | + /** |
|
141 | + * Constructor method. |
|
142 | + * @param string $file The base file of the plugin. |
|
143 | + * @since 1.0.0 |
|
144 | + */ |
|
145 | + public function __construct ( $file ) { |
|
146 | + |
|
147 | + // Setup object data |
|
148 | + $this->file = $file; |
|
149 | + $this->plugin_url = trailingslashit( plugins_url( '', $plugin = $file ) ); |
|
150 | + $this->plugin_path = trailingslashit( dirname( $file ) ); |
|
151 | + $this->template_url = apply_filters( 'sensei_template_url', 'sensei/' ); |
|
152 | + $this->permissions_message = array( 'title' => __( 'Permission Denied', 'woothemes-sensei' ), 'message' => __( 'Unfortunately you do not have permissions to access this page.', 'woothemes-sensei' ) ); |
|
153 | + |
|
154 | + // Initialize the core Sensei functionality |
|
155 | + $this->init(); |
|
156 | + |
|
157 | + // Installation |
|
158 | + if ( is_admin() && ! defined( 'DOING_AJAX' ) ) $this->install(); |
|
159 | + |
|
160 | + // Run this on activation. |
|
161 | + register_activation_hook( $this->file, array( $this, 'activation' ) ); |
|
162 | + |
|
163 | + // Image Sizes |
|
164 | + $this->init_image_sizes(); |
|
165 | + |
|
166 | + // load all hooks |
|
167 | + $this->load_hooks(); |
|
168 | + |
|
169 | + } // End __construct() |
|
170 | + |
|
171 | + /** |
|
172 | + * Load the foundations of Sensei. |
|
173 | + * @since 1.9.0 |
|
174 | + */ |
|
175 | + protected function init(){ |
|
176 | + |
|
177 | + // Localisation |
|
178 | + $this->load_plugin_textdomain(); |
|
179 | + add_action( 'init', array( $this, 'load_localisation' ), 0 ); |
|
180 | + |
|
181 | + // Setup settings |
|
182 | + $this->settings = new Sensei_Settings(); |
|
183 | + |
|
184 | + // load the shortcode loader into memory, so as to listen to all for |
|
185 | + // all shortcodes on the front end |
|
186 | + new Sensei_Shortcode_Loader(); |
|
187 | + |
|
188 | + } |
|
189 | + |
|
190 | + /** |
|
191 | + * Global Sensei Instance |
|
192 | + * |
|
193 | + * Ensure that only one instance of the main Sensei class can be loaded. |
|
194 | + * |
|
195 | + * @since 1.8.0 |
|
196 | + * @static |
|
197 | + * @see WC() |
|
198 | + * @return WooThemes_Sensei Instance. |
|
199 | + */ |
|
200 | + public static function instance() { |
|
201 | 201 | |
202 | - if ( is_null( self::$_instance ) ) { |
|
202 | + if ( is_null( self::$_instance ) ) { |
|
203 | 203 | |
204 | - //Sensei requires a reference to the main Sensei plugin file |
|
205 | - $sensei_main_plugin_file = dirname ( dirname( __FILE__ ) ) . '/woothemes-sensei.php'; |
|
204 | + //Sensei requires a reference to the main Sensei plugin file |
|
205 | + $sensei_main_plugin_file = dirname ( dirname( __FILE__ ) ) . '/woothemes-sensei.php'; |
|
206 | 206 | |
207 | - self::$_instance = new self( $sensei_main_plugin_file ); |
|
207 | + self::$_instance = new self( $sensei_main_plugin_file ); |
|
208 | 208 | |
209 | - // load the global class objects needed throughout Sensei |
|
210 | - self::$_instance->initialize_global_objects(); |
|
209 | + // load the global class objects needed throughout Sensei |
|
210 | + self::$_instance->initialize_global_objects(); |
|
211 | 211 | |
212 | - } |
|
212 | + } |
|
213 | 213 | |
214 | - return self::$_instance; |
|
214 | + return self::$_instance; |
|
215 | 215 | |
216 | - } // end instance() |
|
216 | + } // end instance() |
|
217 | 217 | |
218 | - /** |
|
219 | - * This function is linked into the activation |
|
220 | - * hook to reset flush the urls to ensure Sensei post types show up. |
|
221 | - * |
|
222 | - * @since 1.9.0 |
|
223 | - * |
|
224 | - * @param $plugin |
|
225 | - */ |
|
226 | - public static function activation_flush_rules( $plugin ){ |
|
218 | + /** |
|
219 | + * This function is linked into the activation |
|
220 | + * hook to reset flush the urls to ensure Sensei post types show up. |
|
221 | + * |
|
222 | + * @since 1.9.0 |
|
223 | + * |
|
224 | + * @param $plugin |
|
225 | + */ |
|
226 | + public static function activation_flush_rules( $plugin ){ |
|
227 | 227 | |
228 | - if( strpos( $plugin, '/woothemes-sensei.php' ) > 0 ){ |
|
228 | + if( strpos( $plugin, '/woothemes-sensei.php' ) > 0 ){ |
|
229 | 229 | |
230 | - flush_rewrite_rules(true); |
|
230 | + flush_rewrite_rules(true); |
|
231 | 231 | |
232 | - } |
|
232 | + } |
|
233 | 233 | |
234 | - } |
|
234 | + } |
|
235 | 235 | |
236 | - /** |
|
237 | - * Cloning is forbidden. |
|
238 | - * @since 1.8.0 |
|
239 | - */ |
|
240 | - public function __clone() { |
|
241 | - _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woothemes-sensei' ), '1.8' ); |
|
242 | - } |
|
236 | + /** |
|
237 | + * Cloning is forbidden. |
|
238 | + * @since 1.8.0 |
|
239 | + */ |
|
240 | + public function __clone() { |
|
241 | + _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woothemes-sensei' ), '1.8' ); |
|
242 | + } |
|
243 | 243 | |
244 | - /** |
|
245 | - * Unserializing instances of this class is forbidden. |
|
246 | - * @since 1.8.0 |
|
247 | - */ |
|
248 | - public function __wakeup() { |
|
249 | - _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woothemes-sensei' ), '1.8' ); |
|
250 | - } |
|
244 | + /** |
|
245 | + * Unserializing instances of this class is forbidden. |
|
246 | + * @since 1.8.0 |
|
247 | + */ |
|
248 | + public function __wakeup() { |
|
249 | + _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woothemes-sensei' ), '1.8' ); |
|
250 | + } |
|
251 | 251 | |
252 | - /** |
|
253 | - * Load the properties for the main Sensei object |
|
254 | - * |
|
255 | - * @since 1.9.0 |
|
256 | - */ |
|
257 | - public function initialize_global_objects(){ |
|
252 | + /** |
|
253 | + * Load the properties for the main Sensei object |
|
254 | + * |
|
255 | + * @since 1.9.0 |
|
256 | + */ |
|
257 | + public function initialize_global_objects(){ |
|
258 | 258 | |
259 | - // Setup post types. |
|
260 | - $this->post_types = new Sensei_PostTypes(); |
|
259 | + // Setup post types. |
|
260 | + $this->post_types = new Sensei_PostTypes(); |
|
261 | 261 | |
262 | - // Lad the updates class |
|
263 | - $this->updates = new Sensei_Updates( $this ); |
|
262 | + // Lad the updates class |
|
263 | + $this->updates = new Sensei_Updates( $this ); |
|
264 | 264 | |
265 | - // Load Course Results Class |
|
266 | - $this->course_results = new Sensei_Course_Results(); |
|
265 | + // Load Course Results Class |
|
266 | + $this->course_results = new Sensei_Course_Results(); |
|
267 | 267 | |
268 | - // Load the teacher role |
|
269 | - $this->teacher = new Sensei_Teacher(); |
|
268 | + // Load the teacher role |
|
269 | + $this->teacher = new Sensei_Teacher(); |
|
270 | 270 | |
271 | - // Add the Course class |
|
272 | - $this->course = $this->post_types->course; |
|
271 | + // Add the Course class |
|
272 | + $this->course = $this->post_types->course; |
|
273 | 273 | |
274 | - // Add the lesson class |
|
275 | - $this->lesson = $this->post_types->lesson; |
|
274 | + // Add the lesson class |
|
275 | + $this->lesson = $this->post_types->lesson; |
|
276 | 276 | |
277 | - // Add the question class |
|
278 | - $this->question = $this->post_types->question; |
|
277 | + // Add the question class |
|
278 | + $this->question = $this->post_types->question; |
|
279 | 279 | |
280 | - //Add the quiz class |
|
281 | - $this->quiz = $this->post_types->quiz; |
|
280 | + //Add the quiz class |
|
281 | + $this->quiz = $this->post_types->quiz; |
|
282 | 282 | |
283 | - // load the modules class after all plugsin are loaded |
|
284 | - add_action( 'plugins_loaded', array( $this, 'load_modules_class' ) ); |
|
283 | + // load the modules class after all plugsin are loaded |
|
284 | + add_action( 'plugins_loaded', array( $this, 'load_modules_class' ) ); |
|
285 | 285 | |
286 | - // Load Learner Management Functionality |
|
287 | - $this->learners = new Sensei_Learner_Management( $this->file ); |
|
286 | + // Load Learner Management Functionality |
|
287 | + $this->learners = new Sensei_Learner_Management( $this->file ); |
|
288 | 288 | |
289 | - // Differentiate between administration and frontend logic. |
|
290 | - if ( is_admin() ) { |
|
289 | + // Differentiate between administration and frontend logic. |
|
290 | + if ( is_admin() ) { |
|
291 | 291 | |
292 | - // Load Admin Welcome class |
|
293 | - new Sensei_Welcome(); |
|
292 | + // Load Admin Welcome class |
|
293 | + new Sensei_Welcome(); |
|
294 | 294 | |
295 | - // Load Admin Class |
|
296 | - $this->admin = new Sensei_Admin( $this->file ); |
|
295 | + // Load Admin Class |
|
296 | + $this->admin = new Sensei_Admin( $this->file ); |
|
297 | 297 | |
298 | - // Load Analysis Reports |
|
299 | - $this->analysis = new Sensei_Analysis( $this->file ); |
|
298 | + // Load Analysis Reports |
|
299 | + $this->analysis = new Sensei_Analysis( $this->file ); |
|
300 | 300 | |
301 | - } else { |
|
301 | + } else { |
|
302 | 302 | |
303 | - // Load Frontend Class |
|
304 | - $this->frontend = new Sensei_Frontend(); |
|
303 | + // Load Frontend Class |
|
304 | + $this->frontend = new Sensei_Frontend(); |
|
305 | 305 | |
306 | - // Load notice Class |
|
307 | - $this->notices = new Sensei_Notices(); |
|
306 | + // Load notice Class |
|
307 | + $this->notices = new Sensei_Notices(); |
|
308 | 308 | |
309 | - // Load built in themes support integration |
|
310 | - new Sensei_Theme_Integration_Loader(); |
|
309 | + // Load built in themes support integration |
|
310 | + new Sensei_Theme_Integration_Loader(); |
|
311 | 311 | |
312 | 312 | |
313 | - } |
|
313 | + } |
|
314 | 314 | |
315 | - // Load Grading Functionality |
|
316 | - $this->grading = new Sensei_Grading( $this->file ); |
|
315 | + // Load Grading Functionality |
|
316 | + $this->grading = new Sensei_Grading( $this->file ); |
|
317 | 317 | |
318 | - // Load Email Class |
|
319 | - $this->emails = new Sensei_Emails( $this->file ); |
|
318 | + // Load Email Class |
|
319 | + $this->emails = new Sensei_Emails( $this->file ); |
|
320 | 320 | |
321 | - // Load Learner Profiles Class |
|
322 | - $this->learner_profiles = new Sensei_Learner_Profiles(); |
|
321 | + // Load Learner Profiles Class |
|
322 | + $this->learner_profiles = new Sensei_Learner_Profiles(); |
|
323 | 323 | |
324 | - } |
|
324 | + } |
|
325 | 325 | |
326 | - /** |
|
327 | - * Initialize all Sensei hooks |
|
328 | - * |
|
329 | - * @since 1.9.0 |
|
330 | - */ |
|
331 | - public function load_hooks(){ |
|
326 | + /** |
|
327 | + * Initialize all Sensei hooks |
|
328 | + * |
|
329 | + * @since 1.9.0 |
|
330 | + */ |
|
331 | + public function load_hooks(){ |
|
332 | 332 | |
333 | - add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
334 | - add_action( 'after_setup_theme', array( $this, 'ensure_post_thumbnails_support' ) ); |
|
333 | + add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
334 | + add_action( 'after_setup_theme', array( $this, 'ensure_post_thumbnails_support' ) ); |
|
335 | 335 | |
336 | - // Filter comment counts |
|
337 | - add_filter( 'wp_count_comments', array( $this, 'sensei_count_comments' ), 10, 2 ); |
|
336 | + // Filter comment counts |
|
337 | + add_filter( 'wp_count_comments', array( $this, 'sensei_count_comments' ), 10, 2 ); |
|
338 | 338 | |
339 | - add_action( 'body_class', array( $this, 'body_class' ) ); |
|
339 | + add_action( 'body_class', array( $this, 'body_class' ) ); |
|
340 | 340 | |
341 | - // Check for and activate JetPack LaTeX support |
|
342 | - add_action( 'plugins_loaded', array( $this, 'jetpack_latex_support'), 200 ); // Runs after Jetpack has loaded it's modules |
|
341 | + // Check for and activate JetPack LaTeX support |
|
342 | + add_action( 'plugins_loaded', array( $this, 'jetpack_latex_support'), 200 ); // Runs after Jetpack has loaded it's modules |
|
343 | 343 | |
344 | - // check flush the rewrite rules if the option sensei_flush_rewrite_rules option is 1 |
|
345 | - add_action( 'init', array( $this, 'flush_rewrite_rules'), 101 ); |
|
344 | + // check flush the rewrite rules if the option sensei_flush_rewrite_rules option is 1 |
|
345 | + add_action( 'init', array( $this, 'flush_rewrite_rules'), 101 ); |
|
346 | 346 | |
347 | - } |
|
347 | + } |
|
348 | 348 | |
349 | - /** |
|
350 | - * Run Sensei updates. |
|
351 | - * @access public |
|
352 | - * @since 1.1.0 |
|
353 | - * @return void |
|
354 | - */ |
|
355 | - public function run_updates() { |
|
356 | - // Run updates if administrator |
|
357 | - if ( current_user_can( 'manage_options' ) || current_user_can( 'manage_sensei' ) ) { |
|
349 | + /** |
|
350 | + * Run Sensei updates. |
|
351 | + * @access public |
|
352 | + * @since 1.1.0 |
|
353 | + * @return void |
|
354 | + */ |
|
355 | + public function run_updates() { |
|
356 | + // Run updates if administrator |
|
357 | + if ( current_user_can( 'manage_options' ) || current_user_can( 'manage_sensei' ) ) { |
|
358 | 358 | |
359 | - $this->updates->update(); |
|
359 | + $this->updates->update(); |
|
360 | 360 | |
361 | - } // End If Statement |
|
362 | - } // End run_updates() |
|
361 | + } // End If Statement |
|
362 | + } // End run_updates() |
|
363 | 363 | |
364 | - /** |
|
365 | - * Register the widgets. |
|
366 | - * @access public |
|
367 | - * @since 1.0.0 |
|
368 | - * @return void |
|
369 | - */ |
|
370 | - public function register_widgets () { |
|
371 | - // Widget List (key => value is filename => widget class). |
|
372 | - $widget_list = apply_filters( 'sensei_registered_widgets_list', array( 'course-component' => 'Course_Component', |
|
373 | - 'lesson-component' => 'Lesson_Component', |
|
374 | - 'course-categories' => 'Course_Categories', |
|
375 | - 'category-courses' => 'Category_Courses' ) |
|
376 | - ); |
|
377 | - foreach ( $widget_list as $key => $value ) { |
|
378 | - if ( file_exists( $this->plugin_path . 'widgets/widget-woothemes-sensei-' . $key . '.php' ) ) { |
|
379 | - require_once( $this->plugin_path . 'widgets/widget-woothemes-sensei-' . $key . '.php' ); |
|
380 | - register_widget( 'WooThemes_Sensei_' . $value . '_Widget' ); |
|
381 | - } |
|
382 | - } // End For Loop |
|
364 | + /** |
|
365 | + * Register the widgets. |
|
366 | + * @access public |
|
367 | + * @since 1.0.0 |
|
368 | + * @return void |
|
369 | + */ |
|
370 | + public function register_widgets () { |
|
371 | + // Widget List (key => value is filename => widget class). |
|
372 | + $widget_list = apply_filters( 'sensei_registered_widgets_list', array( 'course-component' => 'Course_Component', |
|
373 | + 'lesson-component' => 'Lesson_Component', |
|
374 | + 'course-categories' => 'Course_Categories', |
|
375 | + 'category-courses' => 'Category_Courses' ) |
|
376 | + ); |
|
377 | + foreach ( $widget_list as $key => $value ) { |
|
378 | + if ( file_exists( $this->plugin_path . 'widgets/widget-woothemes-sensei-' . $key . '.php' ) ) { |
|
379 | + require_once( $this->plugin_path . 'widgets/widget-woothemes-sensei-' . $key . '.php' ); |
|
380 | + register_widget( 'WooThemes_Sensei_' . $value . '_Widget' ); |
|
381 | + } |
|
382 | + } // End For Loop |
|
383 | 383 | |
384 | - do_action( 'sensei_register_widgets' ); |
|
384 | + do_action( 'sensei_register_widgets' ); |
|
385 | 385 | |
386 | - } // End register_widgets() |
|
386 | + } // End register_widgets() |
|
387 | 387 | |
388 | - /** |
|
389 | - * Load the plugin's localisation file. |
|
390 | - * @access public |
|
391 | - * @since 1.0.0 |
|
392 | - * @return void |
|
393 | - */ |
|
394 | - public function load_localisation () { |
|
388 | + /** |
|
389 | + * Load the plugin's localisation file. |
|
390 | + * @access public |
|
391 | + * @since 1.0.0 |
|
392 | + * @return void |
|
393 | + */ |
|
394 | + public function load_localisation () { |
|
395 | 395 | |
396 | - load_plugin_textdomain( 'woothemes-sensei', false, dirname( plugin_basename( $this->file ) ) . '/lang/' ); |
|
396 | + load_plugin_textdomain( 'woothemes-sensei', false, dirname( plugin_basename( $this->file ) ) . '/lang/' ); |
|
397 | 397 | |
398 | - } // End load_localisation() |
|
398 | + } // End load_localisation() |
|
399 | 399 | |
400 | - /** |
|
401 | - * Load the plugin textdomain from the main WordPress "languages" folder. |
|
402 | - * @access public |
|
403 | - * @since 1.0.0 |
|
404 | - * @return void |
|
405 | - */ |
|
406 | - public function load_plugin_textdomain () { |
|
407 | - |
|
408 | - $domain = 'woothemes-sensei'; |
|
409 | - // The "plugin_locale" filter is also used in load_plugin_textdomain() |
|
410 | - $locale = apply_filters( 'plugin_locale', get_locale(), $domain ); |
|
411 | - load_textdomain( $domain, WP_LANG_DIR . '/' . $domain . '/' . $domain . '-' . $locale . '.mo' ); |
|
412 | - load_plugin_textdomain( $domain, FALSE, dirname( plugin_basename( $this->file ) ) . '/lang/' ); |
|
413 | - |
|
414 | - } // End load_plugin_textdomain() |
|
415 | - |
|
416 | - /** |
|
417 | - * Run on activation. |
|
418 | - * @access public |
|
419 | - * @since 1.0.0 |
|
420 | - * @return void |
|
421 | - */ |
|
422 | - public function activation () { |
|
423 | - |
|
424 | - $this->register_plugin_version(); |
|
425 | - |
|
426 | - } // End activation() |
|
427 | - |
|
428 | - |
|
429 | - /** |
|
430 | - * Register activation hooks. |
|
431 | - * @access public |
|
432 | - * @since 1.0.0 |
|
433 | - * @return void |
|
434 | - */ |
|
435 | - public function install () { |
|
436 | - |
|
437 | - register_activation_hook( $this->file, array( $this, 'activate_sensei' ) ); |
|
438 | - register_activation_hook( $this->file, 'flush_rewrite_rules' ); |
|
439 | - |
|
440 | - } // End install() |
|
441 | - |
|
442 | - |
|
443 | - /** |
|
444 | - * Run on activation of the plugin. |
|
445 | - * @access public |
|
446 | - * @since 1.0.0 |
|
447 | - * @return void |
|
448 | - */ |
|
449 | - public function activate_sensei () { |
|
450 | - |
|
451 | - update_option( 'skip_install_sensei_pages', 0 ); |
|
452 | - update_option( 'sensei_installed', 1 ); |
|
453 | - |
|
454 | - } // End activate_sensei() |
|
455 | - |
|
456 | - /** |
|
457 | - * Register the plugin's version. |
|
458 | - * @access public |
|
459 | - * @since 1.0.0 |
|
460 | - * @return void |
|
461 | - */ |
|
462 | - private function register_plugin_version () { |
|
463 | - if ( $this->version != '' ) { |
|
464 | - |
|
465 | - update_option( 'woothemes-sensei-version', $this->version ); |
|
466 | - |
|
467 | - } |
|
468 | - } // End register_plugin_version() |
|
469 | - |
|
470 | - /** |
|
471 | - * Ensure that "post-thumbnails" support is available for those themes that don't register it. |
|
472 | - * @access public |
|
473 | - * @since 1.0.1 |
|
474 | - * @return void |
|
475 | - */ |
|
476 | - public function ensure_post_thumbnails_support () { |
|
477 | - |
|
478 | - if ( ! current_theme_supports( 'post-thumbnails' ) ) { add_theme_support( 'post-thumbnails' ); } |
|
479 | - |
|
480 | - } // End ensure_post_thumbnails_support() |
|
481 | - |
|
482 | - /** |
|
483 | - * template_loader function. |
|
484 | - * |
|
485 | - * @access public |
|
486 | - * @param mixed $template |
|
487 | - * @return void |
|
488 | - * @deprecated |
|
489 | - */ |
|
490 | - public function template_loader ( $template = '' ) { |
|
491 | - |
|
492 | - _deprecated_function( 'Sensei()->template_loader', '1.9.0', 'Use Sensei_Templates::template_loader( $template ) instead' ); |
|
493 | - Sensei_Templates::template_loader( $template ); |
|
494 | - |
|
495 | - } // End template_loader() |
|
496 | - |
|
497 | - /** |
|
498 | - * Determine the relative path to the plugin's directory. |
|
499 | - * @access public |
|
500 | - * @since 1.0.0 |
|
501 | - * @return string $sensei_plugin_path |
|
502 | - */ |
|
503 | - public function plugin_path () { |
|
504 | - |
|
505 | - if ( $this->plugin_path ) { |
|
506 | - |
|
507 | - $sensei_plugin_path = $this->plugin_path; |
|
508 | - |
|
509 | - }else{ |
|
510 | - |
|
511 | - $sensei_plugin_path = plugin_dir_path( __FILE__ ); |
|
512 | - |
|
513 | - } |
|
514 | - |
|
515 | - return $sensei_plugin_path; |
|
516 | - |
|
517 | - } // End plugin_path() |
|
518 | - |
|
519 | - /** |
|
520 | - * Retrieve the ID of a specified page setting. |
|
521 | - * @access public |
|
522 | - * @since 1.0.0 |
|
523 | - * @param string $page |
|
524 | - * @return int |
|
525 | - */ |
|
526 | - public function get_page_id ( $page ) { |
|
527 | - $page = apply_filters( 'sensei_get_' . esc_attr( $page ) . '_page_id', get_option( 'sensei_' . esc_attr( $page ) . '_page_id' ) ); |
|
528 | - return ( $page ) ? $page : -1; |
|
529 | - } // End get_page_id() |
|
530 | - |
|
531 | - /** |
|
532 | - * check_user_permissions function. |
|
533 | - * |
|
534 | - * @access public |
|
535 | - * @param string $page (default: '') |
|
536 | - * |
|
537 | - * @return bool |
|
538 | - */ |
|
539 | - public function check_user_permissions ( $page = '' ) { |
|
540 | - |
|
541 | - global $current_user, $post; |
|
542 | - |
|
543 | - // if user is not logged in skipped for single lesson |
|
544 | - if ( empty( $current_user->caps ) && Sensei()->settings->get('access_permission') |
|
545 | - && 'lesson-single' != $page ){ |
|
546 | - |
|
547 | - $this->permissions_message['title'] = __('Restricted Access', 'woothemes-sensei' ); |
|
548 | - $this->permissions_message['message'] = sprintf( __('You must be logged in to view this %s'), get_post_type() ); |
|
549 | - |
|
550 | - return false; |
|
551 | - } |
|
552 | - |
|
553 | - $user_allowed = false; |
|
554 | - |
|
555 | - switch ( $page ) { |
|
556 | - case 'course-single': |
|
557 | - // check for prerequisite course or lesson, |
|
558 | - $course_prerequisite_id = (int) get_post_meta( $post->ID, '_course_prerequisite', true); |
|
559 | - $update_course = Sensei_WC::course_update( $post->ID ); |
|
560 | - // Count completed lessons |
|
561 | - if ( 0 < absint( $course_prerequisite_id ) ) { |
|
562 | - |
|
563 | - $prerequisite_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, $current_user->ID ); |
|
564 | - |
|
565 | - } |
|
566 | - else { |
|
567 | - $prerequisite_complete = true; |
|
568 | - } // End If Statement |
|
569 | - // Handles restrictions |
|
570 | - if ( !$prerequisite_complete && 0 < absint( $course_prerequisite_id ) ) { |
|
571 | - $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
572 | - $course_link = '<a href="' . esc_url( get_permalink( $course_prerequisite_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
573 | - $this->permissions_message['message'] = sprintf( __('Please complete the previous %1$s before taking this course.', 'woothemes-sensei' ), $course_link ); |
|
574 | - } else { |
|
575 | - $user_allowed = true; |
|
576 | - } // End If Statement |
|
577 | - break; |
|
578 | - case 'lesson-single': |
|
579 | - // Check for WC purchase |
|
580 | - $lesson_course_id = get_post_meta( $post->ID, '_lesson_course',true ); |
|
581 | - |
|
582 | - $update_course = Sensei_WC::course_update( $lesson_course_id ); |
|
583 | - $is_preview = Sensei_Utils::is_preview_lesson( $post->ID ); |
|
584 | - |
|
585 | - if ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) { |
|
586 | - $user_allowed = true; |
|
587 | - } elseif( $this->access_settings() && false == $is_preview ) { |
|
588 | - |
|
589 | - $user_allowed = true; |
|
590 | - |
|
591 | - } else { |
|
592 | - $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
593 | - $course_link = '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
594 | - $wc_post_id = get_post_meta( $lesson_course_id, '_course_woocommerce_product',true ); |
|
595 | - if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) { |
|
596 | - if ( $is_preview ) { |
|
597 | - $this->permissions_message['message'] = sprintf( __('This is a preview lesson. Please purchase the %1$s to access all lessons.', 'woothemes-sensei' ), $course_link ); |
|
598 | - } else { |
|
599 | - $this->permissions_message['message'] = sprintf( __('Please purchase the %1$s before starting this Lesson.', 'woothemes-sensei' ), $course_link ); |
|
600 | - } |
|
601 | - } else { |
|
602 | - if ( $is_preview ) { |
|
603 | - $this->permissions_message['message'] = sprintf( __('This is a preview lesson. Please sign up for the %1$s to access all lessons.', 'woothemes-sensei' ), $course_link ); |
|
604 | - } else { |
|
605 | - /** This filter is documented in class-woothemes-sensei-frontend.php */ |
|
606 | - $this->permissions_message['message'] = sprintf( __( 'Please sign up for the %1$s before starting the lesson.', 'woothemes-sensei' ), $course_link ); |
|
607 | - } |
|
608 | - } // End If Statement |
|
609 | - } // End If Statement |
|
610 | - break; |
|
611 | - case 'quiz-single': |
|
612 | - $lesson_id = get_post_meta( $post->ID, '_quiz_lesson',true ); |
|
613 | - $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course',true ); |
|
614 | - |
|
615 | - $update_course = Sensei_WC::course_update( $lesson_course_id ); |
|
616 | - if ( ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) || sensei_all_access() ) { |
|
617 | - |
|
618 | - // Check for prerequisite lesson for this quiz |
|
619 | - $lesson_prerequisite_id = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true); |
|
620 | - $user_lesson_prerequisite_complete = Sensei_Utils::user_completed_lesson( $lesson_prerequisite_id, $current_user->ID); |
|
621 | - |
|
622 | - // Handle restrictions |
|
623 | - if( sensei_all_access() ) { |
|
624 | - |
|
625 | - $user_allowed = true; |
|
626 | - |
|
627 | - } else { |
|
628 | - |
|
629 | - if ( 0 < absint( $lesson_prerequisite_id ) && ( !$user_lesson_prerequisite_complete ) ) { |
|
630 | - |
|
631 | - $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
632 | - $lesson_link = '<a href="' . esc_url( get_permalink( $lesson_prerequisite_id ) ) . '">' . __( 'lesson', 'woothemes-sensei' ) . '</a>'; |
|
633 | - $this->permissions_message['message'] = sprintf( __('Please complete the previous %1$s before taking this Quiz.', 'woothemes-sensei' ), $lesson_link ); |
|
634 | - |
|
635 | - } else { |
|
636 | - |
|
637 | - $user_allowed = true; |
|
638 | - |
|
639 | - } // End If Statement |
|
640 | - } // End If Statement |
|
641 | - } elseif( $this->access_settings() ) { |
|
642 | - // Check if the user has started the course |
|
643 | - |
|
644 | - if ( is_user_logged_in() && ! Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) && ( isset( $this->settings->settings['access_permission'] ) && ( true == $this->settings->settings['access_permission'] ) ) ) { |
|
645 | - |
|
646 | - $user_allowed = false; |
|
647 | - $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
648 | - $course_link = '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
649 | - $wc_post_id = get_post_meta( $lesson_course_id, '_course_woocommerce_product',true ); |
|
650 | - if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) { |
|
651 | - $this->permissions_message['message'] = sprintf( __('Please purchase the %1$s before starting this Quiz.', 'woothemes-sensei' ), $course_link ); |
|
652 | - } else { |
|
653 | - $this->permissions_message['message'] = sprintf( __('Please sign up for the %1$s before starting this Quiz.', 'woothemes-sensei' ), $course_link ); |
|
654 | - } // End If Statement |
|
655 | - } else { |
|
656 | - $user_allowed = true; |
|
657 | - } // End If Statement |
|
658 | - } else { |
|
659 | - $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
660 | - $course_link = '<a href="' . esc_url( get_permalink( get_post_meta( get_post_meta( $post->ID, '_quiz_lesson', true ), '_lesson_course', true ) ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
661 | - $this->permissions_message['message'] = sprintf( __('Please sign up for the %1$s before taking this Quiz.', 'woothemes-sensei' ), $course_link ); |
|
662 | - } // End If Statement |
|
663 | - break; |
|
664 | - default: |
|
665 | - $user_allowed = true; |
|
666 | - break; |
|
667 | - |
|
668 | - } // End Switch Statement |
|
669 | - |
|
670 | - /** |
|
671 | - * filter the permissions message shown on sensei post types. |
|
672 | - * |
|
673 | - * @since 1.8.7 |
|
674 | - * |
|
675 | - * @param array $permissions_message{ |
|
676 | - * |
|
677 | - * @type string $title |
|
678 | - * @type string $message |
|
679 | - * |
|
680 | - * } |
|
681 | - * @param string $post_id |
|
682 | - */ |
|
683 | - $this->permissions_message = apply_filters( 'sensei_permissions_message', $this->permissions_message, $post->ID ); |
|
684 | - |
|
685 | - |
|
686 | - if( sensei_all_access() || Sensei_Utils::is_preview_lesson( $post->ID ) ) { |
|
687 | - $user_allowed = true; |
|
688 | - } |
|
689 | - |
|
690 | - /** |
|
691 | - * Filter the permissions check final result. Which determines if the user has |
|
692 | - * access to the given page. |
|
693 | - * |
|
694 | - * @since 1.0 |
|
695 | - * |
|
696 | - * @param boolean $user_allowed |
|
697 | - * @param integer $user_id |
|
698 | - * |
|
699 | - */ |
|
700 | - return apply_filters( 'sensei_access_permissions', $user_allowed, $current_user->ID ); |
|
701 | - |
|
702 | - } // End get_placeholder_image() |
|
703 | - |
|
704 | - |
|
705 | - /** |
|
706 | - * Check if visitors have access permission. If the "access_permission" setting is active, do a log in check. |
|
707 | - * @since 1.0.0 |
|
708 | - * @access public |
|
709 | - * @return bool |
|
710 | - */ |
|
711 | - public function access_settings () { |
|
712 | - |
|
713 | - if( sensei_all_access() ) return true; |
|
714 | - |
|
715 | - if ( isset( $this->settings->settings['access_permission'] ) && ( true == $this->settings->settings['access_permission'] ) ) { |
|
716 | - if ( is_user_logged_in() ) { |
|
717 | - return true; |
|
718 | - } else { |
|
719 | - return false; |
|
720 | - } // End If Statement |
|
721 | - } else { |
|
722 | - return true; |
|
723 | - } // End If Statement |
|
724 | - } // End access_settings() |
|
725 | - |
|
726 | - /** |
|
727 | - * load_class loads in class files |
|
728 | - * @since 1.2.0 |
|
729 | - * @access public |
|
730 | - * @return void |
|
731 | - */ |
|
732 | - public function load_class ( $class_name = '' ) { |
|
733 | - if ( '' != $class_name && '' != $this->token ) { |
|
734 | - require_once( 'class-' . esc_attr( $this->token ) . '-' . esc_attr( $class_name ) . '.php' ); |
|
735 | - } // End If Statement |
|
736 | - } // End load_class() |
|
737 | - |
|
738 | - /** |
|
739 | - * Filtering wp_count_comments to ensure that Sensei comments are ignored |
|
740 | - * @since 1.4.0 |
|
741 | - * @access public |
|
742 | - * @param array $comments |
|
743 | - * @param integer $post_id |
|
744 | - * @return array |
|
745 | - */ |
|
746 | - public function sensei_count_comments( $comments, $post_id ) { |
|
747 | - global $wpdb; |
|
748 | - |
|
749 | - $post_id = (int) $post_id; |
|
750 | - |
|
751 | - $count = wp_cache_get("comments-{$post_id}", 'counts'); |
|
752 | - |
|
753 | - if ( false !== $count ) { |
|
754 | - return $count; |
|
755 | - } |
|
756 | - |
|
757 | - $statuses = array( '' ); // Default to the WP normal comments |
|
758 | - $stati = $wpdb->get_results( "SELECT comment_type FROM {$wpdb->comments} GROUP BY comment_type", ARRAY_A ); |
|
759 | - foreach ( (array) $stati AS $status ) { |
|
760 | - if ( 'sensei_' != substr($status['comment_type'], 0, 7 ) ) { |
|
761 | - $statuses[] = $status['comment_type']; |
|
762 | - } |
|
763 | - } |
|
764 | - $where = "WHERE comment_type IN ('" . join("', '", array_unique( $statuses ) ) . "')"; |
|
765 | - |
|
766 | - if ( $post_id > 0 ) |
|
767 | - $where .= $wpdb->prepare( " AND comment_post_ID = %d", $post_id ); |
|
768 | - |
|
769 | - $count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A ); |
|
770 | - |
|
771 | - $total = 0; |
|
772 | - $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash', 'post-trashed' => 'post-trashed'); |
|
773 | - foreach ( (array) $count as $row ) { |
|
774 | - // Don't count post-trashed toward totals |
|
775 | - if ( 'post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'] ) |
|
776 | - $total += $row['num_comments']; |
|
777 | - if ( isset( $approved[$row['comment_approved']] ) ) |
|
778 | - $stats[$approved[$row['comment_approved']]] = $row['num_comments']; |
|
779 | - } |
|
780 | - |
|
781 | - $stats['total_comments'] = $total; |
|
782 | - foreach ( $approved as $key ) { |
|
783 | - if ( empty($stats[$key]) ) |
|
784 | - $stats[$key] = 0; |
|
785 | - } |
|
786 | - |
|
787 | - $stats = (object) $stats; |
|
788 | - wp_cache_set("comments-{$post_id}", $stats, 'counts'); |
|
789 | - |
|
790 | - return $stats; |
|
791 | - } |
|
792 | - |
|
793 | - /** |
|
794 | - * Init images. |
|
795 | - * |
|
796 | - * @since 1.4.5 |
|
797 | - * @access public |
|
798 | - * @return void |
|
799 | - */ |
|
800 | - public function init_image_sizes() { |
|
801 | - $course_archive_thumbnail = $this->get_image_size( 'course_archive_image' ); |
|
802 | - $course_single_thumbnail = $this->get_image_size( 'course_single_image' ); |
|
803 | - $lesson_archive_thumbnail = $this->get_image_size( 'lesson_archive_image' ); |
|
804 | - $lesson_single_thumbnail = $this->get_image_size( 'lesson_single_image' ); |
|
805 | - |
|
806 | - add_image_size( 'course_archive_thumbnail', $course_archive_thumbnail['width'], $course_archive_thumbnail['height'], $course_archive_thumbnail['crop'] ); |
|
807 | - add_image_size( 'course_single_thumbnail', $course_single_thumbnail['width'], $course_single_thumbnail['height'], $course_single_thumbnail['crop'] ); |
|
808 | - add_image_size( 'lesson_archive_thumbnail', $lesson_archive_thumbnail['width'], $lesson_archive_thumbnail['height'], $lesson_archive_thumbnail['crop'] ); |
|
809 | - add_image_size( 'lesson_single_thumbnail', $lesson_single_thumbnail['width'], $lesson_single_thumbnail['height'], $lesson_single_thumbnail['crop'] ); |
|
810 | - } |
|
811 | - |
|
812 | - /** |
|
813 | - * Get an image size. |
|
814 | - * |
|
815 | - * Variable is filtered by sensei_get_image_size_{image_size} |
|
816 | - * |
|
817 | - * @since 1.4.5 |
|
818 | - * @access public |
|
819 | - * @param mixed $image_size |
|
820 | - * @return string |
|
821 | - */ |
|
822 | - public function get_image_size( $image_size ) { |
|
823 | - |
|
824 | - // Only return sizes we define in settings |
|
825 | - if ( ! in_array( $image_size, array( 'course_archive_image', 'course_single_image', 'lesson_archive_image', 'lesson_single_image' ) ) ) |
|
826 | - return apply_filters( 'sensei_get_image_size_' . $image_size, '' ); |
|
827 | - |
|
828 | - if( ! isset( $this->settings->settings[ $image_size . '_width' ] ) ) { |
|
829 | - $this->settings->settings[ $image_size . '_width' ] = false; |
|
830 | - } |
|
831 | - if( ! isset( $this->settings->settings[ $image_size . '_height' ] ) ) { |
|
832 | - $this->settings->settings[ $image_size . '_height' ] = false; |
|
833 | - } |
|
834 | - if( ! isset( $this->settings->settings[ $image_size . '_hard_crop' ] ) ) { |
|
835 | - $this->settings->settings[ $image_size . '_hard_crop' ] = false; |
|
836 | - } |
|
837 | - |
|
838 | - $size = array_filter( array( |
|
839 | - 'width' => $this->settings->settings[ $image_size . '_width' ], |
|
840 | - 'height' => $this->settings->settings[ $image_size . '_height' ], |
|
841 | - 'crop' => $this->settings->settings[ $image_size . '_hard_crop' ] |
|
842 | - ) ); |
|
843 | - |
|
844 | - $size['width'] = isset( $size['width'] ) ? $size['width'] : '100'; |
|
845 | - $size['height'] = isset( $size['height'] ) ? $size['height'] : '100'; |
|
846 | - $size['crop'] = isset( $size['crop'] ) ? $size['crop'] : 0; |
|
847 | - |
|
848 | - return apply_filters( 'sensei_get_image_size_' . $image_size, $size ); |
|
849 | - } |
|
850 | - |
|
851 | - public function body_class( $classes ) { |
|
852 | - if( is_sensei() ) { |
|
853 | - $classes[] = 'sensei'; |
|
854 | - } |
|
855 | - return $classes; |
|
856 | - } |
|
857 | - |
|
858 | - /** |
|
859 | - * Checks that the Jetpack Beautiful Maths module has been activated to support LaTeX within question titles and answers |
|
860 | - * |
|
861 | - * @return null |
|
862 | - * @since 1.7.0 |
|
863 | - */ |
|
864 | - public function jetpack_latex_support() { |
|
865 | - if ( function_exists( 'latex_markup') ) { |
|
866 | - add_filter( 'sensei_question_title', 'latex_markup' ); |
|
867 | - add_filter( 'sensei_answer_text', 'latex_markup' ); |
|
868 | - } |
|
869 | - } |
|
870 | - |
|
871 | - /** |
|
872 | - * Load the module functionality. |
|
873 | - * |
|
874 | - * This function is hooked into plugins_loaded to avoid conflicts with |
|
875 | - * the retired modules extension. |
|
876 | - * |
|
877 | - * @since 1.8.0 |
|
878 | - */ |
|
879 | - public function load_modules_class(){ |
|
880 | - global $sensei_modules; |
|
881 | - |
|
882 | - if( !class_exists( 'Sensei_Modules' ) |
|
883 | - && 'Sensei_Modules' != get_class( $sensei_modules ) ) { |
|
884 | - |
|
885 | - //Load the modules class |
|
886 | - require_once( 'class-sensei-modules.php'); |
|
887 | - Sensei()->modules = new Sensei_Core_Modules( $this->file ); |
|
888 | - |
|
889 | - }else{ |
|
890 | - // fallback for people still using the modules extension. |
|
891 | - global $sensei_modules; |
|
892 | - Sensei()->modules = $sensei_modules; |
|
893 | - add_action( 'admin_notices', array( $this, 'disable_sensei_modules_extension'), 30 ); |
|
894 | - } |
|
895 | - } |
|
896 | - |
|
897 | - /** |
|
898 | - * Tell the user to that the modules extension is no longer needed. |
|
899 | - * |
|
900 | - * @since 1.8.0 |
|
901 | - */ |
|
902 | - public function disable_sensei_modules_extension(){ ?> |
|
400 | + /** |
|
401 | + * Load the plugin textdomain from the main WordPress "languages" folder. |
|
402 | + * @access public |
|
403 | + * @since 1.0.0 |
|
404 | + * @return void |
|
405 | + */ |
|
406 | + public function load_plugin_textdomain () { |
|
407 | + |
|
408 | + $domain = 'woothemes-sensei'; |
|
409 | + // The "plugin_locale" filter is also used in load_plugin_textdomain() |
|
410 | + $locale = apply_filters( 'plugin_locale', get_locale(), $domain ); |
|
411 | + load_textdomain( $domain, WP_LANG_DIR . '/' . $domain . '/' . $domain . '-' . $locale . '.mo' ); |
|
412 | + load_plugin_textdomain( $domain, FALSE, dirname( plugin_basename( $this->file ) ) . '/lang/' ); |
|
413 | + |
|
414 | + } // End load_plugin_textdomain() |
|
415 | + |
|
416 | + /** |
|
417 | + * Run on activation. |
|
418 | + * @access public |
|
419 | + * @since 1.0.0 |
|
420 | + * @return void |
|
421 | + */ |
|
422 | + public function activation () { |
|
423 | + |
|
424 | + $this->register_plugin_version(); |
|
425 | + |
|
426 | + } // End activation() |
|
427 | + |
|
428 | + |
|
429 | + /** |
|
430 | + * Register activation hooks. |
|
431 | + * @access public |
|
432 | + * @since 1.0.0 |
|
433 | + * @return void |
|
434 | + */ |
|
435 | + public function install () { |
|
436 | + |
|
437 | + register_activation_hook( $this->file, array( $this, 'activate_sensei' ) ); |
|
438 | + register_activation_hook( $this->file, 'flush_rewrite_rules' ); |
|
439 | + |
|
440 | + } // End install() |
|
441 | + |
|
442 | + |
|
443 | + /** |
|
444 | + * Run on activation of the plugin. |
|
445 | + * @access public |
|
446 | + * @since 1.0.0 |
|
447 | + * @return void |
|
448 | + */ |
|
449 | + public function activate_sensei () { |
|
450 | + |
|
451 | + update_option( 'skip_install_sensei_pages', 0 ); |
|
452 | + update_option( 'sensei_installed', 1 ); |
|
453 | + |
|
454 | + } // End activate_sensei() |
|
455 | + |
|
456 | + /** |
|
457 | + * Register the plugin's version. |
|
458 | + * @access public |
|
459 | + * @since 1.0.0 |
|
460 | + * @return void |
|
461 | + */ |
|
462 | + private function register_plugin_version () { |
|
463 | + if ( $this->version != '' ) { |
|
464 | + |
|
465 | + update_option( 'woothemes-sensei-version', $this->version ); |
|
466 | + |
|
467 | + } |
|
468 | + } // End register_plugin_version() |
|
469 | + |
|
470 | + /** |
|
471 | + * Ensure that "post-thumbnails" support is available for those themes that don't register it. |
|
472 | + * @access public |
|
473 | + * @since 1.0.1 |
|
474 | + * @return void |
|
475 | + */ |
|
476 | + public function ensure_post_thumbnails_support () { |
|
477 | + |
|
478 | + if ( ! current_theme_supports( 'post-thumbnails' ) ) { add_theme_support( 'post-thumbnails' ); } |
|
479 | + |
|
480 | + } // End ensure_post_thumbnails_support() |
|
481 | + |
|
482 | + /** |
|
483 | + * template_loader function. |
|
484 | + * |
|
485 | + * @access public |
|
486 | + * @param mixed $template |
|
487 | + * @return void |
|
488 | + * @deprecated |
|
489 | + */ |
|
490 | + public function template_loader ( $template = '' ) { |
|
491 | + |
|
492 | + _deprecated_function( 'Sensei()->template_loader', '1.9.0', 'Use Sensei_Templates::template_loader( $template ) instead' ); |
|
493 | + Sensei_Templates::template_loader( $template ); |
|
494 | + |
|
495 | + } // End template_loader() |
|
496 | + |
|
497 | + /** |
|
498 | + * Determine the relative path to the plugin's directory. |
|
499 | + * @access public |
|
500 | + * @since 1.0.0 |
|
501 | + * @return string $sensei_plugin_path |
|
502 | + */ |
|
503 | + public function plugin_path () { |
|
504 | + |
|
505 | + if ( $this->plugin_path ) { |
|
506 | + |
|
507 | + $sensei_plugin_path = $this->plugin_path; |
|
508 | + |
|
509 | + }else{ |
|
510 | + |
|
511 | + $sensei_plugin_path = plugin_dir_path( __FILE__ ); |
|
512 | + |
|
513 | + } |
|
514 | + |
|
515 | + return $sensei_plugin_path; |
|
516 | + |
|
517 | + } // End plugin_path() |
|
518 | + |
|
519 | + /** |
|
520 | + * Retrieve the ID of a specified page setting. |
|
521 | + * @access public |
|
522 | + * @since 1.0.0 |
|
523 | + * @param string $page |
|
524 | + * @return int |
|
525 | + */ |
|
526 | + public function get_page_id ( $page ) { |
|
527 | + $page = apply_filters( 'sensei_get_' . esc_attr( $page ) . '_page_id', get_option( 'sensei_' . esc_attr( $page ) . '_page_id' ) ); |
|
528 | + return ( $page ) ? $page : -1; |
|
529 | + } // End get_page_id() |
|
530 | + |
|
531 | + /** |
|
532 | + * check_user_permissions function. |
|
533 | + * |
|
534 | + * @access public |
|
535 | + * @param string $page (default: '') |
|
536 | + * |
|
537 | + * @return bool |
|
538 | + */ |
|
539 | + public function check_user_permissions ( $page = '' ) { |
|
540 | + |
|
541 | + global $current_user, $post; |
|
542 | + |
|
543 | + // if user is not logged in skipped for single lesson |
|
544 | + if ( empty( $current_user->caps ) && Sensei()->settings->get('access_permission') |
|
545 | + && 'lesson-single' != $page ){ |
|
546 | + |
|
547 | + $this->permissions_message['title'] = __('Restricted Access', 'woothemes-sensei' ); |
|
548 | + $this->permissions_message['message'] = sprintf( __('You must be logged in to view this %s'), get_post_type() ); |
|
549 | + |
|
550 | + return false; |
|
551 | + } |
|
552 | + |
|
553 | + $user_allowed = false; |
|
554 | + |
|
555 | + switch ( $page ) { |
|
556 | + case 'course-single': |
|
557 | + // check for prerequisite course or lesson, |
|
558 | + $course_prerequisite_id = (int) get_post_meta( $post->ID, '_course_prerequisite', true); |
|
559 | + $update_course = Sensei_WC::course_update( $post->ID ); |
|
560 | + // Count completed lessons |
|
561 | + if ( 0 < absint( $course_prerequisite_id ) ) { |
|
562 | + |
|
563 | + $prerequisite_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, $current_user->ID ); |
|
564 | + |
|
565 | + } |
|
566 | + else { |
|
567 | + $prerequisite_complete = true; |
|
568 | + } // End If Statement |
|
569 | + // Handles restrictions |
|
570 | + if ( !$prerequisite_complete && 0 < absint( $course_prerequisite_id ) ) { |
|
571 | + $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
572 | + $course_link = '<a href="' . esc_url( get_permalink( $course_prerequisite_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
573 | + $this->permissions_message['message'] = sprintf( __('Please complete the previous %1$s before taking this course.', 'woothemes-sensei' ), $course_link ); |
|
574 | + } else { |
|
575 | + $user_allowed = true; |
|
576 | + } // End If Statement |
|
577 | + break; |
|
578 | + case 'lesson-single': |
|
579 | + // Check for WC purchase |
|
580 | + $lesson_course_id = get_post_meta( $post->ID, '_lesson_course',true ); |
|
581 | + |
|
582 | + $update_course = Sensei_WC::course_update( $lesson_course_id ); |
|
583 | + $is_preview = Sensei_Utils::is_preview_lesson( $post->ID ); |
|
584 | + |
|
585 | + if ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) { |
|
586 | + $user_allowed = true; |
|
587 | + } elseif( $this->access_settings() && false == $is_preview ) { |
|
588 | + |
|
589 | + $user_allowed = true; |
|
590 | + |
|
591 | + } else { |
|
592 | + $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
593 | + $course_link = '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
594 | + $wc_post_id = get_post_meta( $lesson_course_id, '_course_woocommerce_product',true ); |
|
595 | + if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) { |
|
596 | + if ( $is_preview ) { |
|
597 | + $this->permissions_message['message'] = sprintf( __('This is a preview lesson. Please purchase the %1$s to access all lessons.', 'woothemes-sensei' ), $course_link ); |
|
598 | + } else { |
|
599 | + $this->permissions_message['message'] = sprintf( __('Please purchase the %1$s before starting this Lesson.', 'woothemes-sensei' ), $course_link ); |
|
600 | + } |
|
601 | + } else { |
|
602 | + if ( $is_preview ) { |
|
603 | + $this->permissions_message['message'] = sprintf( __('This is a preview lesson. Please sign up for the %1$s to access all lessons.', 'woothemes-sensei' ), $course_link ); |
|
604 | + } else { |
|
605 | + /** This filter is documented in class-woothemes-sensei-frontend.php */ |
|
606 | + $this->permissions_message['message'] = sprintf( __( 'Please sign up for the %1$s before starting the lesson.', 'woothemes-sensei' ), $course_link ); |
|
607 | + } |
|
608 | + } // End If Statement |
|
609 | + } // End If Statement |
|
610 | + break; |
|
611 | + case 'quiz-single': |
|
612 | + $lesson_id = get_post_meta( $post->ID, '_quiz_lesson',true ); |
|
613 | + $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course',true ); |
|
614 | + |
|
615 | + $update_course = Sensei_WC::course_update( $lesson_course_id ); |
|
616 | + if ( ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) || sensei_all_access() ) { |
|
617 | + |
|
618 | + // Check for prerequisite lesson for this quiz |
|
619 | + $lesson_prerequisite_id = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true); |
|
620 | + $user_lesson_prerequisite_complete = Sensei_Utils::user_completed_lesson( $lesson_prerequisite_id, $current_user->ID); |
|
621 | + |
|
622 | + // Handle restrictions |
|
623 | + if( sensei_all_access() ) { |
|
624 | + |
|
625 | + $user_allowed = true; |
|
626 | + |
|
627 | + } else { |
|
628 | + |
|
629 | + if ( 0 < absint( $lesson_prerequisite_id ) && ( !$user_lesson_prerequisite_complete ) ) { |
|
630 | + |
|
631 | + $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
632 | + $lesson_link = '<a href="' . esc_url( get_permalink( $lesson_prerequisite_id ) ) . '">' . __( 'lesson', 'woothemes-sensei' ) . '</a>'; |
|
633 | + $this->permissions_message['message'] = sprintf( __('Please complete the previous %1$s before taking this Quiz.', 'woothemes-sensei' ), $lesson_link ); |
|
634 | + |
|
635 | + } else { |
|
636 | + |
|
637 | + $user_allowed = true; |
|
638 | + |
|
639 | + } // End If Statement |
|
640 | + } // End If Statement |
|
641 | + } elseif( $this->access_settings() ) { |
|
642 | + // Check if the user has started the course |
|
643 | + |
|
644 | + if ( is_user_logged_in() && ! Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) && ( isset( $this->settings->settings['access_permission'] ) && ( true == $this->settings->settings['access_permission'] ) ) ) { |
|
645 | + |
|
646 | + $user_allowed = false; |
|
647 | + $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
648 | + $course_link = '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
649 | + $wc_post_id = get_post_meta( $lesson_course_id, '_course_woocommerce_product',true ); |
|
650 | + if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) { |
|
651 | + $this->permissions_message['message'] = sprintf( __('Please purchase the %1$s before starting this Quiz.', 'woothemes-sensei' ), $course_link ); |
|
652 | + } else { |
|
653 | + $this->permissions_message['message'] = sprintf( __('Please sign up for the %1$s before starting this Quiz.', 'woothemes-sensei' ), $course_link ); |
|
654 | + } // End If Statement |
|
655 | + } else { |
|
656 | + $user_allowed = true; |
|
657 | + } // End If Statement |
|
658 | + } else { |
|
659 | + $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
660 | + $course_link = '<a href="' . esc_url( get_permalink( get_post_meta( get_post_meta( $post->ID, '_quiz_lesson', true ), '_lesson_course', true ) ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
661 | + $this->permissions_message['message'] = sprintf( __('Please sign up for the %1$s before taking this Quiz.', 'woothemes-sensei' ), $course_link ); |
|
662 | + } // End If Statement |
|
663 | + break; |
|
664 | + default: |
|
665 | + $user_allowed = true; |
|
666 | + break; |
|
667 | + |
|
668 | + } // End Switch Statement |
|
669 | + |
|
670 | + /** |
|
671 | + * filter the permissions message shown on sensei post types. |
|
672 | + * |
|
673 | + * @since 1.8.7 |
|
674 | + * |
|
675 | + * @param array $permissions_message{ |
|
676 | + * |
|
677 | + * @type string $title |
|
678 | + * @type string $message |
|
679 | + * |
|
680 | + * } |
|
681 | + * @param string $post_id |
|
682 | + */ |
|
683 | + $this->permissions_message = apply_filters( 'sensei_permissions_message', $this->permissions_message, $post->ID ); |
|
684 | + |
|
685 | + |
|
686 | + if( sensei_all_access() || Sensei_Utils::is_preview_lesson( $post->ID ) ) { |
|
687 | + $user_allowed = true; |
|
688 | + } |
|
689 | + |
|
690 | + /** |
|
691 | + * Filter the permissions check final result. Which determines if the user has |
|
692 | + * access to the given page. |
|
693 | + * |
|
694 | + * @since 1.0 |
|
695 | + * |
|
696 | + * @param boolean $user_allowed |
|
697 | + * @param integer $user_id |
|
698 | + * |
|
699 | + */ |
|
700 | + return apply_filters( 'sensei_access_permissions', $user_allowed, $current_user->ID ); |
|
701 | + |
|
702 | + } // End get_placeholder_image() |
|
703 | + |
|
704 | + |
|
705 | + /** |
|
706 | + * Check if visitors have access permission. If the "access_permission" setting is active, do a log in check. |
|
707 | + * @since 1.0.0 |
|
708 | + * @access public |
|
709 | + * @return bool |
|
710 | + */ |
|
711 | + public function access_settings () { |
|
712 | + |
|
713 | + if( sensei_all_access() ) return true; |
|
714 | + |
|
715 | + if ( isset( $this->settings->settings['access_permission'] ) && ( true == $this->settings->settings['access_permission'] ) ) { |
|
716 | + if ( is_user_logged_in() ) { |
|
717 | + return true; |
|
718 | + } else { |
|
719 | + return false; |
|
720 | + } // End If Statement |
|
721 | + } else { |
|
722 | + return true; |
|
723 | + } // End If Statement |
|
724 | + } // End access_settings() |
|
725 | + |
|
726 | + /** |
|
727 | + * load_class loads in class files |
|
728 | + * @since 1.2.0 |
|
729 | + * @access public |
|
730 | + * @return void |
|
731 | + */ |
|
732 | + public function load_class ( $class_name = '' ) { |
|
733 | + if ( '' != $class_name && '' != $this->token ) { |
|
734 | + require_once( 'class-' . esc_attr( $this->token ) . '-' . esc_attr( $class_name ) . '.php' ); |
|
735 | + } // End If Statement |
|
736 | + } // End load_class() |
|
737 | + |
|
738 | + /** |
|
739 | + * Filtering wp_count_comments to ensure that Sensei comments are ignored |
|
740 | + * @since 1.4.0 |
|
741 | + * @access public |
|
742 | + * @param array $comments |
|
743 | + * @param integer $post_id |
|
744 | + * @return array |
|
745 | + */ |
|
746 | + public function sensei_count_comments( $comments, $post_id ) { |
|
747 | + global $wpdb; |
|
748 | + |
|
749 | + $post_id = (int) $post_id; |
|
750 | + |
|
751 | + $count = wp_cache_get("comments-{$post_id}", 'counts'); |
|
752 | + |
|
753 | + if ( false !== $count ) { |
|
754 | + return $count; |
|
755 | + } |
|
756 | + |
|
757 | + $statuses = array( '' ); // Default to the WP normal comments |
|
758 | + $stati = $wpdb->get_results( "SELECT comment_type FROM {$wpdb->comments} GROUP BY comment_type", ARRAY_A ); |
|
759 | + foreach ( (array) $stati AS $status ) { |
|
760 | + if ( 'sensei_' != substr($status['comment_type'], 0, 7 ) ) { |
|
761 | + $statuses[] = $status['comment_type']; |
|
762 | + } |
|
763 | + } |
|
764 | + $where = "WHERE comment_type IN ('" . join("', '", array_unique( $statuses ) ) . "')"; |
|
765 | + |
|
766 | + if ( $post_id > 0 ) |
|
767 | + $where .= $wpdb->prepare( " AND comment_post_ID = %d", $post_id ); |
|
768 | + |
|
769 | + $count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A ); |
|
770 | + |
|
771 | + $total = 0; |
|
772 | + $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash', 'post-trashed' => 'post-trashed'); |
|
773 | + foreach ( (array) $count as $row ) { |
|
774 | + // Don't count post-trashed toward totals |
|
775 | + if ( 'post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'] ) |
|
776 | + $total += $row['num_comments']; |
|
777 | + if ( isset( $approved[$row['comment_approved']] ) ) |
|
778 | + $stats[$approved[$row['comment_approved']]] = $row['num_comments']; |
|
779 | + } |
|
780 | + |
|
781 | + $stats['total_comments'] = $total; |
|
782 | + foreach ( $approved as $key ) { |
|
783 | + if ( empty($stats[$key]) ) |
|
784 | + $stats[$key] = 0; |
|
785 | + } |
|
786 | + |
|
787 | + $stats = (object) $stats; |
|
788 | + wp_cache_set("comments-{$post_id}", $stats, 'counts'); |
|
789 | + |
|
790 | + return $stats; |
|
791 | + } |
|
792 | + |
|
793 | + /** |
|
794 | + * Init images. |
|
795 | + * |
|
796 | + * @since 1.4.5 |
|
797 | + * @access public |
|
798 | + * @return void |
|
799 | + */ |
|
800 | + public function init_image_sizes() { |
|
801 | + $course_archive_thumbnail = $this->get_image_size( 'course_archive_image' ); |
|
802 | + $course_single_thumbnail = $this->get_image_size( 'course_single_image' ); |
|
803 | + $lesson_archive_thumbnail = $this->get_image_size( 'lesson_archive_image' ); |
|
804 | + $lesson_single_thumbnail = $this->get_image_size( 'lesson_single_image' ); |
|
805 | + |
|
806 | + add_image_size( 'course_archive_thumbnail', $course_archive_thumbnail['width'], $course_archive_thumbnail['height'], $course_archive_thumbnail['crop'] ); |
|
807 | + add_image_size( 'course_single_thumbnail', $course_single_thumbnail['width'], $course_single_thumbnail['height'], $course_single_thumbnail['crop'] ); |
|
808 | + add_image_size( 'lesson_archive_thumbnail', $lesson_archive_thumbnail['width'], $lesson_archive_thumbnail['height'], $lesson_archive_thumbnail['crop'] ); |
|
809 | + add_image_size( 'lesson_single_thumbnail', $lesson_single_thumbnail['width'], $lesson_single_thumbnail['height'], $lesson_single_thumbnail['crop'] ); |
|
810 | + } |
|
811 | + |
|
812 | + /** |
|
813 | + * Get an image size. |
|
814 | + * |
|
815 | + * Variable is filtered by sensei_get_image_size_{image_size} |
|
816 | + * |
|
817 | + * @since 1.4.5 |
|
818 | + * @access public |
|
819 | + * @param mixed $image_size |
|
820 | + * @return string |
|
821 | + */ |
|
822 | + public function get_image_size( $image_size ) { |
|
823 | + |
|
824 | + // Only return sizes we define in settings |
|
825 | + if ( ! in_array( $image_size, array( 'course_archive_image', 'course_single_image', 'lesson_archive_image', 'lesson_single_image' ) ) ) |
|
826 | + return apply_filters( 'sensei_get_image_size_' . $image_size, '' ); |
|
827 | + |
|
828 | + if( ! isset( $this->settings->settings[ $image_size . '_width' ] ) ) { |
|
829 | + $this->settings->settings[ $image_size . '_width' ] = false; |
|
830 | + } |
|
831 | + if( ! isset( $this->settings->settings[ $image_size . '_height' ] ) ) { |
|
832 | + $this->settings->settings[ $image_size . '_height' ] = false; |
|
833 | + } |
|
834 | + if( ! isset( $this->settings->settings[ $image_size . '_hard_crop' ] ) ) { |
|
835 | + $this->settings->settings[ $image_size . '_hard_crop' ] = false; |
|
836 | + } |
|
837 | + |
|
838 | + $size = array_filter( array( |
|
839 | + 'width' => $this->settings->settings[ $image_size . '_width' ], |
|
840 | + 'height' => $this->settings->settings[ $image_size . '_height' ], |
|
841 | + 'crop' => $this->settings->settings[ $image_size . '_hard_crop' ] |
|
842 | + ) ); |
|
843 | + |
|
844 | + $size['width'] = isset( $size['width'] ) ? $size['width'] : '100'; |
|
845 | + $size['height'] = isset( $size['height'] ) ? $size['height'] : '100'; |
|
846 | + $size['crop'] = isset( $size['crop'] ) ? $size['crop'] : 0; |
|
847 | + |
|
848 | + return apply_filters( 'sensei_get_image_size_' . $image_size, $size ); |
|
849 | + } |
|
850 | + |
|
851 | + public function body_class( $classes ) { |
|
852 | + if( is_sensei() ) { |
|
853 | + $classes[] = 'sensei'; |
|
854 | + } |
|
855 | + return $classes; |
|
856 | + } |
|
857 | + |
|
858 | + /** |
|
859 | + * Checks that the Jetpack Beautiful Maths module has been activated to support LaTeX within question titles and answers |
|
860 | + * |
|
861 | + * @return null |
|
862 | + * @since 1.7.0 |
|
863 | + */ |
|
864 | + public function jetpack_latex_support() { |
|
865 | + if ( function_exists( 'latex_markup') ) { |
|
866 | + add_filter( 'sensei_question_title', 'latex_markup' ); |
|
867 | + add_filter( 'sensei_answer_text', 'latex_markup' ); |
|
868 | + } |
|
869 | + } |
|
870 | + |
|
871 | + /** |
|
872 | + * Load the module functionality. |
|
873 | + * |
|
874 | + * This function is hooked into plugins_loaded to avoid conflicts with |
|
875 | + * the retired modules extension. |
|
876 | + * |
|
877 | + * @since 1.8.0 |
|
878 | + */ |
|
879 | + public function load_modules_class(){ |
|
880 | + global $sensei_modules; |
|
881 | + |
|
882 | + if( !class_exists( 'Sensei_Modules' ) |
|
883 | + && 'Sensei_Modules' != get_class( $sensei_modules ) ) { |
|
884 | + |
|
885 | + //Load the modules class |
|
886 | + require_once( 'class-sensei-modules.php'); |
|
887 | + Sensei()->modules = new Sensei_Core_Modules( $this->file ); |
|
888 | + |
|
889 | + }else{ |
|
890 | + // fallback for people still using the modules extension. |
|
891 | + global $sensei_modules; |
|
892 | + Sensei()->modules = $sensei_modules; |
|
893 | + add_action( 'admin_notices', array( $this, 'disable_sensei_modules_extension'), 30 ); |
|
894 | + } |
|
895 | + } |
|
896 | + |
|
897 | + /** |
|
898 | + * Tell the user to that the modules extension is no longer needed. |
|
899 | + * |
|
900 | + * @since 1.8.0 |
|
901 | + */ |
|
902 | + public function disable_sensei_modules_extension(){ ?> |
|
903 | 903 | <div class="notice updated fade"> |
904 | 904 | <p> |
905 | 905 | <?php |
906 | - $plugin_manage_url = admin_url().'plugins.php#sensei-modules'; |
|
907 | - $plugin_link_element = '<a href="' . $plugin_manage_url . '" >plugins page</a> '; |
|
908 | - ?> |
|
906 | + $plugin_manage_url = admin_url().'plugins.php#sensei-modules'; |
|
907 | + $plugin_link_element = '<a href="' . $plugin_manage_url . '" >plugins page</a> '; |
|
908 | + ?> |
|
909 | 909 | <strong> Modules are now included in Sensei,</strong> so you no longer need the Sensei Modules extension. |
910 | 910 | Please deactivate and delete it from your <?php echo $plugin_link_element; ?>. (This will not affect your existing modules). |
911 | 911 | </p> |
@@ -913,200 +913,200 @@ discard block |
||
913 | 913 | |
914 | 914 | <?php }// end function |
915 | 915 | |
916 | - /** |
|
917 | - * Sensei wide rewrite flush call. |
|
918 | - * |
|
919 | - * To use this simply update the option 'sensei_flush_rewrite_rules' to 1 |
|
920 | - * |
|
921 | - * After the option is one the Rules will be flushed. |
|
922 | - * |
|
923 | - * @since 1.9.0 |
|
924 | - */ |
|
925 | - public function flush_rewrite_rules(){ |
|
926 | - |
|
927 | - // ensures that the rewrite rules are flushed on the second |
|
928 | - // attempt. This ensure that the settings for any other process |
|
929 | - // have been completed and saved to the database before we refresh the |
|
930 | - // rewrite rules. |
|
931 | - $option = get_option('sensei_flush_rewrite_rules'); |
|
932 | - if( '1' == $option ) { |
|
933 | - |
|
934 | - update_option('sensei_flush_rewrite_rules', '2'); |
|
935 | - |
|
936 | - }elseif( '2' == $option ) { |
|
937 | - |
|
938 | - flush_rewrite_rules(); |
|
939 | - update_option('sensei_flush_rewrite_rules', '0'); |
|
940 | - |
|
941 | - } |
|
942 | - |
|
943 | - } // end flush_rewrite_rules |
|
944 | - |
|
945 | - /** |
|
946 | - * Calling this function will tell Sensei to flush rewrite |
|
947 | - * rules on the next load. |
|
948 | - * |
|
949 | - * @since 1.9.0 |
|
950 | - */ |
|
951 | - public function initiate_rewrite_rules_flush(){ |
|
952 | - |
|
953 | - update_option('sensei_flush_rewrite_rules', '1'); |
|
954 | - |
|
955 | - } |
|
956 | - |
|
957 | - /** |
|
958 | - * sensei_woocommerce_email_course_details adds detail to email |
|
959 | - * |
|
960 | - * @deprecated since 1.9.0 use Sensei_WC::email_course_details |
|
961 | - * |
|
962 | - * @since 1.4.5 |
|
963 | - * @access public |
|
964 | - * @param WC_Order $order |
|
965 | - * |
|
966 | - * @return void |
|
967 | - */ |
|
968 | - public function sensei_woocommerce_email_course_details( $order ) { |
|
969 | - |
|
970 | - Sensei_WC::email_course_details( $order ); |
|
971 | - |
|
972 | - } // end func email course details |
|
973 | - |
|
974 | - /** |
|
975 | - * @deprecated since 1.9.0, movde to the Sensei_WC class |
|
976 | - * @param $user_id |
|
977 | - * @param $subscription_key |
|
978 | - */ |
|
979 | - public function sensei_woocommerce_reactivate_subscription( $user_id, $subscription_key ){ |
|
980 | - |
|
981 | - Sensei_WC::reactivate_subscription( $user_id, $subscription_key ); |
|
982 | - } |
|
983 | - |
|
984 | - /** |
|
985 | - * @deprecated since 1.9.0, movde to the Sensei_WC class |
|
986 | - * @param $user_id |
|
987 | - * @param $subscription_key |
|
988 | - */ |
|
989 | - public function sensei_woocommerce_subscription_ended( $user_id, $subscription_key ){ |
|
990 | - |
|
991 | - Sensei_WC::end_subscription( $user_id, $subscription_key ); |
|
992 | - } |
|
993 | - |
|
994 | - /** |
|
995 | - * sensei_woocommerce_complete_order description |
|
996 | - * |
|
997 | - * @deprecated since 1.9.0 use Sensei_WC::complete_order( $order_id ); |
|
998 | - * @since 1.0.3 |
|
999 | - * @access public |
|
1000 | - * @param int $order_id WC order ID |
|
1001 | - * |
|
1002 | - * @return void |
|
1003 | - */ |
|
1004 | - public function sensei_woocommerce_complete_order ( $order_id = 0 ) { |
|
1005 | - |
|
1006 | - Sensei_WC::complete_order( $order_id ); |
|
1007 | - |
|
1008 | - } // End sensei_woocommerce_complete_order() |
|
1009 | - |
|
1010 | - /** |
|
1011 | - * Runs when an order is cancelled. |
|
1012 | - * |
|
1013 | - * @deprecated since 1.9.0 |
|
1014 | - * |
|
1015 | - * @since 1.2.0 |
|
1016 | - * @param integer $order_id order ID |
|
1017 | - * @return void |
|
1018 | - */ |
|
1019 | - public function sensei_woocommerce_cancel_order ( $order_id ) { |
|
1020 | - |
|
1021 | - Sensei_WC::cancel_order( $order_id ); |
|
1022 | - |
|
1023 | - } // End sensei_woocommerce_cancel_order() |
|
1024 | - |
|
1025 | - /** |
|
1026 | - * sensei_activate_subscription runs when a subscription product is purchased |
|
1027 | - * @deprecated since 1.9.0 |
|
1028 | - * @since 1.2.0 |
|
1029 | - * @access public |
|
1030 | - * @param integer $order_id order ID |
|
1031 | - * @return void |
|
1032 | - */ |
|
1033 | - public function sensei_activate_subscription( $order_id = 0 ) { |
|
1034 | - |
|
1035 | - Sensei_WC::activate_subscription( $order_id ); |
|
1036 | - |
|
1037 | - } // End sensei_activate_subscription() |
|
1038 | - |
|
1039 | - /** |
|
1040 | - * If WooCommerce is activated and the customer has purchased the course, update Sensei to indicate that they are taking the course. |
|
1041 | - * @deprecated since 1.9.0 |
|
1042 | - * @since 1.0.0 |
|
1043 | - * @param int $course_id (default: 0) |
|
1044 | - * @param array/Object $order_user (default: array()) Specific user's data. |
|
1045 | - * @return bool|int |
|
1046 | - */ |
|
1047 | - public function woocommerce_course_update ( $course_id = 0, $order_user = array() ) { |
|
1048 | - |
|
1049 | - return Sensei_WC::course_update( $course_id, $order_user ); |
|
1050 | - |
|
1051 | - } // End woocommerce_course_update() |
|
1052 | - |
|
1053 | - /** |
|
1054 | - * Returns the WooCommerce Product Object |
|
1055 | - * |
|
1056 | - * The code caters for pre and post WooCommerce 2.2 installations. |
|
1057 | - * |
|
1058 | - * @deprecated since 1.9.0 |
|
1059 | - * @since 1.1.1 |
|
1060 | - * |
|
1061 | - * @param integer $wc_product_id Product ID or Variation ID |
|
1062 | - * @param string $product_type '' or 'variation' |
|
1063 | - * |
|
1064 | - * @return WC_Product $wc_product_object |
|
1065 | - */ |
|
1066 | - public function sensei_get_woocommerce_product_object ( $wc_product_id = 0, $product_type = '' ) { |
|
1067 | - |
|
1068 | - return Sensei_WC::get_product_object( $wc_product_id, $product_type ); |
|
1069 | - |
|
1070 | - } // End sensei_get_woocommerce_product_object() |
|
1071 | - |
|
1072 | - /** |
|
1073 | - * Setup required WooCommerce settings. |
|
1074 | - * @access public |
|
1075 | - * @since 1.1.0 |
|
1076 | - * @return void |
|
1077 | - */ |
|
1078 | - public function set_woocommerce_functionality() { |
|
1079 | - |
|
1080 | - _deprecated_function('Sensei()->set_woocommerce_functionality', 'Sensei 1.9.0'); |
|
1081 | - |
|
1082 | - } // End set_woocommerce_functionality() |
|
1083 | - |
|
1084 | - /** |
|
1085 | - * Disable guest checkout if a course product is in the cart |
|
1086 | - * @deprecated since 1.9.0 |
|
1087 | - * @param boolean $guest_checkout Current guest checkout setting |
|
1088 | - * @return boolean Modified guest checkout setting |
|
1089 | - */ |
|
1090 | - public function disable_guest_checkout( $guest_checkout ) { |
|
1091 | - |
|
1092 | - return Sensei_WC::disable_guest_checkout( $guest_checkout ); |
|
1093 | - |
|
1094 | - }// end disable_guest_checkout |
|
1095 | - |
|
1096 | - /** |
|
1097 | - * Change order status with virtual products to completed |
|
1098 | - * |
|
1099 | - * @deprecated since 1.9.0 use Sensei_WC::virtual_order_payment_complete( $order_status, $order_id ) |
|
1100 | - * |
|
1101 | - * @since 1.1.0 |
|
1102 | - * @param string $order_status |
|
1103 | - * @param int $order_id |
|
1104 | - * @return string |
|
1105 | - **/ |
|
1106 | - public function virtual_order_payment_complete( $order_status, $order_id ) { |
|
1107 | - |
|
1108 | - return Sensei_WC::virtual_order_payment_complete( $order_status, $order_id ); |
|
1109 | - } |
|
916 | + /** |
|
917 | + * Sensei wide rewrite flush call. |
|
918 | + * |
|
919 | + * To use this simply update the option 'sensei_flush_rewrite_rules' to 1 |
|
920 | + * |
|
921 | + * After the option is one the Rules will be flushed. |
|
922 | + * |
|
923 | + * @since 1.9.0 |
|
924 | + */ |
|
925 | + public function flush_rewrite_rules(){ |
|
926 | + |
|
927 | + // ensures that the rewrite rules are flushed on the second |
|
928 | + // attempt. This ensure that the settings for any other process |
|
929 | + // have been completed and saved to the database before we refresh the |
|
930 | + // rewrite rules. |
|
931 | + $option = get_option('sensei_flush_rewrite_rules'); |
|
932 | + if( '1' == $option ) { |
|
933 | + |
|
934 | + update_option('sensei_flush_rewrite_rules', '2'); |
|
935 | + |
|
936 | + }elseif( '2' == $option ) { |
|
937 | + |
|
938 | + flush_rewrite_rules(); |
|
939 | + update_option('sensei_flush_rewrite_rules', '0'); |
|
940 | + |
|
941 | + } |
|
942 | + |
|
943 | + } // end flush_rewrite_rules |
|
944 | + |
|
945 | + /** |
|
946 | + * Calling this function will tell Sensei to flush rewrite |
|
947 | + * rules on the next load. |
|
948 | + * |
|
949 | + * @since 1.9.0 |
|
950 | + */ |
|
951 | + public function initiate_rewrite_rules_flush(){ |
|
952 | + |
|
953 | + update_option('sensei_flush_rewrite_rules', '1'); |
|
954 | + |
|
955 | + } |
|
956 | + |
|
957 | + /** |
|
958 | + * sensei_woocommerce_email_course_details adds detail to email |
|
959 | + * |
|
960 | + * @deprecated since 1.9.0 use Sensei_WC::email_course_details |
|
961 | + * |
|
962 | + * @since 1.4.5 |
|
963 | + * @access public |
|
964 | + * @param WC_Order $order |
|
965 | + * |
|
966 | + * @return void |
|
967 | + */ |
|
968 | + public function sensei_woocommerce_email_course_details( $order ) { |
|
969 | + |
|
970 | + Sensei_WC::email_course_details( $order ); |
|
971 | + |
|
972 | + } // end func email course details |
|
973 | + |
|
974 | + /** |
|
975 | + * @deprecated since 1.9.0, movde to the Sensei_WC class |
|
976 | + * @param $user_id |
|
977 | + * @param $subscription_key |
|
978 | + */ |
|
979 | + public function sensei_woocommerce_reactivate_subscription( $user_id, $subscription_key ){ |
|
980 | + |
|
981 | + Sensei_WC::reactivate_subscription( $user_id, $subscription_key ); |
|
982 | + } |
|
983 | + |
|
984 | + /** |
|
985 | + * @deprecated since 1.9.0, movde to the Sensei_WC class |
|
986 | + * @param $user_id |
|
987 | + * @param $subscription_key |
|
988 | + */ |
|
989 | + public function sensei_woocommerce_subscription_ended( $user_id, $subscription_key ){ |
|
990 | + |
|
991 | + Sensei_WC::end_subscription( $user_id, $subscription_key ); |
|
992 | + } |
|
993 | + |
|
994 | + /** |
|
995 | + * sensei_woocommerce_complete_order description |
|
996 | + * |
|
997 | + * @deprecated since 1.9.0 use Sensei_WC::complete_order( $order_id ); |
|
998 | + * @since 1.0.3 |
|
999 | + * @access public |
|
1000 | + * @param int $order_id WC order ID |
|
1001 | + * |
|
1002 | + * @return void |
|
1003 | + */ |
|
1004 | + public function sensei_woocommerce_complete_order ( $order_id = 0 ) { |
|
1005 | + |
|
1006 | + Sensei_WC::complete_order( $order_id ); |
|
1007 | + |
|
1008 | + } // End sensei_woocommerce_complete_order() |
|
1009 | + |
|
1010 | + /** |
|
1011 | + * Runs when an order is cancelled. |
|
1012 | + * |
|
1013 | + * @deprecated since 1.9.0 |
|
1014 | + * |
|
1015 | + * @since 1.2.0 |
|
1016 | + * @param integer $order_id order ID |
|
1017 | + * @return void |
|
1018 | + */ |
|
1019 | + public function sensei_woocommerce_cancel_order ( $order_id ) { |
|
1020 | + |
|
1021 | + Sensei_WC::cancel_order( $order_id ); |
|
1022 | + |
|
1023 | + } // End sensei_woocommerce_cancel_order() |
|
1024 | + |
|
1025 | + /** |
|
1026 | + * sensei_activate_subscription runs when a subscription product is purchased |
|
1027 | + * @deprecated since 1.9.0 |
|
1028 | + * @since 1.2.0 |
|
1029 | + * @access public |
|
1030 | + * @param integer $order_id order ID |
|
1031 | + * @return void |
|
1032 | + */ |
|
1033 | + public function sensei_activate_subscription( $order_id = 0 ) { |
|
1034 | + |
|
1035 | + Sensei_WC::activate_subscription( $order_id ); |
|
1036 | + |
|
1037 | + } // End sensei_activate_subscription() |
|
1038 | + |
|
1039 | + /** |
|
1040 | + * If WooCommerce is activated and the customer has purchased the course, update Sensei to indicate that they are taking the course. |
|
1041 | + * @deprecated since 1.9.0 |
|
1042 | + * @since 1.0.0 |
|
1043 | + * @param int $course_id (default: 0) |
|
1044 | + * @param array/Object $order_user (default: array()) Specific user's data. |
|
1045 | + * @return bool|int |
|
1046 | + */ |
|
1047 | + public function woocommerce_course_update ( $course_id = 0, $order_user = array() ) { |
|
1048 | + |
|
1049 | + return Sensei_WC::course_update( $course_id, $order_user ); |
|
1050 | + |
|
1051 | + } // End woocommerce_course_update() |
|
1052 | + |
|
1053 | + /** |
|
1054 | + * Returns the WooCommerce Product Object |
|
1055 | + * |
|
1056 | + * The code caters for pre and post WooCommerce 2.2 installations. |
|
1057 | + * |
|
1058 | + * @deprecated since 1.9.0 |
|
1059 | + * @since 1.1.1 |
|
1060 | + * |
|
1061 | + * @param integer $wc_product_id Product ID or Variation ID |
|
1062 | + * @param string $product_type '' or 'variation' |
|
1063 | + * |
|
1064 | + * @return WC_Product $wc_product_object |
|
1065 | + */ |
|
1066 | + public function sensei_get_woocommerce_product_object ( $wc_product_id = 0, $product_type = '' ) { |
|
1067 | + |
|
1068 | + return Sensei_WC::get_product_object( $wc_product_id, $product_type ); |
|
1069 | + |
|
1070 | + } // End sensei_get_woocommerce_product_object() |
|
1071 | + |
|
1072 | + /** |
|
1073 | + * Setup required WooCommerce settings. |
|
1074 | + * @access public |
|
1075 | + * @since 1.1.0 |
|
1076 | + * @return void |
|
1077 | + */ |
|
1078 | + public function set_woocommerce_functionality() { |
|
1079 | + |
|
1080 | + _deprecated_function('Sensei()->set_woocommerce_functionality', 'Sensei 1.9.0'); |
|
1081 | + |
|
1082 | + } // End set_woocommerce_functionality() |
|
1083 | + |
|
1084 | + /** |
|
1085 | + * Disable guest checkout if a course product is in the cart |
|
1086 | + * @deprecated since 1.9.0 |
|
1087 | + * @param boolean $guest_checkout Current guest checkout setting |
|
1088 | + * @return boolean Modified guest checkout setting |
|
1089 | + */ |
|
1090 | + public function disable_guest_checkout( $guest_checkout ) { |
|
1091 | + |
|
1092 | + return Sensei_WC::disable_guest_checkout( $guest_checkout ); |
|
1093 | + |
|
1094 | + }// end disable_guest_checkout |
|
1095 | + |
|
1096 | + /** |
|
1097 | + * Change order status with virtual products to completed |
|
1098 | + * |
|
1099 | + * @deprecated since 1.9.0 use Sensei_WC::virtual_order_payment_complete( $order_status, $order_id ) |
|
1100 | + * |
|
1101 | + * @since 1.1.0 |
|
1102 | + * @param string $order_status |
|
1103 | + * @param int $order_id |
|
1104 | + * @return string |
|
1105 | + **/ |
|
1106 | + public function virtual_order_payment_complete( $order_status, $order_id ) { |
|
1107 | + |
|
1108 | + return Sensei_WC::virtual_order_payment_complete( $order_status, $order_id ); |
|
1109 | + } |
|
1110 | 1110 | |
1111 | 1111 | } // End Class |
1112 | 1112 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
2 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
3 | 3 | |
4 | 4 | /** |
5 | 5 | * Responsible for loading Sensei and setting up the Main WordPress hooks. |
@@ -142,23 +142,23 @@ discard block |
||
142 | 142 | * @param string $file The base file of the plugin. |
143 | 143 | * @since 1.0.0 |
144 | 144 | */ |
145 | - public function __construct ( $file ) { |
|
145 | + public function __construct($file) { |
|
146 | 146 | |
147 | 147 | // Setup object data |
148 | 148 | $this->file = $file; |
149 | - $this->plugin_url = trailingslashit( plugins_url( '', $plugin = $file ) ); |
|
150 | - $this->plugin_path = trailingslashit( dirname( $file ) ); |
|
151 | - $this->template_url = apply_filters( 'sensei_template_url', 'sensei/' ); |
|
152 | - $this->permissions_message = array( 'title' => __( 'Permission Denied', 'woothemes-sensei' ), 'message' => __( 'Unfortunately you do not have permissions to access this page.', 'woothemes-sensei' ) ); |
|
149 | + $this->plugin_url = trailingslashit(plugins_url('', $plugin = $file)); |
|
150 | + $this->plugin_path = trailingslashit(dirname($file)); |
|
151 | + $this->template_url = apply_filters('sensei_template_url', 'sensei/'); |
|
152 | + $this->permissions_message = array('title' => __('Permission Denied', 'woothemes-sensei'), 'message' => __('Unfortunately you do not have permissions to access this page.', 'woothemes-sensei')); |
|
153 | 153 | |
154 | 154 | // Initialize the core Sensei functionality |
155 | 155 | $this->init(); |
156 | 156 | |
157 | 157 | // Installation |
158 | - if ( is_admin() && ! defined( 'DOING_AJAX' ) ) $this->install(); |
|
158 | + if (is_admin() && ! defined('DOING_AJAX')) $this->install(); |
|
159 | 159 | |
160 | 160 | // Run this on activation. |
161 | - register_activation_hook( $this->file, array( $this, 'activation' ) ); |
|
161 | + register_activation_hook($this->file, array($this, 'activation')); |
|
162 | 162 | |
163 | 163 | // Image Sizes |
164 | 164 | $this->init_image_sizes(); |
@@ -172,11 +172,11 @@ discard block |
||
172 | 172 | * Load the foundations of Sensei. |
173 | 173 | * @since 1.9.0 |
174 | 174 | */ |
175 | - protected function init(){ |
|
175 | + protected function init() { |
|
176 | 176 | |
177 | 177 | // Localisation |
178 | 178 | $this->load_plugin_textdomain(); |
179 | - add_action( 'init', array( $this, 'load_localisation' ), 0 ); |
|
179 | + add_action('init', array($this, 'load_localisation'), 0); |
|
180 | 180 | |
181 | 181 | // Setup settings |
182 | 182 | $this->settings = new Sensei_Settings(); |
@@ -199,12 +199,12 @@ discard block |
||
199 | 199 | */ |
200 | 200 | public static function instance() { |
201 | 201 | |
202 | - if ( is_null( self::$_instance ) ) { |
|
202 | + if (is_null(self::$_instance)) { |
|
203 | 203 | |
204 | 204 | //Sensei requires a reference to the main Sensei plugin file |
205 | - $sensei_main_plugin_file = dirname ( dirname( __FILE__ ) ) . '/woothemes-sensei.php'; |
|
205 | + $sensei_main_plugin_file = dirname(dirname(__FILE__)).'/woothemes-sensei.php'; |
|
206 | 206 | |
207 | - self::$_instance = new self( $sensei_main_plugin_file ); |
|
207 | + self::$_instance = new self($sensei_main_plugin_file); |
|
208 | 208 | |
209 | 209 | // load the global class objects needed throughout Sensei |
210 | 210 | self::$_instance->initialize_global_objects(); |
@@ -223,9 +223,9 @@ discard block |
||
223 | 223 | * |
224 | 224 | * @param $plugin |
225 | 225 | */ |
226 | - public static function activation_flush_rules( $plugin ){ |
|
226 | + public static function activation_flush_rules($plugin) { |
|
227 | 227 | |
228 | - if( strpos( $plugin, '/woothemes-sensei.php' ) > 0 ){ |
|
228 | + if (strpos($plugin, '/woothemes-sensei.php') > 0) { |
|
229 | 229 | |
230 | 230 | flush_rewrite_rules(true); |
231 | 231 | |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | * @since 1.8.0 |
239 | 239 | */ |
240 | 240 | public function __clone() { |
241 | - _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woothemes-sensei' ), '1.8' ); |
|
241 | + _doing_it_wrong(__FUNCTION__, __('Cheatin’ huh?', 'woothemes-sensei'), '1.8'); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | /** |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | * @since 1.8.0 |
247 | 247 | */ |
248 | 248 | public function __wakeup() { |
249 | - _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woothemes-sensei' ), '1.8' ); |
|
249 | + _doing_it_wrong(__FUNCTION__, __('Cheatin’ huh?', 'woothemes-sensei'), '1.8'); |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | /** |
@@ -254,13 +254,13 @@ discard block |
||
254 | 254 | * |
255 | 255 | * @since 1.9.0 |
256 | 256 | */ |
257 | - public function initialize_global_objects(){ |
|
257 | + public function initialize_global_objects() { |
|
258 | 258 | |
259 | 259 | // Setup post types. |
260 | 260 | $this->post_types = new Sensei_PostTypes(); |
261 | 261 | |
262 | 262 | // Lad the updates class |
263 | - $this->updates = new Sensei_Updates( $this ); |
|
263 | + $this->updates = new Sensei_Updates($this); |
|
264 | 264 | |
265 | 265 | // Load Course Results Class |
266 | 266 | $this->course_results = new Sensei_Course_Results(); |
@@ -281,22 +281,22 @@ discard block |
||
281 | 281 | $this->quiz = $this->post_types->quiz; |
282 | 282 | |
283 | 283 | // load the modules class after all plugsin are loaded |
284 | - add_action( 'plugins_loaded', array( $this, 'load_modules_class' ) ); |
|
284 | + add_action('plugins_loaded', array($this, 'load_modules_class')); |
|
285 | 285 | |
286 | 286 | // Load Learner Management Functionality |
287 | - $this->learners = new Sensei_Learner_Management( $this->file ); |
|
287 | + $this->learners = new Sensei_Learner_Management($this->file); |
|
288 | 288 | |
289 | 289 | // Differentiate between administration and frontend logic. |
290 | - if ( is_admin() ) { |
|
290 | + if (is_admin()) { |
|
291 | 291 | |
292 | 292 | // Load Admin Welcome class |
293 | 293 | new Sensei_Welcome(); |
294 | 294 | |
295 | 295 | // Load Admin Class |
296 | - $this->admin = new Sensei_Admin( $this->file ); |
|
296 | + $this->admin = new Sensei_Admin($this->file); |
|
297 | 297 | |
298 | 298 | // Load Analysis Reports |
299 | - $this->analysis = new Sensei_Analysis( $this->file ); |
|
299 | + $this->analysis = new Sensei_Analysis($this->file); |
|
300 | 300 | |
301 | 301 | } else { |
302 | 302 | |
@@ -313,10 +313,10 @@ discard block |
||
313 | 313 | } |
314 | 314 | |
315 | 315 | // Load Grading Functionality |
316 | - $this->grading = new Sensei_Grading( $this->file ); |
|
316 | + $this->grading = new Sensei_Grading($this->file); |
|
317 | 317 | |
318 | 318 | // Load Email Class |
319 | - $this->emails = new Sensei_Emails( $this->file ); |
|
319 | + $this->emails = new Sensei_Emails($this->file); |
|
320 | 320 | |
321 | 321 | // Load Learner Profiles Class |
322 | 322 | $this->learner_profiles = new Sensei_Learner_Profiles(); |
@@ -328,21 +328,21 @@ discard block |
||
328 | 328 | * |
329 | 329 | * @since 1.9.0 |
330 | 330 | */ |
331 | - public function load_hooks(){ |
|
331 | + public function load_hooks() { |
|
332 | 332 | |
333 | - add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
334 | - add_action( 'after_setup_theme', array( $this, 'ensure_post_thumbnails_support' ) ); |
|
333 | + add_action('widgets_init', array($this, 'register_widgets')); |
|
334 | + add_action('after_setup_theme', array($this, 'ensure_post_thumbnails_support')); |
|
335 | 335 | |
336 | 336 | // Filter comment counts |
337 | - add_filter( 'wp_count_comments', array( $this, 'sensei_count_comments' ), 10, 2 ); |
|
337 | + add_filter('wp_count_comments', array($this, 'sensei_count_comments'), 10, 2); |
|
338 | 338 | |
339 | - add_action( 'body_class', array( $this, 'body_class' ) ); |
|
339 | + add_action('body_class', array($this, 'body_class')); |
|
340 | 340 | |
341 | 341 | // Check for and activate JetPack LaTeX support |
342 | - add_action( 'plugins_loaded', array( $this, 'jetpack_latex_support'), 200 ); // Runs after Jetpack has loaded it's modules |
|
342 | + add_action('plugins_loaded', array($this, 'jetpack_latex_support'), 200); // Runs after Jetpack has loaded it's modules |
|
343 | 343 | |
344 | 344 | // check flush the rewrite rules if the option sensei_flush_rewrite_rules option is 1 |
345 | - add_action( 'init', array( $this, 'flush_rewrite_rules'), 101 ); |
|
345 | + add_action('init', array($this, 'flush_rewrite_rules'), 101); |
|
346 | 346 | |
347 | 347 | } |
348 | 348 | |
@@ -354,7 +354,7 @@ discard block |
||
354 | 354 | */ |
355 | 355 | public function run_updates() { |
356 | 356 | // Run updates if administrator |
357 | - if ( current_user_can( 'manage_options' ) || current_user_can( 'manage_sensei' ) ) { |
|
357 | + if (current_user_can('manage_options') || current_user_can('manage_sensei')) { |
|
358 | 358 | |
359 | 359 | $this->updates->update(); |
360 | 360 | |
@@ -367,21 +367,21 @@ discard block |
||
367 | 367 | * @since 1.0.0 |
368 | 368 | * @return void |
369 | 369 | */ |
370 | - public function register_widgets () { |
|
370 | + public function register_widgets() { |
|
371 | 371 | // Widget List (key => value is filename => widget class). |
372 | - $widget_list = apply_filters( 'sensei_registered_widgets_list', array( 'course-component' => 'Course_Component', |
|
372 | + $widget_list = apply_filters('sensei_registered_widgets_list', array('course-component' => 'Course_Component', |
|
373 | 373 | 'lesson-component' => 'Lesson_Component', |
374 | 374 | 'course-categories' => 'Course_Categories', |
375 | - 'category-courses' => 'Category_Courses' ) |
|
375 | + 'category-courses' => 'Category_Courses') |
|
376 | 376 | ); |
377 | - foreach ( $widget_list as $key => $value ) { |
|
378 | - if ( file_exists( $this->plugin_path . 'widgets/widget-woothemes-sensei-' . $key . '.php' ) ) { |
|
379 | - require_once( $this->plugin_path . 'widgets/widget-woothemes-sensei-' . $key . '.php' ); |
|
380 | - register_widget( 'WooThemes_Sensei_' . $value . '_Widget' ); |
|
377 | + foreach ($widget_list as $key => $value) { |
|
378 | + if (file_exists($this->plugin_path.'widgets/widget-woothemes-sensei-'.$key.'.php')) { |
|
379 | + require_once($this->plugin_path.'widgets/widget-woothemes-sensei-'.$key.'.php'); |
|
380 | + register_widget('WooThemes_Sensei_'.$value.'_Widget'); |
|
381 | 381 | } |
382 | 382 | } // End For Loop |
383 | 383 | |
384 | - do_action( 'sensei_register_widgets' ); |
|
384 | + do_action('sensei_register_widgets'); |
|
385 | 385 | |
386 | 386 | } // End register_widgets() |
387 | 387 | |
@@ -391,9 +391,9 @@ discard block |
||
391 | 391 | * @since 1.0.0 |
392 | 392 | * @return void |
393 | 393 | */ |
394 | - public function load_localisation () { |
|
394 | + public function load_localisation() { |
|
395 | 395 | |
396 | - load_plugin_textdomain( 'woothemes-sensei', false, dirname( plugin_basename( $this->file ) ) . '/lang/' ); |
|
396 | + load_plugin_textdomain('woothemes-sensei', false, dirname(plugin_basename($this->file)).'/lang/'); |
|
397 | 397 | |
398 | 398 | } // End load_localisation() |
399 | 399 | |
@@ -403,13 +403,13 @@ discard block |
||
403 | 403 | * @since 1.0.0 |
404 | 404 | * @return void |
405 | 405 | */ |
406 | - public function load_plugin_textdomain () { |
|
406 | + public function load_plugin_textdomain() { |
|
407 | 407 | |
408 | 408 | $domain = 'woothemes-sensei'; |
409 | 409 | // The "plugin_locale" filter is also used in load_plugin_textdomain() |
410 | - $locale = apply_filters( 'plugin_locale', get_locale(), $domain ); |
|
411 | - load_textdomain( $domain, WP_LANG_DIR . '/' . $domain . '/' . $domain . '-' . $locale . '.mo' ); |
|
412 | - load_plugin_textdomain( $domain, FALSE, dirname( plugin_basename( $this->file ) ) . '/lang/' ); |
|
410 | + $locale = apply_filters('plugin_locale', get_locale(), $domain); |
|
411 | + load_textdomain($domain, WP_LANG_DIR.'/'.$domain.'/'.$domain.'-'.$locale.'.mo'); |
|
412 | + load_plugin_textdomain($domain, FALSE, dirname(plugin_basename($this->file)).'/lang/'); |
|
413 | 413 | |
414 | 414 | } // End load_plugin_textdomain() |
415 | 415 | |
@@ -419,7 +419,7 @@ discard block |
||
419 | 419 | * @since 1.0.0 |
420 | 420 | * @return void |
421 | 421 | */ |
422 | - public function activation () { |
|
422 | + public function activation() { |
|
423 | 423 | |
424 | 424 | $this->register_plugin_version(); |
425 | 425 | |
@@ -432,10 +432,10 @@ discard block |
||
432 | 432 | * @since 1.0.0 |
433 | 433 | * @return void |
434 | 434 | */ |
435 | - public function install () { |
|
435 | + public function install() { |
|
436 | 436 | |
437 | - register_activation_hook( $this->file, array( $this, 'activate_sensei' ) ); |
|
438 | - register_activation_hook( $this->file, 'flush_rewrite_rules' ); |
|
437 | + register_activation_hook($this->file, array($this, 'activate_sensei')); |
|
438 | + register_activation_hook($this->file, 'flush_rewrite_rules'); |
|
439 | 439 | |
440 | 440 | } // End install() |
441 | 441 | |
@@ -446,10 +446,10 @@ discard block |
||
446 | 446 | * @since 1.0.0 |
447 | 447 | * @return void |
448 | 448 | */ |
449 | - public function activate_sensei () { |
|
449 | + public function activate_sensei() { |
|
450 | 450 | |
451 | - update_option( 'skip_install_sensei_pages', 0 ); |
|
452 | - update_option( 'sensei_installed', 1 ); |
|
451 | + update_option('skip_install_sensei_pages', 0); |
|
452 | + update_option('sensei_installed', 1); |
|
453 | 453 | |
454 | 454 | } // End activate_sensei() |
455 | 455 | |
@@ -459,10 +459,10 @@ discard block |
||
459 | 459 | * @since 1.0.0 |
460 | 460 | * @return void |
461 | 461 | */ |
462 | - private function register_plugin_version () { |
|
463 | - if ( $this->version != '' ) { |
|
462 | + private function register_plugin_version() { |
|
463 | + if ($this->version != '') { |
|
464 | 464 | |
465 | - update_option( 'woothemes-sensei-version', $this->version ); |
|
465 | + update_option('woothemes-sensei-version', $this->version); |
|
466 | 466 | |
467 | 467 | } |
468 | 468 | } // End register_plugin_version() |
@@ -473,9 +473,9 @@ discard block |
||
473 | 473 | * @since 1.0.1 |
474 | 474 | * @return void |
475 | 475 | */ |
476 | - public function ensure_post_thumbnails_support () { |
|
476 | + public function ensure_post_thumbnails_support() { |
|
477 | 477 | |
478 | - if ( ! current_theme_supports( 'post-thumbnails' ) ) { add_theme_support( 'post-thumbnails' ); } |
|
478 | + if ( ! current_theme_supports('post-thumbnails')) { add_theme_support('post-thumbnails'); } |
|
479 | 479 | |
480 | 480 | } // End ensure_post_thumbnails_support() |
481 | 481 | |
@@ -487,10 +487,10 @@ discard block |
||
487 | 487 | * @return void |
488 | 488 | * @deprecated |
489 | 489 | */ |
490 | - public function template_loader ( $template = '' ) { |
|
490 | + public function template_loader($template = '') { |
|
491 | 491 | |
492 | - _deprecated_function( 'Sensei()->template_loader', '1.9.0', 'Use Sensei_Templates::template_loader( $template ) instead' ); |
|
493 | - Sensei_Templates::template_loader( $template ); |
|
492 | + _deprecated_function('Sensei()->template_loader', '1.9.0', 'Use Sensei_Templates::template_loader( $template ) instead'); |
|
493 | + Sensei_Templates::template_loader($template); |
|
494 | 494 | |
495 | 495 | } // End template_loader() |
496 | 496 | |
@@ -500,15 +500,15 @@ discard block |
||
500 | 500 | * @since 1.0.0 |
501 | 501 | * @return string $sensei_plugin_path |
502 | 502 | */ |
503 | - public function plugin_path () { |
|
503 | + public function plugin_path() { |
|
504 | 504 | |
505 | - if ( $this->plugin_path ) { |
|
505 | + if ($this->plugin_path) { |
|
506 | 506 | |
507 | - $sensei_plugin_path = $this->plugin_path; |
|
507 | + $sensei_plugin_path = $this->plugin_path; |
|
508 | 508 | |
509 | - }else{ |
|
509 | + } else { |
|
510 | 510 | |
511 | - $sensei_plugin_path = plugin_dir_path( __FILE__ ); |
|
511 | + $sensei_plugin_path = plugin_dir_path(__FILE__); |
|
512 | 512 | |
513 | 513 | } |
514 | 514 | |
@@ -523,9 +523,9 @@ discard block |
||
523 | 523 | * @param string $page |
524 | 524 | * @return int |
525 | 525 | */ |
526 | - public function get_page_id ( $page ) { |
|
527 | - $page = apply_filters( 'sensei_get_' . esc_attr( $page ) . '_page_id', get_option( 'sensei_' . esc_attr( $page ) . '_page_id' ) ); |
|
528 | - return ( $page ) ? $page : -1; |
|
526 | + public function get_page_id($page) { |
|
527 | + $page = apply_filters('sensei_get_'.esc_attr($page).'_page_id', get_option('sensei_'.esc_attr($page).'_page_id')); |
|
528 | + return ($page) ? $page : -1; |
|
529 | 529 | } // End get_page_id() |
530 | 530 | |
531 | 531 | /** |
@@ -536,101 +536,101 @@ discard block |
||
536 | 536 | * |
537 | 537 | * @return bool |
538 | 538 | */ |
539 | - public function check_user_permissions ( $page = '' ) { |
|
539 | + public function check_user_permissions($page = '') { |
|
540 | 540 | |
541 | 541 | global $current_user, $post; |
542 | 542 | |
543 | 543 | // if user is not logged in skipped for single lesson |
544 | - if ( empty( $current_user->caps ) && Sensei()->settings->get('access_permission') |
|
545 | - && 'lesson-single' != $page ){ |
|
544 | + if (empty($current_user->caps) && Sensei()->settings->get('access_permission') |
|
545 | + && 'lesson-single' != $page) { |
|
546 | 546 | |
547 | - $this->permissions_message['title'] = __('Restricted Access', 'woothemes-sensei' ); |
|
548 | - $this->permissions_message['message'] = sprintf( __('You must be logged in to view this %s'), get_post_type() ); |
|
547 | + $this->permissions_message['title'] = __('Restricted Access', 'woothemes-sensei'); |
|
548 | + $this->permissions_message['message'] = sprintf(__('You must be logged in to view this %s'), get_post_type()); |
|
549 | 549 | |
550 | 550 | return false; |
551 | 551 | } |
552 | 552 | |
553 | 553 | $user_allowed = false; |
554 | 554 | |
555 | - switch ( $page ) { |
|
555 | + switch ($page) { |
|
556 | 556 | case 'course-single': |
557 | 557 | // check for prerequisite course or lesson, |
558 | - $course_prerequisite_id = (int) get_post_meta( $post->ID, '_course_prerequisite', true); |
|
559 | - $update_course = Sensei_WC::course_update( $post->ID ); |
|
558 | + $course_prerequisite_id = (int) get_post_meta($post->ID, '_course_prerequisite', true); |
|
559 | + $update_course = Sensei_WC::course_update($post->ID); |
|
560 | 560 | // Count completed lessons |
561 | - if ( 0 < absint( $course_prerequisite_id ) ) { |
|
561 | + if (0 < absint($course_prerequisite_id)) { |
|
562 | 562 | |
563 | - $prerequisite_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, $current_user->ID ); |
|
563 | + $prerequisite_complete = Sensei_Utils::user_completed_course($course_prerequisite_id, $current_user->ID); |
|
564 | 564 | |
565 | 565 | } |
566 | 566 | else { |
567 | 567 | $prerequisite_complete = true; |
568 | 568 | } // End If Statement |
569 | 569 | // Handles restrictions |
570 | - if ( !$prerequisite_complete && 0 < absint( $course_prerequisite_id ) ) { |
|
571 | - $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
572 | - $course_link = '<a href="' . esc_url( get_permalink( $course_prerequisite_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
573 | - $this->permissions_message['message'] = sprintf( __('Please complete the previous %1$s before taking this course.', 'woothemes-sensei' ), $course_link ); |
|
570 | + if ( ! $prerequisite_complete && 0 < absint($course_prerequisite_id)) { |
|
571 | + $this->permissions_message['title'] = get_the_title($post->ID).': '.__('Restricted Access', 'woothemes-sensei'); |
|
572 | + $course_link = '<a href="'.esc_url(get_permalink($course_prerequisite_id)).'">'.__('course', 'woothemes-sensei').'</a>'; |
|
573 | + $this->permissions_message['message'] = sprintf(__('Please complete the previous %1$s before taking this course.', 'woothemes-sensei'), $course_link); |
|
574 | 574 | } else { |
575 | 575 | $user_allowed = true; |
576 | 576 | } // End If Statement |
577 | 577 | break; |
578 | 578 | case 'lesson-single': |
579 | 579 | // Check for WC purchase |
580 | - $lesson_course_id = get_post_meta( $post->ID, '_lesson_course',true ); |
|
580 | + $lesson_course_id = get_post_meta($post->ID, '_lesson_course', true); |
|
581 | 581 | |
582 | - $update_course = Sensei_WC::course_update( $lesson_course_id ); |
|
583 | - $is_preview = Sensei_Utils::is_preview_lesson( $post->ID ); |
|
582 | + $update_course = Sensei_WC::course_update($lesson_course_id); |
|
583 | + $is_preview = Sensei_Utils::is_preview_lesson($post->ID); |
|
584 | 584 | |
585 | - if ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) { |
|
585 | + if ($this->access_settings() && Sensei_Utils::user_started_course($lesson_course_id, $current_user->ID)) { |
|
586 | 586 | $user_allowed = true; |
587 | - } elseif( $this->access_settings() && false == $is_preview ) { |
|
587 | + } elseif ($this->access_settings() && false == $is_preview) { |
|
588 | 588 | |
589 | 589 | $user_allowed = true; |
590 | 590 | |
591 | 591 | } else { |
592 | - $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
593 | - $course_link = '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
594 | - $wc_post_id = get_post_meta( $lesson_course_id, '_course_woocommerce_product',true ); |
|
595 | - if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) { |
|
596 | - if ( $is_preview ) { |
|
597 | - $this->permissions_message['message'] = sprintf( __('This is a preview lesson. Please purchase the %1$s to access all lessons.', 'woothemes-sensei' ), $course_link ); |
|
592 | + $this->permissions_message['title'] = get_the_title($post->ID).': '.__('Restricted Access', 'woothemes-sensei'); |
|
593 | + $course_link = '<a href="'.esc_url(get_permalink($lesson_course_id)).'">'.__('course', 'woothemes-sensei').'</a>'; |
|
594 | + $wc_post_id = get_post_meta($lesson_course_id, '_course_woocommerce_product', true); |
|
595 | + if (Sensei_WC::is_woocommerce_active() && (0 < $wc_post_id)) { |
|
596 | + if ($is_preview) { |
|
597 | + $this->permissions_message['message'] = sprintf(__('This is a preview lesson. Please purchase the %1$s to access all lessons.', 'woothemes-sensei'), $course_link); |
|
598 | 598 | } else { |
599 | - $this->permissions_message['message'] = sprintf( __('Please purchase the %1$s before starting this Lesson.', 'woothemes-sensei' ), $course_link ); |
|
599 | + $this->permissions_message['message'] = sprintf(__('Please purchase the %1$s before starting this Lesson.', 'woothemes-sensei'), $course_link); |
|
600 | 600 | } |
601 | 601 | } else { |
602 | - if ( $is_preview ) { |
|
603 | - $this->permissions_message['message'] = sprintf( __('This is a preview lesson. Please sign up for the %1$s to access all lessons.', 'woothemes-sensei' ), $course_link ); |
|
602 | + if ($is_preview) { |
|
603 | + $this->permissions_message['message'] = sprintf(__('This is a preview lesson. Please sign up for the %1$s to access all lessons.', 'woothemes-sensei'), $course_link); |
|
604 | 604 | } else { |
605 | 605 | /** This filter is documented in class-woothemes-sensei-frontend.php */ |
606 | - $this->permissions_message['message'] = sprintf( __( 'Please sign up for the %1$s before starting the lesson.', 'woothemes-sensei' ), $course_link ); |
|
606 | + $this->permissions_message['message'] = sprintf(__('Please sign up for the %1$s before starting the lesson.', 'woothemes-sensei'), $course_link); |
|
607 | 607 | } |
608 | 608 | } // End If Statement |
609 | 609 | } // End If Statement |
610 | 610 | break; |
611 | 611 | case 'quiz-single': |
612 | - $lesson_id = get_post_meta( $post->ID, '_quiz_lesson',true ); |
|
613 | - $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course',true ); |
|
612 | + $lesson_id = get_post_meta($post->ID, '_quiz_lesson', true); |
|
613 | + $lesson_course_id = get_post_meta($lesson_id, '_lesson_course', true); |
|
614 | 614 | |
615 | - $update_course = Sensei_WC::course_update( $lesson_course_id ); |
|
616 | - if ( ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) || sensei_all_access() ) { |
|
615 | + $update_course = Sensei_WC::course_update($lesson_course_id); |
|
616 | + if (($this->access_settings() && Sensei_Utils::user_started_course($lesson_course_id, $current_user->ID)) || sensei_all_access()) { |
|
617 | 617 | |
618 | 618 | // Check for prerequisite lesson for this quiz |
619 | - $lesson_prerequisite_id = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true); |
|
620 | - $user_lesson_prerequisite_complete = Sensei_Utils::user_completed_lesson( $lesson_prerequisite_id, $current_user->ID); |
|
619 | + $lesson_prerequisite_id = (int) get_post_meta($lesson_id, '_lesson_prerequisite', true); |
|
620 | + $user_lesson_prerequisite_complete = Sensei_Utils::user_completed_lesson($lesson_prerequisite_id, $current_user->ID); |
|
621 | 621 | |
622 | 622 | // Handle restrictions |
623 | - if( sensei_all_access() ) { |
|
623 | + if (sensei_all_access()) { |
|
624 | 624 | |
625 | 625 | $user_allowed = true; |
626 | 626 | |
627 | 627 | } else { |
628 | 628 | |
629 | - if ( 0 < absint( $lesson_prerequisite_id ) && ( !$user_lesson_prerequisite_complete ) ) { |
|
629 | + if (0 < absint($lesson_prerequisite_id) && ( ! $user_lesson_prerequisite_complete)) { |
|
630 | 630 | |
631 | - $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
632 | - $lesson_link = '<a href="' . esc_url( get_permalink( $lesson_prerequisite_id ) ) . '">' . __( 'lesson', 'woothemes-sensei' ) . '</a>'; |
|
633 | - $this->permissions_message['message'] = sprintf( __('Please complete the previous %1$s before taking this Quiz.', 'woothemes-sensei' ), $lesson_link ); |
|
631 | + $this->permissions_message['title'] = get_the_title($post->ID).': '.__('Restricted Access', 'woothemes-sensei'); |
|
632 | + $lesson_link = '<a href="'.esc_url(get_permalink($lesson_prerequisite_id)).'">'.__('lesson', 'woothemes-sensei').'</a>'; |
|
633 | + $this->permissions_message['message'] = sprintf(__('Please complete the previous %1$s before taking this Quiz.', 'woothemes-sensei'), $lesson_link); |
|
634 | 634 | |
635 | 635 | } else { |
636 | 636 | |
@@ -638,27 +638,27 @@ discard block |
||
638 | 638 | |
639 | 639 | } // End If Statement |
640 | 640 | } // End If Statement |
641 | - } elseif( $this->access_settings() ) { |
|
641 | + } elseif ($this->access_settings()) { |
|
642 | 642 | // Check if the user has started the course |
643 | 643 | |
644 | - if ( is_user_logged_in() && ! Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) && ( isset( $this->settings->settings['access_permission'] ) && ( true == $this->settings->settings['access_permission'] ) ) ) { |
|
644 | + if (is_user_logged_in() && ! Sensei_Utils::user_started_course($lesson_course_id, $current_user->ID) && (isset($this->settings->settings['access_permission']) && (true == $this->settings->settings['access_permission']))) { |
|
645 | 645 | |
646 | 646 | $user_allowed = false; |
647 | - $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
648 | - $course_link = '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
649 | - $wc_post_id = get_post_meta( $lesson_course_id, '_course_woocommerce_product',true ); |
|
650 | - if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) { |
|
651 | - $this->permissions_message['message'] = sprintf( __('Please purchase the %1$s before starting this Quiz.', 'woothemes-sensei' ), $course_link ); |
|
647 | + $this->permissions_message['title'] = get_the_title($post->ID).': '.__('Restricted Access', 'woothemes-sensei'); |
|
648 | + $course_link = '<a href="'.esc_url(get_permalink($lesson_course_id)).'">'.__('course', 'woothemes-sensei').'</a>'; |
|
649 | + $wc_post_id = get_post_meta($lesson_course_id, '_course_woocommerce_product', true); |
|
650 | + if (Sensei_WC::is_woocommerce_active() && (0 < $wc_post_id)) { |
|
651 | + $this->permissions_message['message'] = sprintf(__('Please purchase the %1$s before starting this Quiz.', 'woothemes-sensei'), $course_link); |
|
652 | 652 | } else { |
653 | - $this->permissions_message['message'] = sprintf( __('Please sign up for the %1$s before starting this Quiz.', 'woothemes-sensei' ), $course_link ); |
|
653 | + $this->permissions_message['message'] = sprintf(__('Please sign up for the %1$s before starting this Quiz.', 'woothemes-sensei'), $course_link); |
|
654 | 654 | } // End If Statement |
655 | 655 | } else { |
656 | 656 | $user_allowed = true; |
657 | 657 | } // End If Statement |
658 | 658 | } else { |
659 | - $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
660 | - $course_link = '<a href="' . esc_url( get_permalink( get_post_meta( get_post_meta( $post->ID, '_quiz_lesson', true ), '_lesson_course', true ) ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
661 | - $this->permissions_message['message'] = sprintf( __('Please sign up for the %1$s before taking this Quiz.', 'woothemes-sensei' ), $course_link ); |
|
659 | + $this->permissions_message['title'] = get_the_title($post->ID).': '.__('Restricted Access', 'woothemes-sensei'); |
|
660 | + $course_link = '<a href="'.esc_url(get_permalink(get_post_meta(get_post_meta($post->ID, '_quiz_lesson', true), '_lesson_course', true))).'">'.__('course', 'woothemes-sensei').'</a>'; |
|
661 | + $this->permissions_message['message'] = sprintf(__('Please sign up for the %1$s before taking this Quiz.', 'woothemes-sensei'), $course_link); |
|
662 | 662 | } // End If Statement |
663 | 663 | break; |
664 | 664 | default: |
@@ -680,10 +680,10 @@ discard block |
||
680 | 680 | * } |
681 | 681 | * @param string $post_id |
682 | 682 | */ |
683 | - $this->permissions_message = apply_filters( 'sensei_permissions_message', $this->permissions_message, $post->ID ); |
|
683 | + $this->permissions_message = apply_filters('sensei_permissions_message', $this->permissions_message, $post->ID); |
|
684 | 684 | |
685 | 685 | |
686 | - if( sensei_all_access() || Sensei_Utils::is_preview_lesson( $post->ID ) ) { |
|
686 | + if (sensei_all_access() || Sensei_Utils::is_preview_lesson($post->ID)) { |
|
687 | 687 | $user_allowed = true; |
688 | 688 | } |
689 | 689 | |
@@ -697,7 +697,7 @@ discard block |
||
697 | 697 | * @param integer $user_id |
698 | 698 | * |
699 | 699 | */ |
700 | - return apply_filters( 'sensei_access_permissions', $user_allowed, $current_user->ID ); |
|
700 | + return apply_filters('sensei_access_permissions', $user_allowed, $current_user->ID); |
|
701 | 701 | |
702 | 702 | } // End get_placeholder_image() |
703 | 703 | |
@@ -708,12 +708,12 @@ discard block |
||
708 | 708 | * @access public |
709 | 709 | * @return bool |
710 | 710 | */ |
711 | - public function access_settings () { |
|
711 | + public function access_settings() { |
|
712 | 712 | |
713 | - if( sensei_all_access() ) return true; |
|
713 | + if (sensei_all_access()) return true; |
|
714 | 714 | |
715 | - if ( isset( $this->settings->settings['access_permission'] ) && ( true == $this->settings->settings['access_permission'] ) ) { |
|
716 | - if ( is_user_logged_in() ) { |
|
715 | + if (isset($this->settings->settings['access_permission']) && (true == $this->settings->settings['access_permission'])) { |
|
716 | + if (is_user_logged_in()) { |
|
717 | 717 | return true; |
718 | 718 | } else { |
719 | 719 | return false; |
@@ -729,9 +729,9 @@ discard block |
||
729 | 729 | * @access public |
730 | 730 | * @return void |
731 | 731 | */ |
732 | - public function load_class ( $class_name = '' ) { |
|
733 | - if ( '' != $class_name && '' != $this->token ) { |
|
734 | - require_once( 'class-' . esc_attr( $this->token ) . '-' . esc_attr( $class_name ) . '.php' ); |
|
732 | + public function load_class($class_name = '') { |
|
733 | + if ('' != $class_name && '' != $this->token) { |
|
734 | + require_once('class-'.esc_attr($this->token).'-'.esc_attr($class_name).'.php'); |
|
735 | 735 | } // End If Statement |
736 | 736 | } // End load_class() |
737 | 737 | |
@@ -743,44 +743,44 @@ discard block |
||
743 | 743 | * @param integer $post_id |
744 | 744 | * @return array |
745 | 745 | */ |
746 | - public function sensei_count_comments( $comments, $post_id ) { |
|
746 | + public function sensei_count_comments($comments, $post_id) { |
|
747 | 747 | global $wpdb; |
748 | 748 | |
749 | 749 | $post_id = (int) $post_id; |
750 | 750 | |
751 | 751 | $count = wp_cache_get("comments-{$post_id}", 'counts'); |
752 | 752 | |
753 | - if ( false !== $count ) { |
|
753 | + if (false !== $count) { |
|
754 | 754 | return $count; |
755 | 755 | } |
756 | 756 | |
757 | - $statuses = array( '' ); // Default to the WP normal comments |
|
758 | - $stati = $wpdb->get_results( "SELECT comment_type FROM {$wpdb->comments} GROUP BY comment_type", ARRAY_A ); |
|
759 | - foreach ( (array) $stati AS $status ) { |
|
760 | - if ( 'sensei_' != substr($status['comment_type'], 0, 7 ) ) { |
|
757 | + $statuses = array(''); // Default to the WP normal comments |
|
758 | + $stati = $wpdb->get_results("SELECT comment_type FROM {$wpdb->comments} GROUP BY comment_type", ARRAY_A); |
|
759 | + foreach ((array) $stati AS $status) { |
|
760 | + if ('sensei_' != substr($status['comment_type'], 0, 7)) { |
|
761 | 761 | $statuses[] = $status['comment_type']; |
762 | 762 | } |
763 | 763 | } |
764 | - $where = "WHERE comment_type IN ('" . join("', '", array_unique( $statuses ) ) . "')"; |
|
764 | + $where = "WHERE comment_type IN ('".join("', '", array_unique($statuses))."')"; |
|
765 | 765 | |
766 | - if ( $post_id > 0 ) |
|
767 | - $where .= $wpdb->prepare( " AND comment_post_ID = %d", $post_id ); |
|
766 | + if ($post_id > 0) |
|
767 | + $where .= $wpdb->prepare(" AND comment_post_ID = %d", $post_id); |
|
768 | 768 | |
769 | - $count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A ); |
|
769 | + $count = $wpdb->get_results("SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A); |
|
770 | 770 | |
771 | 771 | $total = 0; |
772 | 772 | $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash', 'post-trashed' => 'post-trashed'); |
773 | - foreach ( (array) $count as $row ) { |
|
773 | + foreach ((array) $count as $row) { |
|
774 | 774 | // Don't count post-trashed toward totals |
775 | - if ( 'post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'] ) |
|
775 | + if ('post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved']) |
|
776 | 776 | $total += $row['num_comments']; |
777 | - if ( isset( $approved[$row['comment_approved']] ) ) |
|
777 | + if (isset($approved[$row['comment_approved']])) |
|
778 | 778 | $stats[$approved[$row['comment_approved']]] = $row['num_comments']; |
779 | 779 | } |
780 | 780 | |
781 | 781 | $stats['total_comments'] = $total; |
782 | - foreach ( $approved as $key ) { |
|
783 | - if ( empty($stats[$key]) ) |
|
782 | + foreach ($approved as $key) { |
|
783 | + if (empty($stats[$key])) |
|
784 | 784 | $stats[$key] = 0; |
785 | 785 | } |
786 | 786 | |
@@ -798,15 +798,15 @@ discard block |
||
798 | 798 | * @return void |
799 | 799 | */ |
800 | 800 | public function init_image_sizes() { |
801 | - $course_archive_thumbnail = $this->get_image_size( 'course_archive_image' ); |
|
802 | - $course_single_thumbnail = $this->get_image_size( 'course_single_image' ); |
|
803 | - $lesson_archive_thumbnail = $this->get_image_size( 'lesson_archive_image' ); |
|
804 | - $lesson_single_thumbnail = $this->get_image_size( 'lesson_single_image' ); |
|
805 | - |
|
806 | - add_image_size( 'course_archive_thumbnail', $course_archive_thumbnail['width'], $course_archive_thumbnail['height'], $course_archive_thumbnail['crop'] ); |
|
807 | - add_image_size( 'course_single_thumbnail', $course_single_thumbnail['width'], $course_single_thumbnail['height'], $course_single_thumbnail['crop'] ); |
|
808 | - add_image_size( 'lesson_archive_thumbnail', $lesson_archive_thumbnail['width'], $lesson_archive_thumbnail['height'], $lesson_archive_thumbnail['crop'] ); |
|
809 | - add_image_size( 'lesson_single_thumbnail', $lesson_single_thumbnail['width'], $lesson_single_thumbnail['height'], $lesson_single_thumbnail['crop'] ); |
|
801 | + $course_archive_thumbnail = $this->get_image_size('course_archive_image'); |
|
802 | + $course_single_thumbnail = $this->get_image_size('course_single_image'); |
|
803 | + $lesson_archive_thumbnail = $this->get_image_size('lesson_archive_image'); |
|
804 | + $lesson_single_thumbnail = $this->get_image_size('lesson_single_image'); |
|
805 | + |
|
806 | + add_image_size('course_archive_thumbnail', $course_archive_thumbnail['width'], $course_archive_thumbnail['height'], $course_archive_thumbnail['crop']); |
|
807 | + add_image_size('course_single_thumbnail', $course_single_thumbnail['width'], $course_single_thumbnail['height'], $course_single_thumbnail['crop']); |
|
808 | + add_image_size('lesson_archive_thumbnail', $lesson_archive_thumbnail['width'], $lesson_archive_thumbnail['height'], $lesson_archive_thumbnail['crop']); |
|
809 | + add_image_size('lesson_single_thumbnail', $lesson_single_thumbnail['width'], $lesson_single_thumbnail['height'], $lesson_single_thumbnail['crop']); |
|
810 | 810 | } |
811 | 811 | |
812 | 812 | /** |
@@ -819,37 +819,37 @@ discard block |
||
819 | 819 | * @param mixed $image_size |
820 | 820 | * @return string |
821 | 821 | */ |
822 | - public function get_image_size( $image_size ) { |
|
822 | + public function get_image_size($image_size) { |
|
823 | 823 | |
824 | 824 | // Only return sizes we define in settings |
825 | - if ( ! in_array( $image_size, array( 'course_archive_image', 'course_single_image', 'lesson_archive_image', 'lesson_single_image' ) ) ) |
|
826 | - return apply_filters( 'sensei_get_image_size_' . $image_size, '' ); |
|
825 | + if ( ! in_array($image_size, array('course_archive_image', 'course_single_image', 'lesson_archive_image', 'lesson_single_image'))) |
|
826 | + return apply_filters('sensei_get_image_size_'.$image_size, ''); |
|
827 | 827 | |
828 | - if( ! isset( $this->settings->settings[ $image_size . '_width' ] ) ) { |
|
829 | - $this->settings->settings[ $image_size . '_width' ] = false; |
|
828 | + if ( ! isset($this->settings->settings[$image_size.'_width'])) { |
|
829 | + $this->settings->settings[$image_size.'_width'] = false; |
|
830 | 830 | } |
831 | - if( ! isset( $this->settings->settings[ $image_size . '_height' ] ) ) { |
|
832 | - $this->settings->settings[ $image_size . '_height' ] = false; |
|
831 | + if ( ! isset($this->settings->settings[$image_size.'_height'])) { |
|
832 | + $this->settings->settings[$image_size.'_height'] = false; |
|
833 | 833 | } |
834 | - if( ! isset( $this->settings->settings[ $image_size . '_hard_crop' ] ) ) { |
|
835 | - $this->settings->settings[ $image_size . '_hard_crop' ] = false; |
|
834 | + if ( ! isset($this->settings->settings[$image_size.'_hard_crop'])) { |
|
835 | + $this->settings->settings[$image_size.'_hard_crop'] = false; |
|
836 | 836 | } |
837 | 837 | |
838 | - $size = array_filter( array( |
|
839 | - 'width' => $this->settings->settings[ $image_size . '_width' ], |
|
840 | - 'height' => $this->settings->settings[ $image_size . '_height' ], |
|
841 | - 'crop' => $this->settings->settings[ $image_size . '_hard_crop' ] |
|
842 | - ) ); |
|
838 | + $size = array_filter(array( |
|
839 | + 'width' => $this->settings->settings[$image_size.'_width'], |
|
840 | + 'height' => $this->settings->settings[$image_size.'_height'], |
|
841 | + 'crop' => $this->settings->settings[$image_size.'_hard_crop'] |
|
842 | + )); |
|
843 | 843 | |
844 | - $size['width'] = isset( $size['width'] ) ? $size['width'] : '100'; |
|
845 | - $size['height'] = isset( $size['height'] ) ? $size['height'] : '100'; |
|
846 | - $size['crop'] = isset( $size['crop'] ) ? $size['crop'] : 0; |
|
844 | + $size['width'] = isset($size['width']) ? $size['width'] : '100'; |
|
845 | + $size['height'] = isset($size['height']) ? $size['height'] : '100'; |
|
846 | + $size['crop'] = isset($size['crop']) ? $size['crop'] : 0; |
|
847 | 847 | |
848 | - return apply_filters( 'sensei_get_image_size_' . $image_size, $size ); |
|
848 | + return apply_filters('sensei_get_image_size_'.$image_size, $size); |
|
849 | 849 | } |
850 | 850 | |
851 | - public function body_class( $classes ) { |
|
852 | - if( is_sensei() ) { |
|
851 | + public function body_class($classes) { |
|
852 | + if (is_sensei()) { |
|
853 | 853 | $classes[] = 'sensei'; |
854 | 854 | } |
855 | 855 | return $classes; |
@@ -862,9 +862,9 @@ discard block |
||
862 | 862 | * @since 1.7.0 |
863 | 863 | */ |
864 | 864 | public function jetpack_latex_support() { |
865 | - if ( function_exists( 'latex_markup') ) { |
|
866 | - add_filter( 'sensei_question_title', 'latex_markup' ); |
|
867 | - add_filter( 'sensei_answer_text', 'latex_markup' ); |
|
865 | + if (function_exists('latex_markup')) { |
|
866 | + add_filter('sensei_question_title', 'latex_markup'); |
|
867 | + add_filter('sensei_answer_text', 'latex_markup'); |
|
868 | 868 | } |
869 | 869 | } |
870 | 870 | |
@@ -876,21 +876,21 @@ discard block |
||
876 | 876 | * |
877 | 877 | * @since 1.8.0 |
878 | 878 | */ |
879 | - public function load_modules_class(){ |
|
879 | + public function load_modules_class() { |
|
880 | 880 | global $sensei_modules; |
881 | 881 | |
882 | - if( !class_exists( 'Sensei_Modules' ) |
|
883 | - && 'Sensei_Modules' != get_class( $sensei_modules ) ) { |
|
882 | + if ( ! class_exists('Sensei_Modules') |
|
883 | + && 'Sensei_Modules' != get_class($sensei_modules)) { |
|
884 | 884 | |
885 | 885 | //Load the modules class |
886 | - require_once( 'class-sensei-modules.php'); |
|
887 | - Sensei()->modules = new Sensei_Core_Modules( $this->file ); |
|
886 | + require_once('class-sensei-modules.php'); |
|
887 | + Sensei()->modules = new Sensei_Core_Modules($this->file); |
|
888 | 888 | |
889 | - }else{ |
|
889 | + } else { |
|
890 | 890 | // fallback for people still using the modules extension. |
891 | 891 | global $sensei_modules; |
892 | 892 | Sensei()->modules = $sensei_modules; |
893 | - add_action( 'admin_notices', array( $this, 'disable_sensei_modules_extension'), 30 ); |
|
893 | + add_action('admin_notices', array($this, 'disable_sensei_modules_extension'), 30); |
|
894 | 894 | } |
895 | 895 | } |
896 | 896 | |
@@ -899,12 +899,12 @@ discard block |
||
899 | 899 | * |
900 | 900 | * @since 1.8.0 |
901 | 901 | */ |
902 | - public function disable_sensei_modules_extension(){ ?> |
|
902 | + public function disable_sensei_modules_extension() { ?> |
|
903 | 903 | <div class="notice updated fade"> |
904 | 904 | <p> |
905 | 905 | <?php |
906 | 906 | $plugin_manage_url = admin_url().'plugins.php#sensei-modules'; |
907 | - $plugin_link_element = '<a href="' . $plugin_manage_url . '" >plugins page</a> '; |
|
907 | + $plugin_link_element = '<a href="'.$plugin_manage_url.'" >plugins page</a> '; |
|
908 | 908 | ?> |
909 | 909 | <strong> Modules are now included in Sensei,</strong> so you no longer need the Sensei Modules extension. |
910 | 910 | Please deactivate and delete it from your <?php echo $plugin_link_element; ?>. (This will not affect your existing modules). |
@@ -922,18 +922,18 @@ discard block |
||
922 | 922 | * |
923 | 923 | * @since 1.9.0 |
924 | 924 | */ |
925 | - public function flush_rewrite_rules(){ |
|
925 | + public function flush_rewrite_rules() { |
|
926 | 926 | |
927 | 927 | // ensures that the rewrite rules are flushed on the second |
928 | 928 | // attempt. This ensure that the settings for any other process |
929 | 929 | // have been completed and saved to the database before we refresh the |
930 | 930 | // rewrite rules. |
931 | - $option = get_option('sensei_flush_rewrite_rules'); |
|
932 | - if( '1' == $option ) { |
|
931 | + $option = get_option('sensei_flush_rewrite_rules'); |
|
932 | + if ('1' == $option) { |
|
933 | 933 | |
934 | 934 | update_option('sensei_flush_rewrite_rules', '2'); |
935 | 935 | |
936 | - }elseif( '2' == $option ) { |
|
936 | + }elseif ('2' == $option) { |
|
937 | 937 | |
938 | 938 | flush_rewrite_rules(); |
939 | 939 | update_option('sensei_flush_rewrite_rules', '0'); |
@@ -948,7 +948,7 @@ discard block |
||
948 | 948 | * |
949 | 949 | * @since 1.9.0 |
950 | 950 | */ |
951 | - public function initiate_rewrite_rules_flush(){ |
|
951 | + public function initiate_rewrite_rules_flush() { |
|
952 | 952 | |
953 | 953 | update_option('sensei_flush_rewrite_rules', '1'); |
954 | 954 | |
@@ -965,9 +965,9 @@ discard block |
||
965 | 965 | * |
966 | 966 | * @return void |
967 | 967 | */ |
968 | - public function sensei_woocommerce_email_course_details( $order ) { |
|
968 | + public function sensei_woocommerce_email_course_details($order) { |
|
969 | 969 | |
970 | - Sensei_WC::email_course_details( $order ); |
|
970 | + Sensei_WC::email_course_details($order); |
|
971 | 971 | |
972 | 972 | } // end func email course details |
973 | 973 | |
@@ -976,9 +976,9 @@ discard block |
||
976 | 976 | * @param $user_id |
977 | 977 | * @param $subscription_key |
978 | 978 | */ |
979 | - public function sensei_woocommerce_reactivate_subscription( $user_id, $subscription_key ){ |
|
979 | + public function sensei_woocommerce_reactivate_subscription($user_id, $subscription_key) { |
|
980 | 980 | |
981 | - Sensei_WC::reactivate_subscription( $user_id, $subscription_key ); |
|
981 | + Sensei_WC::reactivate_subscription($user_id, $subscription_key); |
|
982 | 982 | } |
983 | 983 | |
984 | 984 | /** |
@@ -986,9 +986,9 @@ discard block |
||
986 | 986 | * @param $user_id |
987 | 987 | * @param $subscription_key |
988 | 988 | */ |
989 | - public function sensei_woocommerce_subscription_ended( $user_id, $subscription_key ){ |
|
989 | + public function sensei_woocommerce_subscription_ended($user_id, $subscription_key) { |
|
990 | 990 | |
991 | - Sensei_WC::end_subscription( $user_id, $subscription_key ); |
|
991 | + Sensei_WC::end_subscription($user_id, $subscription_key); |
|
992 | 992 | } |
993 | 993 | |
994 | 994 | /** |
@@ -1001,9 +1001,9 @@ discard block |
||
1001 | 1001 | * |
1002 | 1002 | * @return void |
1003 | 1003 | */ |
1004 | - public function sensei_woocommerce_complete_order ( $order_id = 0 ) { |
|
1004 | + public function sensei_woocommerce_complete_order($order_id = 0) { |
|
1005 | 1005 | |
1006 | - Sensei_WC::complete_order( $order_id ); |
|
1006 | + Sensei_WC::complete_order($order_id); |
|
1007 | 1007 | |
1008 | 1008 | } // End sensei_woocommerce_complete_order() |
1009 | 1009 | |
@@ -1016,9 +1016,9 @@ discard block |
||
1016 | 1016 | * @param integer $order_id order ID |
1017 | 1017 | * @return void |
1018 | 1018 | */ |
1019 | - public function sensei_woocommerce_cancel_order ( $order_id ) { |
|
1019 | + public function sensei_woocommerce_cancel_order($order_id) { |
|
1020 | 1020 | |
1021 | - Sensei_WC::cancel_order( $order_id ); |
|
1021 | + Sensei_WC::cancel_order($order_id); |
|
1022 | 1022 | |
1023 | 1023 | } // End sensei_woocommerce_cancel_order() |
1024 | 1024 | |
@@ -1030,9 +1030,9 @@ discard block |
||
1030 | 1030 | * @param integer $order_id order ID |
1031 | 1031 | * @return void |
1032 | 1032 | */ |
1033 | - public function sensei_activate_subscription( $order_id = 0 ) { |
|
1033 | + public function sensei_activate_subscription($order_id = 0) { |
|
1034 | 1034 | |
1035 | - Sensei_WC::activate_subscription( $order_id ); |
|
1035 | + Sensei_WC::activate_subscription($order_id); |
|
1036 | 1036 | |
1037 | 1037 | } // End sensei_activate_subscription() |
1038 | 1038 | |
@@ -1044,9 +1044,9 @@ discard block |
||
1044 | 1044 | * @param array/Object $order_user (default: array()) Specific user's data. |
1045 | 1045 | * @return bool|int |
1046 | 1046 | */ |
1047 | - public function woocommerce_course_update ( $course_id = 0, $order_user = array() ) { |
|
1047 | + public function woocommerce_course_update($course_id = 0, $order_user = array()) { |
|
1048 | 1048 | |
1049 | - return Sensei_WC::course_update( $course_id, $order_user ); |
|
1049 | + return Sensei_WC::course_update($course_id, $order_user); |
|
1050 | 1050 | |
1051 | 1051 | } // End woocommerce_course_update() |
1052 | 1052 | |
@@ -1063,9 +1063,9 @@ discard block |
||
1063 | 1063 | * |
1064 | 1064 | * @return WC_Product $wc_product_object |
1065 | 1065 | */ |
1066 | - public function sensei_get_woocommerce_product_object ( $wc_product_id = 0, $product_type = '' ) { |
|
1066 | + public function sensei_get_woocommerce_product_object($wc_product_id = 0, $product_type = '') { |
|
1067 | 1067 | |
1068 | - return Sensei_WC::get_product_object( $wc_product_id, $product_type ); |
|
1068 | + return Sensei_WC::get_product_object($wc_product_id, $product_type); |
|
1069 | 1069 | |
1070 | 1070 | } // End sensei_get_woocommerce_product_object() |
1071 | 1071 | |
@@ -1087,9 +1087,9 @@ discard block |
||
1087 | 1087 | * @param boolean $guest_checkout Current guest checkout setting |
1088 | 1088 | * @return boolean Modified guest checkout setting |
1089 | 1089 | */ |
1090 | - public function disable_guest_checkout( $guest_checkout ) { |
|
1090 | + public function disable_guest_checkout($guest_checkout) { |
|
1091 | 1091 | |
1092 | - return Sensei_WC::disable_guest_checkout( $guest_checkout ); |
|
1092 | + return Sensei_WC::disable_guest_checkout($guest_checkout); |
|
1093 | 1093 | |
1094 | 1094 | }// end disable_guest_checkout |
1095 | 1095 | |
@@ -1103,9 +1103,9 @@ discard block |
||
1103 | 1103 | * @param int $order_id |
1104 | 1104 | * @return string |
1105 | 1105 | **/ |
1106 | - public function virtual_order_payment_complete( $order_status, $order_id ) { |
|
1106 | + public function virtual_order_payment_complete($order_status, $order_id) { |
|
1107 | 1107 | |
1108 | - return Sensei_WC::virtual_order_payment_complete( $order_status, $order_id ); |
|
1108 | + return Sensei_WC::virtual_order_payment_complete($order_status, $order_id); |
|
1109 | 1109 | } |
1110 | 1110 | |
1111 | 1111 | } // End Class |
@@ -1115,4 +1115,4 @@ discard block |
||
1115 | 1115 | * @ignore only for backward compatibility |
1116 | 1116 | * @since 1.9.0 |
1117 | 1117 | */ |
1118 | -class Woothemes_Sensei extends Sensei_Main{ } |
|
1118 | +class Woothemes_Sensei extends Sensei_Main { } |
@@ -1,5 +1,8 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
3 | + exit; |
|
4 | +} |
|
5 | +// Exit if accessed directly |
|
3 | 6 | |
4 | 7 | /** |
5 | 8 | * Responsible for loading Sensei and setting up the Main WordPress hooks. |
@@ -155,7 +158,9 @@ discard block |
||
155 | 158 | $this->init(); |
156 | 159 | |
157 | 160 | // Installation |
158 | - if ( is_admin() && ! defined( 'DOING_AJAX' ) ) $this->install(); |
|
161 | + if ( is_admin() && ! defined( 'DOING_AJAX' ) ) { |
|
162 | + $this->install(); |
|
163 | + } |
|
159 | 164 | |
160 | 165 | // Run this on activation. |
161 | 166 | register_activation_hook( $this->file, array( $this, 'activation' ) ); |
@@ -506,7 +511,7 @@ discard block |
||
506 | 511 | |
507 | 512 | $sensei_plugin_path = $this->plugin_path; |
508 | 513 | |
509 | - }else{ |
|
514 | + } else{ |
|
510 | 515 | |
511 | 516 | $sensei_plugin_path = plugin_dir_path( __FILE__ ); |
512 | 517 | |
@@ -562,8 +567,7 @@ discard block |
||
562 | 567 | |
563 | 568 | $prerequisite_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, $current_user->ID ); |
564 | 569 | |
565 | - } |
|
566 | - else { |
|
570 | + } else { |
|
567 | 571 | $prerequisite_complete = true; |
568 | 572 | } // End If Statement |
569 | 573 | // Handles restrictions |
@@ -710,7 +714,9 @@ discard block |
||
710 | 714 | */ |
711 | 715 | public function access_settings () { |
712 | 716 | |
713 | - if( sensei_all_access() ) return true; |
|
717 | + if( sensei_all_access() ) { |
|
718 | + return true; |
|
719 | + } |
|
714 | 720 | |
715 | 721 | if ( isset( $this->settings->settings['access_permission'] ) && ( true == $this->settings->settings['access_permission'] ) ) { |
716 | 722 | if ( is_user_logged_in() ) { |
@@ -763,8 +769,9 @@ discard block |
||
763 | 769 | } |
764 | 770 | $where = "WHERE comment_type IN ('" . join("', '", array_unique( $statuses ) ) . "')"; |
765 | 771 | |
766 | - if ( $post_id > 0 ) |
|
767 | - $where .= $wpdb->prepare( " AND comment_post_ID = %d", $post_id ); |
|
772 | + if ( $post_id > 0 ) { |
|
773 | + $where .= $wpdb->prepare( " AND comment_post_ID = %d", $post_id ); |
|
774 | + } |
|
768 | 775 | |
769 | 776 | $count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A ); |
770 | 777 | |
@@ -772,16 +779,19 @@ discard block |
||
772 | 779 | $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash', 'post-trashed' => 'post-trashed'); |
773 | 780 | foreach ( (array) $count as $row ) { |
774 | 781 | // Don't count post-trashed toward totals |
775 | - if ( 'post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'] ) |
|
776 | - $total += $row['num_comments']; |
|
777 | - if ( isset( $approved[$row['comment_approved']] ) ) |
|
778 | - $stats[$approved[$row['comment_approved']]] = $row['num_comments']; |
|
782 | + if ( 'post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'] ) { |
|
783 | + $total += $row['num_comments']; |
|
784 | + } |
|
785 | + if ( isset( $approved[$row['comment_approved']] ) ) { |
|
786 | + $stats[$approved[$row['comment_approved']]] = $row['num_comments']; |
|
787 | + } |
|
779 | 788 | } |
780 | 789 | |
781 | 790 | $stats['total_comments'] = $total; |
782 | 791 | foreach ( $approved as $key ) { |
783 | - if ( empty($stats[$key]) ) |
|
784 | - $stats[$key] = 0; |
|
792 | + if ( empty($stats[$key]) ) { |
|
793 | + $stats[$key] = 0; |
|
794 | + } |
|
785 | 795 | } |
786 | 796 | |
787 | 797 | $stats = (object) $stats; |
@@ -822,8 +832,9 @@ discard block |
||
822 | 832 | public function get_image_size( $image_size ) { |
823 | 833 | |
824 | 834 | // Only return sizes we define in settings |
825 | - if ( ! in_array( $image_size, array( 'course_archive_image', 'course_single_image', 'lesson_archive_image', 'lesson_single_image' ) ) ) |
|
826 | - return apply_filters( 'sensei_get_image_size_' . $image_size, '' ); |
|
835 | + if ( ! in_array( $image_size, array( 'course_archive_image', 'course_single_image', 'lesson_archive_image', 'lesson_single_image' ) ) ) { |
|
836 | + return apply_filters( 'sensei_get_image_size_' . $image_size, '' ); |
|
837 | + } |
|
827 | 838 | |
828 | 839 | if( ! isset( $this->settings->settings[ $image_size . '_width' ] ) ) { |
829 | 840 | $this->settings->settings[ $image_size . '_width' ] = false; |
@@ -886,7 +897,7 @@ discard block |
||
886 | 897 | require_once( 'class-sensei-modules.php'); |
887 | 898 | Sensei()->modules = new Sensei_Core_Modules( $this->file ); |
888 | 899 | |
889 | - }else{ |
|
900 | + } else{ |
|
890 | 901 | // fallback for people still using the modules extension. |
891 | 902 | global $sensei_modules; |
892 | 903 | Sensei()->modules = $sensei_modules; |
@@ -933,7 +944,7 @@ discard block |
||
933 | 944 | |
934 | 945 | update_option('sensei_flush_rewrite_rules', '2'); |
935 | 946 | |
936 | - }elseif( '2' == $option ) { |
|
947 | + } elseif( '2' == $option ) { |
|
937 | 948 | |
938 | 949 | flush_rewrite_rules(); |
939 | 950 | update_option('sensei_flush_rewrite_rules', '0'); |
@@ -1,5 +1,8 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
@@ -836,7 +836,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
@@ -12,735 +12,735 @@ discard block |
||
12 | 12 | */ |
13 | 13 | |
14 | 14 | Class Sensei_WC{ |
15 | - /** |
|
16 | - * Load the files needed for the woocommerce integration. |
|
17 | - * |
|
18 | - * @since 1.9.0 |
|
19 | - */ |
|
20 | - public static function load_woocommerce_integration_hooks(){ |
|
15 | + /** |
|
16 | + * Load the files needed for the woocommerce integration. |
|
17 | + * |
|
18 | + * @since 1.9.0 |
|
19 | + */ |
|
20 | + public static function load_woocommerce_integration_hooks(){ |
|
21 | 21 | |
22 | - require_once( __DIR__ . '/hooks/woocommerce.php' ); |
|
22 | + require_once( __DIR__ . '/hooks/woocommerce.php' ); |
|
23 | 23 | |
24 | - } |
|
25 | - /** |
|
26 | - * check if WooCommerce plugin is loaded and allowed by Sensei |
|
27 | - * |
|
28 | - * @since 1.9.0 |
|
29 | - * @return bool |
|
30 | - */ |
|
31 | - public static function is_woocommerce_active(){ |
|
24 | + } |
|
25 | + /** |
|
26 | + * check if WooCommerce plugin is loaded and allowed by Sensei |
|
27 | + * |
|
28 | + * @since 1.9.0 |
|
29 | + * @return bool |
|
30 | + */ |
|
31 | + public static function is_woocommerce_active(){ |
|
32 | 32 | |
33 | - $is_woocommerce_enabled_in_settings = isset( Sensei()->settings->settings['woocommerce_enabled'] ) && Sensei()->settings->settings['woocommerce_enabled']; |
|
34 | - return self::is_woocommerce_present() && $is_woocommerce_enabled_in_settings; |
|
33 | + $is_woocommerce_enabled_in_settings = isset( Sensei()->settings->settings['woocommerce_enabled'] ) && Sensei()->settings->settings['woocommerce_enabled']; |
|
34 | + return self::is_woocommerce_present() && $is_woocommerce_enabled_in_settings; |
|
35 | 35 | |
36 | - } // end is_woocommerce_active |
|
36 | + } // end is_woocommerce_active |
|
37 | 37 | |
38 | - /** |
|
39 | - * Checks if the WooCommerce plugin is installed and activation. |
|
40 | - * |
|
41 | - * If you need to check if WooCommerce is activated use Sensei_Utils::is_woocommerce_active(). |
|
42 | - * This function does nott check to see if the Sensei setting for WooCommerce is enabled. |
|
43 | - * |
|
44 | - * @since 1.9.0 |
|
45 | - * |
|
46 | - * @return bool |
|
47 | - */ |
|
48 | - public static function is_woocommerce_present(){ |
|
38 | + /** |
|
39 | + * Checks if the WooCommerce plugin is installed and activation. |
|
40 | + * |
|
41 | + * If you need to check if WooCommerce is activated use Sensei_Utils::is_woocommerce_active(). |
|
42 | + * This function does nott check to see if the Sensei setting for WooCommerce is enabled. |
|
43 | + * |
|
44 | + * @since 1.9.0 |
|
45 | + * |
|
46 | + * @return bool |
|
47 | + */ |
|
48 | + public static function is_woocommerce_present(){ |
|
49 | 49 | |
50 | - $active_plugins = (array) get_option( 'active_plugins', array() ); |
|
50 | + $active_plugins = (array) get_option( 'active_plugins', array() ); |
|
51 | 51 | |
52 | - if ( is_multisite() ){ |
|
52 | + if ( is_multisite() ){ |
|
53 | 53 | |
54 | - $active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) ); |
|
54 | + $active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) ); |
|
55 | 55 | |
56 | - } |
|
56 | + } |
|
57 | 57 | |
58 | - $is_woocommerce_plugin_present_and_activated = in_array( 'woocommerce/woocommerce.php', $active_plugins ) || array_key_exists( 'woocommerce/woocommerce.php', $active_plugins ); |
|
58 | + $is_woocommerce_plugin_present_and_activated = in_array( 'woocommerce/woocommerce.php', $active_plugins ) || array_key_exists( 'woocommerce/woocommerce.php', $active_plugins ); |
|
59 | 59 | |
60 | - return class_exists( 'Woocommerce' ) || $is_woocommerce_plugin_present_and_activated; |
|
60 | + return class_exists( 'Woocommerce' ) || $is_woocommerce_plugin_present_and_activated; |
|
61 | 61 | |
62 | - }// end is_woocommerce_present |
|
62 | + }// end is_woocommerce_present |
|
63 | 63 | |
64 | - /** |
|
65 | - * Find the order active number (completed or processing ) for a given user on a course. It will return the latest order. |
|
66 | - * |
|
67 | - * If multiple exist we will return the latest order. |
|
68 | - * |
|
69 | - * @param $user_id |
|
70 | - * @param $course_id |
|
71 | - * @return array $user_course_orders |
|
72 | - */ |
|
73 | - public static function get_learner_course_active_order_id( $user_id, $course_id ){ |
|
64 | + /** |
|
65 | + * Find the order active number (completed or processing ) for a given user on a course. It will return the latest order. |
|
66 | + * |
|
67 | + * If multiple exist we will return the latest order. |
|
68 | + * |
|
69 | + * @param $user_id |
|
70 | + * @param $course_id |
|
71 | + * @return array $user_course_orders |
|
72 | + */ |
|
73 | + public static function get_learner_course_active_order_id( $user_id, $course_id ){ |
|
74 | 74 | |
75 | - $course_product_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
75 | + $course_product_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
76 | 76 | |
77 | - $orders_query = new WP_Query( array( |
|
78 | - 'post_type' => 'shop_order', |
|
79 | - 'posts_per_page' => -1, |
|
80 | - 'post_status' => array( 'wc-processing', 'wc-completed' ), |
|
81 | - 'meta_key'=> '_customer_user', |
|
82 | - 'meta_value'=> $user_id, |
|
83 | - ) ); |
|
77 | + $orders_query = new WP_Query( array( |
|
78 | + 'post_type' => 'shop_order', |
|
79 | + 'posts_per_page' => -1, |
|
80 | + 'post_status' => array( 'wc-processing', 'wc-completed' ), |
|
81 | + 'meta_key'=> '_customer_user', |
|
82 | + 'meta_value'=> $user_id, |
|
83 | + ) ); |
|
84 | 84 | |
85 | - if( $orders_query->post_count == 0 ){ |
|
85 | + if( $orders_query->post_count == 0 ){ |
|
86 | 86 | |
87 | - return false; |
|
87 | + return false; |
|
88 | 88 | |
89 | - } |
|
89 | + } |
|
90 | 90 | |
91 | - foreach( $orders_query->get_posts() as $order ){ |
|
91 | + foreach( $orders_query->get_posts() as $order ){ |
|
92 | 92 | |
93 | - $order = new WC_Order( $order->ID ); |
|
94 | - $items = $order->get_items(); |
|
93 | + $order = new WC_Order( $order->ID ); |
|
94 | + $items = $order->get_items(); |
|
95 | 95 | |
96 | - $user_orders = array(); |
|
96 | + $user_orders = array(); |
|
97 | 97 | |
98 | - foreach( $items as $item ){ |
|
98 | + foreach( $items as $item ){ |
|
99 | 99 | |
100 | - // if the product id on the order and the one given to this function |
|
101 | - // this order has been placed by the given user on the given course. |
|
102 | - $product = wc_get_product( $item['product_id'] ); |
|
100 | + // if the product id on the order and the one given to this function |
|
101 | + // this order has been placed by the given user on the given course. |
|
102 | + $product = wc_get_product( $item['product_id'] ); |
|
103 | 103 | |
104 | - if ( $product->is_type( 'variable' )) { |
|
104 | + if ( $product->is_type( 'variable' )) { |
|
105 | 105 | |
106 | - $item_product_id = $item['variation_id']; |
|
106 | + $item_product_id = $item['variation_id']; |
|
107 | 107 | |
108 | - } else { |
|
108 | + } else { |
|
109 | 109 | |
110 | - $item_product_id = $item['product_id']; |
|
110 | + $item_product_id = $item['product_id']; |
|
111 | 111 | |
112 | - } |
|
112 | + } |
|
113 | 113 | |
114 | - if( $course_product_id == $item_product_id ){ |
|
114 | + if( $course_product_id == $item_product_id ){ |
|
115 | 115 | |
116 | - return $order->id; |
|
116 | + return $order->id; |
|
117 | 117 | |
118 | - } |
|
118 | + } |
|
119 | 119 | |
120 | 120 | |
121 | - }//end for each order item |
|
121 | + }//end for each order item |
|
122 | 122 | |
123 | - } // end for each order |
|
123 | + } // end for each order |
|
124 | 124 | |
125 | - // if we reach this place we found no order |
|
126 | - return false; |
|
125 | + // if we reach this place we found no order |
|
126 | + return false; |
|
127 | 127 | |
128 | - } // end get_learner_course_active_order_ids |
|
128 | + } // end get_learner_course_active_order_ids |
|
129 | 129 | |
130 | - /** |
|
131 | - * Output WooCommerce specific course filters |
|
132 | - * Removing the paged argument |
|
133 | - * |
|
134 | - * @since 1.9.0 |
|
135 | - * @param $filter_links |
|
136 | - * @return mixed |
|
137 | - */ |
|
138 | - public static function add_course_archive_wc_filter_links( $filter_links ){ |
|
130 | + /** |
|
131 | + * Output WooCommerce specific course filters |
|
132 | + * Removing the paged argument |
|
133 | + * |
|
134 | + * @since 1.9.0 |
|
135 | + * @param $filter_links |
|
136 | + * @return mixed |
|
137 | + */ |
|
138 | + public static function add_course_archive_wc_filter_links( $filter_links ){ |
|
139 | 139 | |
140 | - $free_courses = self::get_free_courses(); |
|
141 | - $paid_courses = self::get_paid_courses(); |
|
140 | + $free_courses = self::get_free_courses(); |
|
141 | + $paid_courses = self::get_paid_courses(); |
|
142 | 142 | |
143 | - if ( empty( $free_courses ) || empty( $paid_courses ) ){ |
|
144 | - // do not show any WooCommerce filters if all courses are |
|
145 | - // free or if all courses are paid |
|
146 | - return $filter_links; |
|
143 | + if ( empty( $free_courses ) || empty( $paid_courses ) ){ |
|
144 | + // do not show any WooCommerce filters if all courses are |
|
145 | + // free or if all courses are paid |
|
146 | + return $filter_links; |
|
147 | 147 | |
148 | - } |
|
148 | + } |
|
149 | 149 | |
150 | - $filter_links[] = array( |
|
151 | - 'id'=>'paid' , |
|
152 | - 'url'=> add_query_arg( array( 'course_filter'=>'paid'), Sensei_Course::get_courses_page_url() ), |
|
153 | - 'title'=>__( 'Paid', 'woothemes-sensei' ) |
|
154 | - ); |
|
150 | + $filter_links[] = array( |
|
151 | + 'id'=>'paid' , |
|
152 | + 'url'=> add_query_arg( array( 'course_filter'=>'paid'), Sensei_Course::get_courses_page_url() ), |
|
153 | + 'title'=>__( 'Paid', 'woothemes-sensei' ) |
|
154 | + ); |
|
155 | 155 | |
156 | - $filter_links[] = array( |
|
157 | - 'id'=>'free', |
|
158 | - 'url'=> add_query_arg( array( 'course_filter'=>'free'), Sensei_Course::get_courses_page_url() ), |
|
159 | - 'title'=>__( 'Free', 'woothemes-sensei' ) |
|
160 | - ); |
|
156 | + $filter_links[] = array( |
|
157 | + 'id'=>'free', |
|
158 | + 'url'=> add_query_arg( array( 'course_filter'=>'free'), Sensei_Course::get_courses_page_url() ), |
|
159 | + 'title'=>__( 'Free', 'woothemes-sensei' ) |
|
160 | + ); |
|
161 | 161 | |
162 | - return $filter_links; |
|
162 | + return $filter_links; |
|
163 | 163 | |
164 | - }// end add_course_archive_wc_filter_links |
|
164 | + }// end add_course_archive_wc_filter_links |
|
165 | 165 | |
166 | - /** |
|
167 | - * Apply the free filter the the course query |
|
168 | - * getting all course with no products or products with zero price |
|
169 | - * |
|
170 | - * hooked into pre_get_posts |
|
171 | - * |
|
172 | - * @since 1.9.0 |
|
173 | - * @param WP_Query $query |
|
174 | - * @return WP_Query $query |
|
175 | - */ |
|
176 | - public static function course_archive_wc_filter_free( $query ){ |
|
166 | + /** |
|
167 | + * Apply the free filter the the course query |
|
168 | + * getting all course with no products or products with zero price |
|
169 | + * |
|
170 | + * hooked into pre_get_posts |
|
171 | + * |
|
172 | + * @since 1.9.0 |
|
173 | + * @param WP_Query $query |
|
174 | + * @return WP_Query $query |
|
175 | + */ |
|
176 | + public static function course_archive_wc_filter_free( $query ){ |
|
177 | 177 | |
178 | - if( isset( $_GET['course_filter'] ) && 'free' == $_GET['course_filter'] |
|
179 | - && 'course' == $query->get( 'post_type') && $query->is_main_query() ){ |
|
178 | + if( isset( $_GET['course_filter'] ) && 'free' == $_GET['course_filter'] |
|
179 | + && 'course' == $query->get( 'post_type') && $query->is_main_query() ){ |
|
180 | 180 | |
181 | - // setup the course meta query |
|
182 | - $meta_query = self::get_free_courses_meta_query_args(); |
|
181 | + // setup the course meta query |
|
182 | + $meta_query = self::get_free_courses_meta_query_args(); |
|
183 | 183 | |
184 | - // manipulate the query to return free courses |
|
185 | - $query->set('meta_query', $meta_query ); |
|
184 | + // manipulate the query to return free courses |
|
185 | + $query->set('meta_query', $meta_query ); |
|
186 | 186 | |
187 | - // don't show any paid courses |
|
188 | - $courses = self::get_paid_courses(); |
|
189 | - $ids = array(); |
|
190 | - foreach( $courses as $course ){ |
|
191 | - $ids[] = $course->ID; |
|
192 | - } |
|
193 | - $query->set( 'post__not_in', $ids ); |
|
187 | + // don't show any paid courses |
|
188 | + $courses = self::get_paid_courses(); |
|
189 | + $ids = array(); |
|
190 | + foreach( $courses as $course ){ |
|
191 | + $ids[] = $course->ID; |
|
192 | + } |
|
193 | + $query->set( 'post__not_in', $ids ); |
|
194 | 194 | |
195 | - }// end if course_filter |
|
195 | + }// end if course_filter |
|
196 | 196 | |
197 | - return $query; |
|
197 | + return $query; |
|
198 | 198 | |
199 | - }// course_archive_wc_filter_free |
|
199 | + }// course_archive_wc_filter_free |
|
200 | 200 | |
201 | - /** |
|
202 | - * Apply the paid filter to the course query on the courses page |
|
203 | - * will include all course with a product attached with a price |
|
204 | - * more than 0 |
|
205 | - * |
|
206 | - * hooked into pre_get_posts |
|
207 | - * |
|
208 | - * @since 1.9.0 |
|
209 | - * @param WP_Query $query |
|
210 | - * @return WP_Query $query |
|
211 | - */ |
|
212 | - public static function course_archive_wc_filter_paid( $query ){ |
|
201 | + /** |
|
202 | + * Apply the paid filter to the course query on the courses page |
|
203 | + * will include all course with a product attached with a price |
|
204 | + * more than 0 |
|
205 | + * |
|
206 | + * hooked into pre_get_posts |
|
207 | + * |
|
208 | + * @since 1.9.0 |
|
209 | + * @param WP_Query $query |
|
210 | + * @return WP_Query $query |
|
211 | + */ |
|
212 | + public static function course_archive_wc_filter_paid( $query ){ |
|
213 | 213 | |
214 | - if( isset( $_GET['course_filter'] ) && 'paid' == $_GET['course_filter'] |
|
215 | - && 'course' == $query->get( 'post_type') && $query->is_main_query() ){ |
|
216 | - |
|
217 | - // setup the course meta query |
|
218 | - $meta_query = self::get_paid_courses_meta_query_args(); |
|
219 | - |
|
220 | - // manipulate the query to return free courses |
|
221 | - $query->set('meta_query', $meta_query ); |
|
222 | - |
|
223 | - } |
|
224 | - |
|
225 | - return $query; |
|
226 | - |
|
227 | - } |
|
228 | - |
|
229 | - /** |
|
230 | - * Load the WooCommerce single product actions above |
|
231 | - * single courses if woocommerce is active allowing purchase |
|
232 | - * information and actions to be hooked from WooCommerce. |
|
233 | - */ |
|
234 | - public static function do_single_course_wc_single_product_action(){ |
|
235 | - |
|
236 | - /** |
|
237 | - * this hooks is documented within the WooCommerce plugin. |
|
238 | - */ |
|
239 | - if ( Sensei_WC::is_woocommerce_active() ) { |
|
240 | - |
|
241 | - do_action( 'woocommerce_before_single_product' ); |
|
242 | - |
|
243 | - } // End If Statement |
|
244 | - |
|
245 | - }// end do_single_course_wc_single_product_action |
|
246 | - |
|
247 | - /** |
|
248 | - * Hooking into the single lesson page to alter the |
|
249 | - * user access permissions based on if they have purchased the |
|
250 | - * course the lesson belongs to. |
|
251 | - * |
|
252 | - * This function will only return false or the passed in user_access value. |
|
253 | - * It doesn't return true in order to avoid altering other options. |
|
254 | - * |
|
255 | - * @since 1.9.0 |
|
256 | - * |
|
257 | - * @param $can_user_view_lesson |
|
258 | - * @param $lesson_id |
|
259 | - * @param $user_id |
|
260 | - * @return bool |
|
261 | - */ |
|
262 | - public static function alter_can_user_view_lesson ( $can_user_view_lesson, $lesson_id, $user_id ){ |
|
263 | - |
|
264 | - // check if the course has a valid product attached to it |
|
265 | - // which the user should have purchased if they want to access |
|
266 | - // the current lesson |
|
267 | - $course_id = get_post_meta( $lesson_id , '_lesson_course', true); |
|
268 | - $wc_post_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
269 | - $product = Sensei()->sensei_get_woocommerce_product_object($wc_post_id); |
|
270 | - if( isset ($product) && is_object($product) ){ |
|
271 | - |
|
272 | - // valid product found |
|
273 | - $order_id = self::get_learner_course_active_order_id( $user_id, $course_id ); |
|
274 | - |
|
275 | - // product has a successful order so this user may access the content |
|
276 | - // this function may only return false or the default |
|
277 | - // returning true may override other negatives which we don't want |
|
278 | - if( ! $order_id ){ |
|
279 | - |
|
280 | - return false; |
|
281 | - |
|
282 | - } |
|
283 | - |
|
284 | - } |
|
285 | - |
|
286 | - // return the passed in value |
|
287 | - return $can_user_view_lesson; |
|
288 | - |
|
289 | - } |
|
290 | - |
|
291 | - /** |
|
292 | - * Add course link to order thank you and details pages. |
|
293 | - * |
|
294 | - * @since 1.4.5 |
|
295 | - * @access public |
|
296 | - * |
|
297 | - * @return void |
|
298 | - */ |
|
299 | - public static function course_link_from_order( ) { |
|
300 | - |
|
301 | - if( ! is_order_received_page() ){ |
|
302 | - return; |
|
303 | - } |
|
304 | - |
|
305 | - $order_id = get_query_var( 'order-received' ); |
|
214 | + if( isset( $_GET['course_filter'] ) && 'paid' == $_GET['course_filter'] |
|
215 | + && 'course' == $query->get( 'post_type') && $query->is_main_query() ){ |
|
216 | + |
|
217 | + // setup the course meta query |
|
218 | + $meta_query = self::get_paid_courses_meta_query_args(); |
|
219 | + |
|
220 | + // manipulate the query to return free courses |
|
221 | + $query->set('meta_query', $meta_query ); |
|
222 | + |
|
223 | + } |
|
224 | + |
|
225 | + return $query; |
|
226 | + |
|
227 | + } |
|
228 | + |
|
229 | + /** |
|
230 | + * Load the WooCommerce single product actions above |
|
231 | + * single courses if woocommerce is active allowing purchase |
|
232 | + * information and actions to be hooked from WooCommerce. |
|
233 | + */ |
|
234 | + public static function do_single_course_wc_single_product_action(){ |
|
235 | + |
|
236 | + /** |
|
237 | + * this hooks is documented within the WooCommerce plugin. |
|
238 | + */ |
|
239 | + if ( Sensei_WC::is_woocommerce_active() ) { |
|
240 | + |
|
241 | + do_action( 'woocommerce_before_single_product' ); |
|
242 | + |
|
243 | + } // End If Statement |
|
244 | + |
|
245 | + }// end do_single_course_wc_single_product_action |
|
246 | + |
|
247 | + /** |
|
248 | + * Hooking into the single lesson page to alter the |
|
249 | + * user access permissions based on if they have purchased the |
|
250 | + * course the lesson belongs to. |
|
251 | + * |
|
252 | + * This function will only return false or the passed in user_access value. |
|
253 | + * It doesn't return true in order to avoid altering other options. |
|
254 | + * |
|
255 | + * @since 1.9.0 |
|
256 | + * |
|
257 | + * @param $can_user_view_lesson |
|
258 | + * @param $lesson_id |
|
259 | + * @param $user_id |
|
260 | + * @return bool |
|
261 | + */ |
|
262 | + public static function alter_can_user_view_lesson ( $can_user_view_lesson, $lesson_id, $user_id ){ |
|
263 | + |
|
264 | + // check if the course has a valid product attached to it |
|
265 | + // which the user should have purchased if they want to access |
|
266 | + // the current lesson |
|
267 | + $course_id = get_post_meta( $lesson_id , '_lesson_course', true); |
|
268 | + $wc_post_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
269 | + $product = Sensei()->sensei_get_woocommerce_product_object($wc_post_id); |
|
270 | + if( isset ($product) && is_object($product) ){ |
|
271 | + |
|
272 | + // valid product found |
|
273 | + $order_id = self::get_learner_course_active_order_id( $user_id, $course_id ); |
|
274 | + |
|
275 | + // product has a successful order so this user may access the content |
|
276 | + // this function may only return false or the default |
|
277 | + // returning true may override other negatives which we don't want |
|
278 | + if( ! $order_id ){ |
|
279 | + |
|
280 | + return false; |
|
281 | + |
|
282 | + } |
|
283 | + |
|
284 | + } |
|
285 | + |
|
286 | + // return the passed in value |
|
287 | + return $can_user_view_lesson; |
|
288 | + |
|
289 | + } |
|
290 | + |
|
291 | + /** |
|
292 | + * Add course link to order thank you and details pages. |
|
293 | + * |
|
294 | + * @since 1.4.5 |
|
295 | + * @access public |
|
296 | + * |
|
297 | + * @return void |
|
298 | + */ |
|
299 | + public static function course_link_from_order( ) { |
|
300 | + |
|
301 | + if( ! is_order_received_page() ){ |
|
302 | + return; |
|
303 | + } |
|
304 | + |
|
305 | + $order_id = get_query_var( 'order-received' ); |
|
306 | 306 | $order = new WC_Order( $order_id ); |
307 | 307 | |
308 | 308 | // exit early if not wc-completed or wc-processing |
309 | 309 | if( 'wc-completed' != $order->post_status |
310 | - && 'wc-processing' != $order->post_status ) { |
|
311 | - return; |
|
312 | - } |
|
310 | + && 'wc-processing' != $order->post_status ) { |
|
311 | + return; |
|
312 | + } |
|
313 | 313 | |
314 | - $course_links = array(); // store the for links for courses purchased |
|
314 | + $course_links = array(); // store the for links for courses purchased |
|
315 | 315 | foreach ( $order->get_items() as $item ) { |
316 | 316 | |
317 | - if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
317 | + if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
318 | 318 | |
319 | - // If item has variation_id then its a variation of the product |
|
320 | - $item_id = $item['variation_id']; |
|
319 | + // If item has variation_id then its a variation of the product |
|
320 | + $item_id = $item['variation_id']; |
|
321 | 321 | |
322 | - } else { |
|
322 | + } else { |
|
323 | 323 | |
324 | - //If not its real product set its id to item_id |
|
325 | - $item_id = $item['product_id']; |
|
324 | + //If not its real product set its id to item_id |
|
325 | + $item_id = $item['product_id']; |
|
326 | 326 | |
327 | - } // End If Statement |
|
327 | + } // End If Statement |
|
328 | 328 | |
329 | - $user_id = get_post_meta( $order->id, '_customer_user', true ); |
|
329 | + $user_id = get_post_meta( $order->id, '_customer_user', true ); |
|
330 | 330 | |
331 | - if( $user_id ) { |
|
331 | + if( $user_id ) { |
|
332 | 332 | |
333 | - // Get all courses for product |
|
334 | - $args = Sensei_Course::get_default_query_args(); |
|
335 | - $args['meta_query'] = array( array( |
|
336 | - 'key' => '_course_woocommerce_product', |
|
337 | - 'value' => $item_id |
|
338 | - ) ); |
|
339 | - $args['orderby'] = 'menu_order date'; |
|
340 | - $args['order'] = 'ASC'; |
|
333 | + // Get all courses for product |
|
334 | + $args = Sensei_Course::get_default_query_args(); |
|
335 | + $args['meta_query'] = array( array( |
|
336 | + 'key' => '_course_woocommerce_product', |
|
337 | + 'value' => $item_id |
|
338 | + ) ); |
|
339 | + $args['orderby'] = 'menu_order date'; |
|
340 | + $args['order'] = 'ASC'; |
|
341 | 341 | |
342 | - // loop through courses |
|
343 | - $courses = get_posts( $args ); |
|
344 | - if( $courses && count( $courses ) > 0 ) { |
|
342 | + // loop through courses |
|
343 | + $courses = get_posts( $args ); |
|
344 | + if( $courses && count( $courses ) > 0 ) { |
|
345 | 345 | |
346 | - foreach( $courses as $course ) { |
|
346 | + foreach( $courses as $course ) { |
|
347 | 347 | |
348 | - $title = $course->post_title; |
|
349 | - $permalink = get_permalink( $course->ID ); |
|
350 | - $course_links[] .= '<a href="' . esc_url( $permalink ) . '" >' . $title . '</a> '; |
|
348 | + $title = $course->post_title; |
|
349 | + $permalink = get_permalink( $course->ID ); |
|
350 | + $course_links[] .= '<a href="' . esc_url( $permalink ) . '" >' . $title . '</a> '; |
|
351 | 351 | |
352 | - } // end for each |
|
352 | + } // end for each |
|
353 | 353 | |
354 | - // close the message div |
|
354 | + // close the message div |
|
355 | 355 | |
356 | - }// end if $courses check |
|
357 | - } |
|
358 | - }// end loop through orders |
|
356 | + }// end if $courses check |
|
357 | + } |
|
358 | + }// end loop through orders |
|
359 | 359 | |
360 | - // add the courses to the WooCommerce notice |
|
361 | - if( ! empty( $course_links) ){ |
|
360 | + // add the courses to the WooCommerce notice |
|
361 | + if( ! empty( $course_links) ){ |
|
362 | 362 | |
363 | - $courses_html = _nx( |
|
364 | - 'You have purchased the following course:', |
|
365 | - 'You have purchased the following courses:', |
|
366 | - count( $course_links ), |
|
367 | - 'Purchase thank you note on Checkout page. The course link(s) will be show', 'woothemes-sensei' |
|
368 | - ); |
|
363 | + $courses_html = _nx( |
|
364 | + 'You have purchased the following course:', |
|
365 | + 'You have purchased the following courses:', |
|
366 | + count( $course_links ), |
|
367 | + 'Purchase thank you note on Checkout page. The course link(s) will be show', 'woothemes-sensei' |
|
368 | + ); |
|
369 | 369 | |
370 | - foreach( $course_links as $link ){ |
|
370 | + foreach( $course_links as $link ){ |
|
371 | 371 | |
372 | - $courses_html .= '<li>' . $link . '</li>'; |
|
372 | + $courses_html .= '<li>' . $link . '</li>'; |
|
373 | 373 | |
374 | - } |
|
374 | + } |
|
375 | 375 | |
376 | - $courses_html .= ' </ul>'; |
|
376 | + $courses_html .= ' </ul>'; |
|
377 | 377 | |
378 | - wc_add_notice( $courses_html, 'success' ); |
|
379 | - } |
|
378 | + wc_add_notice( $courses_html, 'success' ); |
|
379 | + } |
|
380 | 380 | |
381 | 381 | } // end course_link_order_form |
382 | 382 | |
383 | - /** |
|
384 | - * Show the message that a user should complete |
|
385 | - * their purchase if the course is in the cart |
|
386 | - * |
|
387 | - * This should be used within the course loop or single course page |
|
388 | - * |
|
389 | - * @since 1.9.0 |
|
390 | - */ |
|
391 | - public static function course_in_cart_message(){ |
|
383 | + /** |
|
384 | + * Show the message that a user should complete |
|
385 | + * their purchase if the course is in the cart |
|
386 | + * |
|
387 | + * This should be used within the course loop or single course page |
|
388 | + * |
|
389 | + * @since 1.9.0 |
|
390 | + */ |
|
391 | + public static function course_in_cart_message(){ |
|
392 | 392 | |
393 | - global $post; |
|
393 | + global $post; |
|
394 | 394 | |
395 | - if( self::is_course_in_cart( $post->ID ) ){ ?> |
|
395 | + if( self::is_course_in_cart( $post->ID ) ){ ?> |
|
396 | 396 | |
397 | 397 | <div class="sensei-message info"> |
398 | 398 | <?php |
399 | 399 | |
400 | - $cart_link = '<a class="cart-complete" href="' . WC()->cart->get_checkout_url() |
|
401 | - . '" title="' . __('complete purchase', 'woothemes-sensei') . '">' |
|
402 | - . __('complete the purchase', 'woothemes-sensei') . '</a>'; |
|
400 | + $cart_link = '<a class="cart-complete" href="' . WC()->cart->get_checkout_url() |
|
401 | + . '" title="' . __('complete purchase', 'woothemes-sensei') . '">' |
|
402 | + . __('complete the purchase', 'woothemes-sensei') . '</a>'; |
|
403 | 403 | |
404 | - echo sprintf( __('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei'), $cart_link ); |
|
404 | + echo sprintf( __('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei'), $cart_link ); |
|
405 | 405 | |
406 | - ?> |
|
406 | + ?> |
|
407 | 407 | </div> |
408 | 408 | <?php } |
409 | 409 | |
410 | - } // End sensei_woocommerce_in_cart_message() |
|
410 | + } // End sensei_woocommerce_in_cart_message() |
|
411 | 411 | |
412 | - /** |
|
413 | - * Checks the cart to see if a course is in the cart. |
|
414 | - * |
|
415 | - * @param $course_id |
|
416 | - * @return bool |
|
417 | - */ |
|
418 | - public static function is_course_in_cart( $course_id ){ |
|
419 | - |
|
420 | - $wc_post_id = absint( get_post_meta( $course_id, '_course_woocommerce_product', true ) ); |
|
421 | - $user_course_status_id = Sensei_Utils::user_started_course( $course_id , get_current_user_id() ); |
|
422 | - |
|
423 | - if ( 0 < intval( $wc_post_id ) && ! $user_course_status_id ) { |
|
424 | - |
|
425 | - if ( self::is_product_in_cart( $wc_post_id ) ) { |
|
426 | - |
|
427 | - return true; |
|
428 | - |
|
429 | - } |
|
430 | - |
|
431 | - } |
|
432 | - |
|
433 | - return false; |
|
434 | - |
|
435 | - }// is_course_in_cart |
|
436 | - |
|
437 | - /** |
|
438 | - * Check the cart to see if the product is in the cart |
|
439 | - * |
|
440 | - * @param $product_id |
|
441 | - * @return bool |
|
442 | - */ |
|
443 | - public static function is_product_in_cart( $product_id ){ |
|
444 | - |
|
445 | - if ( 0 < $product_id ) { |
|
446 | - |
|
447 | - $product = wc_get_product( $product_id ); |
|
448 | - |
|
449 | - $parent_id = ''; |
|
450 | - if( isset( $product->variation_id ) && 0 < intval( $product->variation_id ) ) { |
|
451 | - $wc_product_id = $product->parent->id; |
|
452 | - } |
|
453 | - foreach( WC()->cart->get_cart() as $cart_item_key => $values ) { |
|
454 | - |
|
455 | - $cart_product = $values['data']; |
|
456 | - if( $product_id == $cart_product->id ) { |
|
457 | - |
|
458 | - return true; |
|
459 | - |
|
460 | - } |
|
461 | - |
|
462 | - } |
|
463 | - } // End If Statement |
|
464 | - |
|
465 | - return false; |
|
466 | - |
|
467 | - } // end is_product_in_car |
|
468 | - |
|
469 | - /** |
|
470 | - * Get all free WooCommerce products |
|
471 | - * |
|
472 | - * @since 1.9.0 |
|
473 | - * |
|
474 | - * @return array $free_products{ |
|
475 | - * @type int $wp_post_id |
|
476 | - * } |
|
477 | - */ |
|
478 | - public static function get_free_product_ids(){ |
|
479 | - |
|
480 | - return get_posts( array( |
|
481 | - 'post_type' => 'product', |
|
482 | - 'posts_per_page' => '1000', |
|
483 | - 'fields' => 'ids', |
|
484 | - 'meta_query'=> array( |
|
485 | - 'relation' => 'OR', |
|
486 | - array( |
|
487 | - 'key'=> '_regular_price', |
|
488 | - 'value' => 0, |
|
489 | - ), |
|
490 | - array( |
|
491 | - 'key'=> '_sale_price', |
|
492 | - 'value' => 0, |
|
493 | - ), |
|
494 | - ), |
|
495 | - )); |
|
496 | - |
|
497 | - }// end get free product query |
|
498 | - |
|
499 | - /** |
|
500 | - * The metat query for courses that are free |
|
501 | - * |
|
502 | - * @since 1.9.0 |
|
503 | - * @return array $wp_meta_query_param |
|
504 | - */ |
|
505 | - public static function get_free_courses_meta_query_args(){ |
|
506 | - |
|
507 | - return array( |
|
508 | - 'relation' => 'OR', |
|
509 | - array( |
|
510 | - 'key' => '_course_woocommerce_product', |
|
511 | - 'value' => '-', |
|
512 | - 'compare' => '=', |
|
513 | - ), |
|
514 | - array( |
|
515 | - 'key' => '_course_woocommerce_product', |
|
516 | - 'value' => self::get_free_product_ids(), |
|
517 | - 'compare' => 'IN', |
|
518 | - ), |
|
519 | - ); |
|
520 | - |
|
521 | - }// get_free_courses_meta_query |
|
522 | - |
|
523 | - /** |
|
524 | - * The metat query for courses that are free |
|
525 | - * |
|
526 | - * @since 1.9.0 |
|
527 | - * @return array $wp_query_meta_query_args_param |
|
528 | - */ |
|
529 | - public static function get_paid_courses_meta_query_args(){ |
|
530 | - |
|
531 | - $paid_product_ids = self::get_paid_product_ids(); |
|
532 | - |
|
533 | - return array( |
|
534 | - array( |
|
535 | - 'key' => '_course_woocommerce_product', |
|
536 | - // when empty we give a false post_id to ensure the caller doesn't get any courses for their |
|
537 | - // query |
|
538 | - 'value' => empty( $paid_product_ids )? '-1000' : $paid_product_ids, |
|
539 | - 'compare' => 'IN', |
|
540 | - ), |
|
541 | - ); |
|
542 | - |
|
543 | - }// get_free_courses_meta_query |
|
544 | - |
|
545 | - /** |
|
546 | - * The WordPress Query args |
|
547 | - * for paid products on sale |
|
548 | - * |
|
549 | - * @since 1.9.0 |
|
550 | - * @return array $product_query_args |
|
551 | - */ |
|
552 | - public static function get_paid_products_on_sale_query_args(){ |
|
553 | - |
|
554 | - $args = array( |
|
555 | - 'post_type' => 'product', |
|
556 | - 'posts_per_page' => 1000, |
|
557 | - 'orderby' => 'date', |
|
558 | - 'order' => 'DESC', |
|
559 | - 'suppress_filters' => 0 |
|
560 | - ); |
|
561 | - |
|
562 | - $args[ 'fields' ] = 'ids'; |
|
563 | - |
|
564 | - $args[ 'meta_query' ] = array( |
|
565 | - 'relation' => 'AND', |
|
566 | - array( |
|
567 | - 'key'=> '_regular_price', |
|
568 | - 'compare' => '>', |
|
569 | - 'value' => 0, |
|
570 | - ), |
|
571 | - array( |
|
572 | - 'key'=> '_sale_price', |
|
573 | - 'compare' => '>', |
|
574 | - 'value' => 0, |
|
575 | - ), |
|
576 | - ); |
|
577 | - |
|
578 | - return $args; |
|
579 | - |
|
580 | - } // get_paid_products_on_sale_query_args |
|
581 | - |
|
582 | - |
|
583 | - /** |
|
584 | - * Return the WordPress query args for |
|
585 | - * products not on sale but that is not a free |
|
586 | - * |
|
587 | - * @since 1.9.0 |
|
588 | - * |
|
589 | - * @return array |
|
590 | - */ |
|
591 | - public static function get_paid_products_not_on_sale_query_args(){ |
|
592 | - |
|
593 | - $args = array( |
|
594 | - 'post_type' => 'product', |
|
595 | - 'posts_per_page' => 1000, |
|
596 | - 'orderby' => 'date', |
|
597 | - 'order' => 'DESC', |
|
598 | - 'suppress_filters' => 0 |
|
599 | - ); |
|
600 | - |
|
601 | - $args[ 'fields' ] = 'ids'; |
|
602 | - $args[ 'meta_query' ] = array( |
|
603 | - 'relation' => 'AND', |
|
604 | - array( |
|
605 | - 'key'=> '_regular_price', |
|
606 | - 'compare' => '>', |
|
607 | - 'value' => 0, |
|
608 | - ), |
|
609 | - array( |
|
610 | - 'key'=> '_sale_price', |
|
611 | - 'compare' => '=', |
|
612 | - 'value' => '', |
|
613 | - ), |
|
614 | - ); |
|
615 | - |
|
616 | - return $args; |
|
617 | - |
|
618 | - |
|
619 | - } // get_paid_courses_meta_query |
|
620 | - |
|
621 | - /** |
|
622 | - * Get all WooCommerce non-free product id's |
|
623 | - * |
|
624 | - * @since 1.9.0 |
|
625 | - * |
|
626 | - * @return array $woocommerce_paid_product_ids |
|
627 | - */ |
|
628 | - public static function get_paid_product_ids(){ |
|
629 | - |
|
630 | - // get all the paid WooCommerce products that has regular |
|
631 | - // and sale price greater than 0 |
|
632 | - // will be used later to check for course with the id as meta |
|
633 | - $paid_product_ids_with_sale = get_posts( self::get_paid_products_on_sale_query_args() ); |
|
634 | - |
|
635 | - // get all the paid WooCommerce products that has regular price |
|
636 | - // greater than 0 without a sale price |
|
637 | - // will be used later to check for course with the id as meta |
|
638 | - $paid_product_ids_without_sale = get_posts( self::get_paid_products_not_on_sale_query_args() ); |
|
639 | - |
|
640 | - // combine products ID's with regular and sale price grater than zero and those without |
|
641 | - // sale but regular price greater than zero |
|
642 | - $woocommerce_paid_product_ids = array_merge( $paid_product_ids_with_sale, $paid_product_ids_without_sale ); |
|
643 | - |
|
644 | - // if |
|
645 | - if( empty($woocommerce_paid_product_ids) ){ |
|
646 | - return array( ); |
|
647 | - } |
|
648 | - return $woocommerce_paid_product_ids; |
|
649 | - |
|
650 | - } |
|
651 | - |
|
652 | - /** |
|
653 | - * Get all free courses. |
|
654 | - * |
|
655 | - * This course that have a WC product attached |
|
656 | - * that has a price or sale price of zero and |
|
657 | - * other courses with no WooCommerce products |
|
658 | - * attached. |
|
659 | - * |
|
660 | - * @since 1.9.0 |
|
661 | - * |
|
662 | - * @return array |
|
663 | - */ |
|
664 | - public static function get_free_courses(){ |
|
665 | - |
|
666 | - $free_course_query_args = Sensei_Course::get_default_query_args(); |
|
667 | - $free_course_query_args[ 'meta_query' ] = self::get_free_courses_meta_query_args(); |
|
668 | - |
|
669 | - // don't show any paid courses |
|
670 | - $courses = self::get_paid_courses(); |
|
671 | - $ids = array(); |
|
672 | - foreach( $courses as $course ){ |
|
673 | - $ids[] = $course->ID; |
|
674 | - } |
|
675 | - $free_course_query_args[ 'post__not_in' ] = $ids; |
|
676 | - |
|
677 | - return get_posts( $free_course_query_args ); |
|
678 | - |
|
679 | - } |
|
680 | - |
|
681 | - /** |
|
682 | - * Return all products that are not free |
|
683 | - * |
|
684 | - * @since 1.9.0 |
|
685 | - * @return array |
|
686 | - */ |
|
687 | - public static function get_paid_courses(){ |
|
688 | - |
|
689 | - $paid_course_query_args = Sensei_Course::get_default_query_args(); |
|
690 | - |
|
691 | - $paid_course_query_args[ 'meta_query' ] = self::get_paid_courses_meta_query_args(); |
|
692 | - |
|
693 | - return get_posts( $paid_course_query_args ); |
|
694 | - } |
|
695 | - |
|
696 | - /** |
|
697 | - * Show the WooCommerce add to cart button for the current course |
|
698 | - * |
|
699 | - * The function will only show the button if |
|
700 | - * 1- the user can buy the course |
|
701 | - * 2- if they have completed their pre-requisite |
|
702 | - * 3- if the course has a valid product attached |
|
703 | - * |
|
704 | - * @since 1.9.0 |
|
705 | - * @param int $course_id |
|
706 | - * @return string $html markup for the button or nothing if user not allowed to buy |
|
707 | - */ |
|
708 | - public static function the_add_to_cart_button_html( $course_id ){ |
|
709 | - |
|
710 | - if ( ! Sensei_Course::is_prerequisite_complete( $course_id )) { |
|
711 | - return ''; |
|
712 | - } |
|
713 | - |
|
714 | - $wc_post_id = self::get_course_product_id( $course_id ); |
|
715 | - |
|
716 | - // Check if customer purchased the product |
|
717 | - if ( self::has_customer_bought_product( get_current_user_id(), $wc_post_id ) |
|
718 | - || empty( $wc_post_id ) ) { |
|
719 | - |
|
720 | - return ''; |
|
721 | - |
|
722 | - } |
|
723 | - |
|
724 | - // based on simple.php in WC templates/single-product/add-to-cart/ |
|
725 | - // Get the product |
|
726 | - $product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id ); |
|
727 | - |
|
728 | - // do not show the button for invalid products, non purchasable products, out |
|
729 | - // of stock product or if course is already in cart |
|
730 | - if ( ! isset ( $product ) |
|
731 | - || ! is_object( $product ) |
|
732 | - || ! $product->is_purchasable() |
|
733 | - || ! $product->is_in_stock() |
|
734 | - || self::is_course_in_cart( $wc_post_id ) ) { |
|
735 | - |
|
736 | - return ''; |
|
737 | - |
|
738 | - } |
|
739 | - |
|
740 | - // |
|
741 | - // button output: |
|
742 | - // |
|
743 | - ?> |
|
412 | + /** |
|
413 | + * Checks the cart to see if a course is in the cart. |
|
414 | + * |
|
415 | + * @param $course_id |
|
416 | + * @return bool |
|
417 | + */ |
|
418 | + public static function is_course_in_cart( $course_id ){ |
|
419 | + |
|
420 | + $wc_post_id = absint( get_post_meta( $course_id, '_course_woocommerce_product', true ) ); |
|
421 | + $user_course_status_id = Sensei_Utils::user_started_course( $course_id , get_current_user_id() ); |
|
422 | + |
|
423 | + if ( 0 < intval( $wc_post_id ) && ! $user_course_status_id ) { |
|
424 | + |
|
425 | + if ( self::is_product_in_cart( $wc_post_id ) ) { |
|
426 | + |
|
427 | + return true; |
|
428 | + |
|
429 | + } |
|
430 | + |
|
431 | + } |
|
432 | + |
|
433 | + return false; |
|
434 | + |
|
435 | + }// is_course_in_cart |
|
436 | + |
|
437 | + /** |
|
438 | + * Check the cart to see if the product is in the cart |
|
439 | + * |
|
440 | + * @param $product_id |
|
441 | + * @return bool |
|
442 | + */ |
|
443 | + public static function is_product_in_cart( $product_id ){ |
|
444 | + |
|
445 | + if ( 0 < $product_id ) { |
|
446 | + |
|
447 | + $product = wc_get_product( $product_id ); |
|
448 | + |
|
449 | + $parent_id = ''; |
|
450 | + if( isset( $product->variation_id ) && 0 < intval( $product->variation_id ) ) { |
|
451 | + $wc_product_id = $product->parent->id; |
|
452 | + } |
|
453 | + foreach( WC()->cart->get_cart() as $cart_item_key => $values ) { |
|
454 | + |
|
455 | + $cart_product = $values['data']; |
|
456 | + if( $product_id == $cart_product->id ) { |
|
457 | + |
|
458 | + return true; |
|
459 | + |
|
460 | + } |
|
461 | + |
|
462 | + } |
|
463 | + } // End If Statement |
|
464 | + |
|
465 | + return false; |
|
466 | + |
|
467 | + } // end is_product_in_car |
|
468 | + |
|
469 | + /** |
|
470 | + * Get all free WooCommerce products |
|
471 | + * |
|
472 | + * @since 1.9.0 |
|
473 | + * |
|
474 | + * @return array $free_products{ |
|
475 | + * @type int $wp_post_id |
|
476 | + * } |
|
477 | + */ |
|
478 | + public static function get_free_product_ids(){ |
|
479 | + |
|
480 | + return get_posts( array( |
|
481 | + 'post_type' => 'product', |
|
482 | + 'posts_per_page' => '1000', |
|
483 | + 'fields' => 'ids', |
|
484 | + 'meta_query'=> array( |
|
485 | + 'relation' => 'OR', |
|
486 | + array( |
|
487 | + 'key'=> '_regular_price', |
|
488 | + 'value' => 0, |
|
489 | + ), |
|
490 | + array( |
|
491 | + 'key'=> '_sale_price', |
|
492 | + 'value' => 0, |
|
493 | + ), |
|
494 | + ), |
|
495 | + )); |
|
496 | + |
|
497 | + }// end get free product query |
|
498 | + |
|
499 | + /** |
|
500 | + * The metat query for courses that are free |
|
501 | + * |
|
502 | + * @since 1.9.0 |
|
503 | + * @return array $wp_meta_query_param |
|
504 | + */ |
|
505 | + public static function get_free_courses_meta_query_args(){ |
|
506 | + |
|
507 | + return array( |
|
508 | + 'relation' => 'OR', |
|
509 | + array( |
|
510 | + 'key' => '_course_woocommerce_product', |
|
511 | + 'value' => '-', |
|
512 | + 'compare' => '=', |
|
513 | + ), |
|
514 | + array( |
|
515 | + 'key' => '_course_woocommerce_product', |
|
516 | + 'value' => self::get_free_product_ids(), |
|
517 | + 'compare' => 'IN', |
|
518 | + ), |
|
519 | + ); |
|
520 | + |
|
521 | + }// get_free_courses_meta_query |
|
522 | + |
|
523 | + /** |
|
524 | + * The metat query for courses that are free |
|
525 | + * |
|
526 | + * @since 1.9.0 |
|
527 | + * @return array $wp_query_meta_query_args_param |
|
528 | + */ |
|
529 | + public static function get_paid_courses_meta_query_args(){ |
|
530 | + |
|
531 | + $paid_product_ids = self::get_paid_product_ids(); |
|
532 | + |
|
533 | + return array( |
|
534 | + array( |
|
535 | + 'key' => '_course_woocommerce_product', |
|
536 | + // when empty we give a false post_id to ensure the caller doesn't get any courses for their |
|
537 | + // query |
|
538 | + 'value' => empty( $paid_product_ids )? '-1000' : $paid_product_ids, |
|
539 | + 'compare' => 'IN', |
|
540 | + ), |
|
541 | + ); |
|
542 | + |
|
543 | + }// get_free_courses_meta_query |
|
544 | + |
|
545 | + /** |
|
546 | + * The WordPress Query args |
|
547 | + * for paid products on sale |
|
548 | + * |
|
549 | + * @since 1.9.0 |
|
550 | + * @return array $product_query_args |
|
551 | + */ |
|
552 | + public static function get_paid_products_on_sale_query_args(){ |
|
553 | + |
|
554 | + $args = array( |
|
555 | + 'post_type' => 'product', |
|
556 | + 'posts_per_page' => 1000, |
|
557 | + 'orderby' => 'date', |
|
558 | + 'order' => 'DESC', |
|
559 | + 'suppress_filters' => 0 |
|
560 | + ); |
|
561 | + |
|
562 | + $args[ 'fields' ] = 'ids'; |
|
563 | + |
|
564 | + $args[ 'meta_query' ] = array( |
|
565 | + 'relation' => 'AND', |
|
566 | + array( |
|
567 | + 'key'=> '_regular_price', |
|
568 | + 'compare' => '>', |
|
569 | + 'value' => 0, |
|
570 | + ), |
|
571 | + array( |
|
572 | + 'key'=> '_sale_price', |
|
573 | + 'compare' => '>', |
|
574 | + 'value' => 0, |
|
575 | + ), |
|
576 | + ); |
|
577 | + |
|
578 | + return $args; |
|
579 | + |
|
580 | + } // get_paid_products_on_sale_query_args |
|
581 | + |
|
582 | + |
|
583 | + /** |
|
584 | + * Return the WordPress query args for |
|
585 | + * products not on sale but that is not a free |
|
586 | + * |
|
587 | + * @since 1.9.0 |
|
588 | + * |
|
589 | + * @return array |
|
590 | + */ |
|
591 | + public static function get_paid_products_not_on_sale_query_args(){ |
|
592 | + |
|
593 | + $args = array( |
|
594 | + 'post_type' => 'product', |
|
595 | + 'posts_per_page' => 1000, |
|
596 | + 'orderby' => 'date', |
|
597 | + 'order' => 'DESC', |
|
598 | + 'suppress_filters' => 0 |
|
599 | + ); |
|
600 | + |
|
601 | + $args[ 'fields' ] = 'ids'; |
|
602 | + $args[ 'meta_query' ] = array( |
|
603 | + 'relation' => 'AND', |
|
604 | + array( |
|
605 | + 'key'=> '_regular_price', |
|
606 | + 'compare' => '>', |
|
607 | + 'value' => 0, |
|
608 | + ), |
|
609 | + array( |
|
610 | + 'key'=> '_sale_price', |
|
611 | + 'compare' => '=', |
|
612 | + 'value' => '', |
|
613 | + ), |
|
614 | + ); |
|
615 | + |
|
616 | + return $args; |
|
617 | + |
|
618 | + |
|
619 | + } // get_paid_courses_meta_query |
|
620 | + |
|
621 | + /** |
|
622 | + * Get all WooCommerce non-free product id's |
|
623 | + * |
|
624 | + * @since 1.9.0 |
|
625 | + * |
|
626 | + * @return array $woocommerce_paid_product_ids |
|
627 | + */ |
|
628 | + public static function get_paid_product_ids(){ |
|
629 | + |
|
630 | + // get all the paid WooCommerce products that has regular |
|
631 | + // and sale price greater than 0 |
|
632 | + // will be used later to check for course with the id as meta |
|
633 | + $paid_product_ids_with_sale = get_posts( self::get_paid_products_on_sale_query_args() ); |
|
634 | + |
|
635 | + // get all the paid WooCommerce products that has regular price |
|
636 | + // greater than 0 without a sale price |
|
637 | + // will be used later to check for course with the id as meta |
|
638 | + $paid_product_ids_without_sale = get_posts( self::get_paid_products_not_on_sale_query_args() ); |
|
639 | + |
|
640 | + // combine products ID's with regular and sale price grater than zero and those without |
|
641 | + // sale but regular price greater than zero |
|
642 | + $woocommerce_paid_product_ids = array_merge( $paid_product_ids_with_sale, $paid_product_ids_without_sale ); |
|
643 | + |
|
644 | + // if |
|
645 | + if( empty($woocommerce_paid_product_ids) ){ |
|
646 | + return array( ); |
|
647 | + } |
|
648 | + return $woocommerce_paid_product_ids; |
|
649 | + |
|
650 | + } |
|
651 | + |
|
652 | + /** |
|
653 | + * Get all free courses. |
|
654 | + * |
|
655 | + * This course that have a WC product attached |
|
656 | + * that has a price or sale price of zero and |
|
657 | + * other courses with no WooCommerce products |
|
658 | + * attached. |
|
659 | + * |
|
660 | + * @since 1.9.0 |
|
661 | + * |
|
662 | + * @return array |
|
663 | + */ |
|
664 | + public static function get_free_courses(){ |
|
665 | + |
|
666 | + $free_course_query_args = Sensei_Course::get_default_query_args(); |
|
667 | + $free_course_query_args[ 'meta_query' ] = self::get_free_courses_meta_query_args(); |
|
668 | + |
|
669 | + // don't show any paid courses |
|
670 | + $courses = self::get_paid_courses(); |
|
671 | + $ids = array(); |
|
672 | + foreach( $courses as $course ){ |
|
673 | + $ids[] = $course->ID; |
|
674 | + } |
|
675 | + $free_course_query_args[ 'post__not_in' ] = $ids; |
|
676 | + |
|
677 | + return get_posts( $free_course_query_args ); |
|
678 | + |
|
679 | + } |
|
680 | + |
|
681 | + /** |
|
682 | + * Return all products that are not free |
|
683 | + * |
|
684 | + * @since 1.9.0 |
|
685 | + * @return array |
|
686 | + */ |
|
687 | + public static function get_paid_courses(){ |
|
688 | + |
|
689 | + $paid_course_query_args = Sensei_Course::get_default_query_args(); |
|
690 | + |
|
691 | + $paid_course_query_args[ 'meta_query' ] = self::get_paid_courses_meta_query_args(); |
|
692 | + |
|
693 | + return get_posts( $paid_course_query_args ); |
|
694 | + } |
|
695 | + |
|
696 | + /** |
|
697 | + * Show the WooCommerce add to cart button for the current course |
|
698 | + * |
|
699 | + * The function will only show the button if |
|
700 | + * 1- the user can buy the course |
|
701 | + * 2- if they have completed their pre-requisite |
|
702 | + * 3- if the course has a valid product attached |
|
703 | + * |
|
704 | + * @since 1.9.0 |
|
705 | + * @param int $course_id |
|
706 | + * @return string $html markup for the button or nothing if user not allowed to buy |
|
707 | + */ |
|
708 | + public static function the_add_to_cart_button_html( $course_id ){ |
|
709 | + |
|
710 | + if ( ! Sensei_Course::is_prerequisite_complete( $course_id )) { |
|
711 | + return ''; |
|
712 | + } |
|
713 | + |
|
714 | + $wc_post_id = self::get_course_product_id( $course_id ); |
|
715 | + |
|
716 | + // Check if customer purchased the product |
|
717 | + if ( self::has_customer_bought_product( get_current_user_id(), $wc_post_id ) |
|
718 | + || empty( $wc_post_id ) ) { |
|
719 | + |
|
720 | + return ''; |
|
721 | + |
|
722 | + } |
|
723 | + |
|
724 | + // based on simple.php in WC templates/single-product/add-to-cart/ |
|
725 | + // Get the product |
|
726 | + $product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id ); |
|
727 | + |
|
728 | + // do not show the button for invalid products, non purchasable products, out |
|
729 | + // of stock product or if course is already in cart |
|
730 | + if ( ! isset ( $product ) |
|
731 | + || ! is_object( $product ) |
|
732 | + || ! $product->is_purchasable() |
|
733 | + || ! $product->is_in_stock() |
|
734 | + || self::is_course_in_cart( $wc_post_id ) ) { |
|
735 | + |
|
736 | + return ''; |
|
737 | + |
|
738 | + } |
|
739 | + |
|
740 | + // |
|
741 | + // button output: |
|
742 | + // |
|
743 | + ?> |
|
744 | 744 | |
745 | 745 | <form action="<?php echo esc_url( $product->add_to_cart_url() ); ?>" |
746 | 746 | class="cart" |
@@ -773,54 +773,54 @@ discard block |
||
773 | 773 | </form> |
774 | 774 | |
775 | 775 | <?php |
776 | - } // end the_add_to_cart_button_html |
|
776 | + } // end the_add_to_cart_button_html |
|
777 | 777 | |
778 | - /** |
|
779 | - * Alter the no permissions message on the single course page |
|
780 | - * Changes the message to a WooCommerce specific message. |
|
781 | - * |
|
782 | - * @since 1.9.0 |
|
783 | - * |
|
784 | - * @param $message |
|
785 | - * @param $post_id |
|
786 | - * |
|
787 | - * @return string $message |
|
788 | - */ |
|
789 | - public static function alter_no_permissions_message( $message, $post_id ){ |
|
778 | + /** |
|
779 | + * Alter the no permissions message on the single course page |
|
780 | + * Changes the message to a WooCommerce specific message. |
|
781 | + * |
|
782 | + * @since 1.9.0 |
|
783 | + * |
|
784 | + * @param $message |
|
785 | + * @param $post_id |
|
786 | + * |
|
787 | + * @return string $message |
|
788 | + */ |
|
789 | + public static function alter_no_permissions_message( $message, $post_id ){ |
|
790 | 790 | |
791 | - if( empty( $post_id ) || 'course'!=get_post_type( $post_id ) ){ |
|
792 | - return $message; |
|
793 | - } |
|
791 | + if( empty( $post_id ) || 'course'!=get_post_type( $post_id ) ){ |
|
792 | + return $message; |
|
793 | + } |
|
794 | 794 | |
795 | - $product_id = self::get_course_product_id( $post_id ); |
|
795 | + $product_id = self::get_course_product_id( $post_id ); |
|
796 | 796 | |
797 | - if( ! $product_id |
|
798 | - || self::has_customer_bought_product( get_current_user_id(),$product_id ) ){ |
|
797 | + if( ! $product_id |
|
798 | + || self::has_customer_bought_product( get_current_user_id(),$product_id ) ){ |
|
799 | 799 | |
800 | - return $message; |
|
800 | + return $message; |
|
801 | 801 | |
802 | - } |
|
802 | + } |
|
803 | 803 | |
804 | - ob_start(); |
|
805 | - self::the_course_no_permissions_message( $post_id ); |
|
806 | - $woocommerce_course_no_permissions_message = ob_get_clean(); |
|
804 | + ob_start(); |
|
805 | + self::the_course_no_permissions_message( $post_id ); |
|
806 | + $woocommerce_course_no_permissions_message = ob_get_clean(); |
|
807 | 807 | |
808 | - return $woocommerce_course_no_permissions_message ; |
|
808 | + return $woocommerce_course_no_permissions_message ; |
|
809 | 809 | |
810 | - } |
|
811 | - /** |
|
812 | - * Show the no permissions message when a user is logged in |
|
813 | - * and have not yet purchased the current course |
|
814 | - * |
|
815 | - * @since 1.9.0 |
|
816 | - */ |
|
817 | - public static function the_course_no_permissions_message( $course_id ){ |
|
810 | + } |
|
811 | + /** |
|
812 | + * Show the no permissions message when a user is logged in |
|
813 | + * and have not yet purchased the current course |
|
814 | + * |
|
815 | + * @since 1.9.0 |
|
816 | + */ |
|
817 | + public static function the_course_no_permissions_message( $course_id ){ |
|
818 | 818 | |
819 | - // login link |
|
820 | - $my_courses_page_id = intval( Sensei()->settings->settings[ 'my_course_page' ] ); |
|
821 | - $login_link = '<a href="' . esc_url( get_permalink( $my_courses_page_id ) ) . '">' . __( 'log in', 'woothemes-sensei' ) . '</a>'; |
|
819 | + // login link |
|
820 | + $my_courses_page_id = intval( Sensei()->settings->settings[ 'my_course_page' ] ); |
|
821 | + $login_link = '<a href="' . esc_url( get_permalink( $my_courses_page_id ) ) . '">' . __( 'log in', 'woothemes-sensei' ) . '</a>'; |
|
822 | 822 | |
823 | - ?> |
|
823 | + ?> |
|
824 | 824 | |
825 | 825 | <span class="add-to-cart-login"> |
826 | 826 | <?php echo sprintf( __( 'Or %1$s to access your purchased courses', 'woothemes-sensei' ), $login_link ); ?> |
@@ -828,763 +828,763 @@ discard block |
||
828 | 828 | |
829 | 829 | <?php } |
830 | 830 | |
831 | - /** |
|
832 | - * Checks if a user has bought a product item. |
|
833 | - * |
|
834 | - * @since 1.9.0 |
|
835 | - * |
|
836 | - * @param int $user_id |
|
837 | - * @param int $product_id |
|
838 | - * |
|
839 | - * @return bool |
|
840 | - */ |
|
841 | - public static function has_customer_bought_product ( $user_id, $product_id ){ |
|
831 | + /** |
|
832 | + * Checks if a user has bought a product item. |
|
833 | + * |
|
834 | + * @since 1.9.0 |
|
835 | + * |
|
836 | + * @param int $user_id |
|
837 | + * @param int $product_id |
|
838 | + * |
|
839 | + * @return bool |
|
840 | + */ |
|
841 | + public static function has_customer_bought_product ( $user_id, $product_id ){ |
|
842 | 842 | |
843 | - $orders = get_posts( array( |
|
844 | - 'numberposts' => -1, |
|
845 | - 'post_type' => 'shope_order', |
|
846 | - 'meta_key' => '_customer_user', |
|
847 | - 'meta_value' => intval( $user_id ), |
|
848 | - 'post_status' => array( 'wc-complete','wc-processing' ), |
|
849 | - ) ); |
|
843 | + $orders = get_posts( array( |
|
844 | + 'numberposts' => -1, |
|
845 | + 'post_type' => 'shope_order', |
|
846 | + 'meta_key' => '_customer_user', |
|
847 | + 'meta_value' => intval( $user_id ), |
|
848 | + 'post_status' => array( 'wc-complete','wc-processing' ), |
|
849 | + ) ); |
|
850 | 850 | |
851 | - foreach ( $orders as $order_id ) { |
|
851 | + foreach ( $orders as $order_id ) { |
|
852 | 852 | |
853 | - $order = new WC_Order( $order_id->ID ); |
|
854 | - |
|
855 | - // wc-active is the subscriptions complete status |
|
856 | - if ( ! in_array( $order->post_status, array( 'wc-complete','wc-processing' ) ) ){ |
|
857 | - |
|
858 | - continue; |
|
853 | + $order = new WC_Order( $order_id->ID ); |
|
854 | + |
|
855 | + // wc-active is the subscriptions complete status |
|
856 | + if ( ! in_array( $order->post_status, array( 'wc-complete','wc-processing' ) ) ){ |
|
857 | + |
|
858 | + continue; |
|
859 | 859 | |
860 | - } |
|
860 | + } |
|
861 | 861 | |
862 | - if ( ! ( 0 < sizeof( $order->get_items() ) ) ) { |
|
862 | + if ( ! ( 0 < sizeof( $order->get_items() ) ) ) { |
|
863 | 863 | |
864 | - continue; |
|
864 | + continue; |
|
865 | 865 | |
866 | - } |
|
866 | + } |
|
867 | 867 | |
868 | - foreach( $order->get_items() as $item ) { |
|
868 | + foreach( $order->get_items() as $item ) { |
|
869 | 869 | |
870 | - // Check if user has bought product |
|
871 | - if ( $item['product_id'] == $product_id || $item['variation_id'] == $product_id ) { |
|
870 | + // Check if user has bought product |
|
871 | + if ( $item['product_id'] == $product_id || $item['variation_id'] == $product_id ) { |
|
872 | 872 | |
873 | - // Check if user has an active subscription for product |
|
874 | - if( class_exists( 'WC_Subscriptions_Manager' ) ) { |
|
875 | - $sub_key = wcs_get_subscription( $order ); |
|
876 | - if( $sub_key ) { |
|
877 | - $sub = wcs_get_subscription( $sub_key ); |
|
878 | - if( $sub && isset( $sub['status'] ) ) { |
|
879 | - if( 'active' == $sub['status'] ) { |
|
880 | - return true; |
|
881 | - } else { |
|
882 | - return false; |
|
883 | - } |
|
884 | - } |
|
885 | - } |
|
886 | - } |
|
873 | + // Check if user has an active subscription for product |
|
874 | + if( class_exists( 'WC_Subscriptions_Manager' ) ) { |
|
875 | + $sub_key = wcs_get_subscription( $order ); |
|
876 | + if( $sub_key ) { |
|
877 | + $sub = wcs_get_subscription( $sub_key ); |
|
878 | + if( $sub && isset( $sub['status'] ) ) { |
|
879 | + if( 'active' == $sub['status'] ) { |
|
880 | + return true; |
|
881 | + } else { |
|
882 | + return false; |
|
883 | + } |
|
884 | + } |
|
885 | + } |
|
886 | + } |
|
887 | 887 | |
888 | - // Customer has bought product |
|
889 | - return true; |
|
890 | - } // End If Statement |
|
888 | + // Customer has bought product |
|
889 | + return true; |
|
890 | + } // End If Statement |
|
891 | 891 | |
892 | - } // End For each item |
|
892 | + } // End For each item |
|
893 | 893 | |
894 | - } // End For each order |
|
894 | + } // End For each order |
|
895 | 895 | |
896 | - } // end has customer bought product |
|
896 | + } // end has customer bought product |
|
897 | 897 | |
898 | - /** |
|
899 | - * Return the product id for the given course |
|
900 | - * |
|
901 | - * @since 1.9.0 |
|
902 | - * |
|
903 | - * @param int $course_id |
|
904 | - * |
|
905 | - * @return string $woocommerce_product_id or false if none exist |
|
906 | - * |
|
907 | - */ |
|
908 | - public static function get_course_product_id( $course_id ){ |
|
898 | + /** |
|
899 | + * Return the product id for the given course |
|
900 | + * |
|
901 | + * @since 1.9.0 |
|
902 | + * |
|
903 | + * @param int $course_id |
|
904 | + * |
|
905 | + * @return string $woocommerce_product_id or false if none exist |
|
906 | + * |
|
907 | + */ |
|
908 | + public static function get_course_product_id( $course_id ){ |
|
909 | 909 | |
910 | - $product_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
910 | + $product_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
911 | 911 | |
912 | - if( empty( $product_id ) || 'product' != get_post_type( $product_id ) ){ |
|
913 | - return false; |
|
914 | - } |
|
912 | + if( empty( $product_id ) || 'product' != get_post_type( $product_id ) ){ |
|
913 | + return false; |
|
914 | + } |
|
915 | 915 | |
916 | - return $product_id; |
|
916 | + return $product_id; |
|
917 | 917 | |
918 | - } |
|
918 | + } |
|
919 | 919 | |
920 | - /** |
|
921 | - * Alter the body classes adding WooCommerce to the body |
|
922 | - * |
|
923 | - * @param array $classes |
|
924 | - * @return array |
|
925 | - */ |
|
926 | - public static function add_woocommerce_body_class( $classes ){ |
|
920 | + /** |
|
921 | + * Alter the body classes adding WooCommerce to the body |
|
922 | + * |
|
923 | + * @param array $classes |
|
924 | + * @return array |
|
925 | + */ |
|
926 | + public static function add_woocommerce_body_class( $classes ){ |
|
927 | 927 | |
928 | - if( ! in_array( 'woocommerce', $classes ) ){ |
|
928 | + if( ! in_array( 'woocommerce', $classes ) ){ |
|
929 | 929 | |
930 | - $classes[] ='woocommerce'; |
|
930 | + $classes[] ='woocommerce'; |
|
931 | 931 | |
932 | - } |
|
932 | + } |
|
933 | 933 | |
934 | - return $classes; |
|
934 | + return $classes; |
|
935 | 935 | |
936 | - } |
|
936 | + } |
|
937 | 937 | |
938 | - /** |
|
939 | - * Responds to when a subscription product is purchased |
|
940 | - * |
|
941 | - * @since 1.2.0 |
|
942 | - * @since 1.9.0 move to class Sensei_WC |
|
943 | - * |
|
944 | - * @param WC_Order $order |
|
945 | - * |
|
946 | - * @return void |
|
947 | - */ |
|
948 | - public static function activate_subscription( $order ) { |
|
938 | + /** |
|
939 | + * Responds to when a subscription product is purchased |
|
940 | + * |
|
941 | + * @since 1.2.0 |
|
942 | + * @since 1.9.0 move to class Sensei_WC |
|
943 | + * |
|
944 | + * @param WC_Order $order |
|
945 | + * |
|
946 | + * @return void |
|
947 | + */ |
|
948 | + public static function activate_subscription( $order ) { |
|
949 | 949 | |
950 | - $order_user = get_user_by('id', $order->user_id); |
|
951 | - $user['ID'] = $order_user->ID; |
|
952 | - $user['user_login'] = $order_user->user_login; |
|
953 | - $user['user_email'] = $order_user->user_email; |
|
954 | - $user['user_url'] = $order_user->user_url; |
|
950 | + $order_user = get_user_by('id', $order->user_id); |
|
951 | + $user['ID'] = $order_user->ID; |
|
952 | + $user['user_login'] = $order_user->user_login; |
|
953 | + $user['user_email'] = $order_user->user_email; |
|
954 | + $user['user_url'] = $order_user->user_url; |
|
955 | 955 | |
956 | - // Run through each product ordered |
|
957 | - if ( ! sizeof($order->get_items() )>0 ) { |
|
956 | + // Run through each product ordered |
|
957 | + if ( ! sizeof($order->get_items() )>0 ) { |
|
958 | 958 | |
959 | - return; |
|
959 | + return; |
|
960 | 960 | |
961 | - } |
|
961 | + } |
|
962 | 962 | |
963 | - foreach($order->get_items() as $item) { |
|
963 | + foreach($order->get_items() as $item) { |
|
964 | 964 | |
965 | - $product_type = ''; |
|
965 | + $product_type = ''; |
|
966 | 966 | |
967 | - if (isset($item['variation_id']) && $item['variation_id'] > 0) { |
|
967 | + if (isset($item['variation_id']) && $item['variation_id'] > 0) { |
|
968 | 968 | |
969 | - $item_id = $item['variation_id']; |
|
970 | - $product_type = 'subscription_variation'; |
|
969 | + $item_id = $item['variation_id']; |
|
970 | + $product_type = 'subscription_variation'; |
|
971 | 971 | |
972 | - } else { |
|
972 | + } else { |
|
973 | 973 | |
974 | - $item_id = $item['product_id']; |
|
974 | + $item_id = $item['product_id']; |
|
975 | 975 | |
976 | - } // End If Statement |
|
976 | + } // End If Statement |
|
977 | 977 | |
978 | - $_product = self::get_product_object( $item_id, $product_type ); |
|
978 | + $_product = self::get_product_object( $item_id, $product_type ); |
|
979 | 979 | |
980 | - // Get courses that use the WC product |
|
981 | - $courses = array(); |
|
980 | + // Get courses that use the WC product |
|
981 | + $courses = array(); |
|
982 | 982 | |
983 | - if ( ! in_array( $product_type, self::get_subscription_types() ) ) { |
|
983 | + if ( ! in_array( $product_type, self::get_subscription_types() ) ) { |
|
984 | 984 | |
985 | - $courses = Sensei()->course->get_product_courses( $item_id ); |
|
985 | + $courses = Sensei()->course->get_product_courses( $item_id ); |
|
986 | 986 | |
987 | - } // End If Statement |
|
987 | + } // End If Statement |
|
988 | 988 | |
989 | - // Loop and add the user to the course. |
|
990 | - foreach ( $courses as $course_item ){ |
|
989 | + // Loop and add the user to the course. |
|
990 | + foreach ( $courses as $course_item ){ |
|
991 | 991 | |
992 | - Sensei_Utils::user_start_course( intval( $user['ID'] ), $course_item->ID ); |
|
992 | + Sensei_Utils::user_start_course( intval( $user['ID'] ), $course_item->ID ); |
|
993 | 993 | |
994 | - } // End For Loop |
|
994 | + } // End For Loop |
|
995 | 995 | |
996 | - } // End For Loop |
|
996 | + } // End For Loop |
|
997 | 997 | |
998 | - } // End activate_subscription() |
|
998 | + } // End activate_subscription() |
|
999 | 999 | |
1000 | - /** |
|
1001 | - * Adds detail to to the WooCommerce order |
|
1002 | - * |
|
1003 | - * @since 1.4.5 |
|
1004 | - * @since 1.9.0 function moved to class Sensei_WC and renamed from sensei_woocommerce_email_course_details to email_course_details |
|
1005 | - * |
|
1006 | - * @param WC_Order $order |
|
1007 | - * |
|
1008 | - * @return void |
|
1009 | - */ |
|
1010 | - public static function email_course_details( $order ){ |
|
1000 | + /** |
|
1001 | + * Adds detail to to the WooCommerce order |
|
1002 | + * |
|
1003 | + * @since 1.4.5 |
|
1004 | + * @since 1.9.0 function moved to class Sensei_WC and renamed from sensei_woocommerce_email_course_details to email_course_details |
|
1005 | + * |
|
1006 | + * @param WC_Order $order |
|
1007 | + * |
|
1008 | + * @return void |
|
1009 | + */ |
|
1010 | + public static function email_course_details( $order ){ |
|
1011 | 1011 | |
1012 | - global $woocommerce; |
|
1012 | + global $woocommerce; |
|
1013 | 1013 | |
1014 | - // exit early if not wc-completed or wc-processing |
|
1015 | - if( 'wc-completed' != $order->post_status |
|
1016 | - && 'wc-processing' != $order->post_status ) { |
|
1017 | - return; |
|
1018 | - } |
|
1014 | + // exit early if not wc-completed or wc-processing |
|
1015 | + if( 'wc-completed' != $order->post_status |
|
1016 | + && 'wc-processing' != $order->post_status ) { |
|
1017 | + return; |
|
1018 | + } |
|
1019 | 1019 | |
1020 | - $order_items = $order->get_items(); |
|
1021 | - $order_id = $order->id; |
|
1020 | + $order_items = $order->get_items(); |
|
1021 | + $order_id = $order->id; |
|
1022 | 1022 | |
1023 | - //If object have items go through them all to find course |
|
1024 | - if ( 0 < sizeof( $order_items ) ) { |
|
1023 | + //If object have items go through them all to find course |
|
1024 | + if ( 0 < sizeof( $order_items ) ) { |
|
1025 | 1025 | |
1026 | - $course_details_html = '<h2>' . __( 'Course details', 'woothemes-sensei' ) . '</h2>'; |
|
1027 | - $order_contains_courses = false; |
|
1026 | + $course_details_html = '<h2>' . __( 'Course details', 'woothemes-sensei' ) . '</h2>'; |
|
1027 | + $order_contains_courses = false; |
|
1028 | 1028 | |
1029 | 1029 | |
1030 | - foreach ( $order_items as $item ) { |
|
1030 | + foreach ( $order_items as $item ) { |
|
1031 | 1031 | |
1032 | - $product_type = ''; |
|
1033 | - if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
1034 | - // If item has variation_id then its from variation |
|
1035 | - $item_id = $item['variation_id']; |
|
1036 | - $product_type = 'variation'; |
|
1037 | - } else { |
|
1038 | - // If not its real product set its id to item_id |
|
1039 | - $item_id = $item['product_id']; |
|
1040 | - } // End If Statement |
|
1032 | + $product_type = ''; |
|
1033 | + if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
1034 | + // If item has variation_id then its from variation |
|
1035 | + $item_id = $item['variation_id']; |
|
1036 | + $product_type = 'variation'; |
|
1037 | + } else { |
|
1038 | + // If not its real product set its id to item_id |
|
1039 | + $item_id = $item['product_id']; |
|
1040 | + } // End If Statement |
|
1041 | 1041 | |
1042 | - $user_id = get_post_meta( $order_id, '_customer_user', true ); |
|
1042 | + $user_id = get_post_meta( $order_id, '_customer_user', true ); |
|
1043 | 1043 | |
1044 | - if( $user_id ) { |
|
1044 | + if( $user_id ) { |
|
1045 | 1045 | |
1046 | - // Get all courses for product |
|
1047 | - $args = array( |
|
1048 | - 'posts_per_page' => -1, |
|
1049 | - 'post_type' => 'course', |
|
1050 | - 'meta_query' => array( |
|
1051 | - array( |
|
1052 | - 'key' => '_course_woocommerce_product', |
|
1053 | - 'value' => $item_id |
|
1054 | - ) |
|
1055 | - ), |
|
1056 | - 'orderby' => 'menu_order date', |
|
1057 | - 'order' => 'ASC', |
|
1058 | - ); |
|
1059 | - $courses = get_posts( $args ); |
|
1046 | + // Get all courses for product |
|
1047 | + $args = array( |
|
1048 | + 'posts_per_page' => -1, |
|
1049 | + 'post_type' => 'course', |
|
1050 | + 'meta_query' => array( |
|
1051 | + array( |
|
1052 | + 'key' => '_course_woocommerce_product', |
|
1053 | + 'value' => $item_id |
|
1054 | + ) |
|
1055 | + ), |
|
1056 | + 'orderby' => 'menu_order date', |
|
1057 | + 'order' => 'ASC', |
|
1058 | + ); |
|
1059 | + $courses = get_posts( $args ); |
|
1060 | 1060 | |
1061 | - if( $courses && count( $courses ) > 0 ) { |
|
1061 | + if( $courses && count( $courses ) > 0 ) { |
|
1062 | 1062 | |
1063 | - foreach( $courses as $course ) { |
|
1063 | + foreach( $courses as $course ) { |
|
1064 | 1064 | |
1065 | - $title = $course->post_title; |
|
1066 | - $permalink = get_permalink( $course->ID ); |
|
1067 | - $order_contains_courses = true; |
|
1068 | - $course_details_html .= '<p><strong>' . sprintf( __( 'View course: %1$s', 'woothemes-sensei' ), '</strong><a href="' . esc_url( $permalink ) . '">' . $title . '</a>' ) . '</p>'; |
|
1069 | - } |
|
1065 | + $title = $course->post_title; |
|
1066 | + $permalink = get_permalink( $course->ID ); |
|
1067 | + $order_contains_courses = true; |
|
1068 | + $course_details_html .= '<p><strong>' . sprintf( __( 'View course: %1$s', 'woothemes-sensei' ), '</strong><a href="' . esc_url( $permalink ) . '">' . $title . '</a>' ) . '</p>'; |
|
1069 | + } |
|
1070 | 1070 | |
1071 | 1071 | |
1072 | - } // end if has courses |
|
1072 | + } // end if has courses |
|
1073 | 1073 | |
1074 | - } // end if $userPid |
|
1074 | + } // end if $userPid |
|
1075 | 1075 | |
1076 | - } // end for each order item |
|
1076 | + } // end for each order item |
|
1077 | 1077 | |
1078 | - // Output Course details |
|
1079 | - if( $order_contains_courses ){ |
|
1078 | + // Output Course details |
|
1079 | + if( $order_contains_courses ){ |
|
1080 | 1080 | |
1081 | - echo $course_details_html; |
|
1081 | + echo $course_details_html; |
|
1082 | 1082 | |
1083 | - } |
|
1083 | + } |
|
1084 | 1084 | |
1085 | 1085 | |
1086 | - } // end if order items not empty |
|
1086 | + } // end if order items not empty |
|
1087 | 1087 | |
1088 | - }// end email_course_details |
|
1088 | + }// end email_course_details |
|
1089 | 1089 | |
1090 | - /** |
|
1091 | - * sensei_woocommerce_complete_order description |
|
1092 | - * @since 1.0.3 |
|
1093 | - * @access public |
|
1094 | - * @param int $order_id WC order ID |
|
1095 | - * @return void |
|
1096 | - */ |
|
1097 | - public static function complete_order ( $order_id = 0 ) { |
|
1090 | + /** |
|
1091 | + * sensei_woocommerce_complete_order description |
|
1092 | + * @since 1.0.3 |
|
1093 | + * @access public |
|
1094 | + * @param int $order_id WC order ID |
|
1095 | + * @return void |
|
1096 | + */ |
|
1097 | + public static function complete_order ( $order_id = 0 ) { |
|
1098 | 1098 | |
1099 | - $order_user = array(); |
|
1099 | + $order_user = array(); |
|
1100 | 1100 | |
1101 | - // Check for WooCommerce |
|
1102 | - if ( Sensei_WC::is_woocommerce_active() && ( 0 < $order_id ) ) { |
|
1103 | - // Get order object |
|
1104 | - $order = new WC_Order( $order_id ); |
|
1105 | - $user = get_user_by( 'id', $order->get_user_id() ); |
|
1106 | - $order_user['ID'] = $user->ID; |
|
1107 | - $order_user['user_login'] = $user->user_login; |
|
1108 | - $order_user['user_email'] = $user->user_email; |
|
1109 | - $order_user['user_url'] = $user->user_url; |
|
1110 | - // Run through each product ordered |
|
1111 | - if ( 0 < sizeof( $order->get_items() ) ) { |
|
1101 | + // Check for WooCommerce |
|
1102 | + if ( Sensei_WC::is_woocommerce_active() && ( 0 < $order_id ) ) { |
|
1103 | + // Get order object |
|
1104 | + $order = new WC_Order( $order_id ); |
|
1105 | + $user = get_user_by( 'id', $order->get_user_id() ); |
|
1106 | + $order_user['ID'] = $user->ID; |
|
1107 | + $order_user['user_login'] = $user->user_login; |
|
1108 | + $order_user['user_email'] = $user->user_email; |
|
1109 | + $order_user['user_url'] = $user->user_url; |
|
1110 | + // Run through each product ordered |
|
1111 | + if ( 0 < sizeof( $order->get_items() ) ) { |
|
1112 | 1112 | |
1113 | - foreach( $order->get_items() as $item ) { |
|
1113 | + foreach( $order->get_items() as $item ) { |
|
1114 | 1114 | |
1115 | - $product_type = ''; |
|
1116 | - if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
1115 | + $product_type = ''; |
|
1116 | + if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
1117 | 1117 | |
1118 | - $item_id = $item['variation_id']; |
|
1119 | - $product_type = 'variation'; |
|
1118 | + $item_id = $item['variation_id']; |
|
1119 | + $product_type = 'variation'; |
|
1120 | 1120 | |
1121 | - } else { |
|
1121 | + } else { |
|
1122 | 1122 | |
1123 | - $item_id = $item['product_id']; |
|
1123 | + $item_id = $item['product_id']; |
|
1124 | 1124 | |
1125 | - } // End If Statement |
|
1125 | + } // End If Statement |
|
1126 | 1126 | |
1127 | - $_product = Sensei_WC::get_product_object( $item_id, $product_type ); |
|
1127 | + $_product = Sensei_WC::get_product_object( $item_id, $product_type ); |
|
1128 | 1128 | |
1129 | - // Get courses that use the WC product |
|
1130 | - $courses = Sensei()->course->get_product_courses( $_product->id ); |
|
1129 | + // Get courses that use the WC product |
|
1130 | + $courses = Sensei()->course->get_product_courses( $_product->id ); |
|
1131 | 1131 | |
1132 | - // Loop and update those courses |
|
1133 | - foreach ( $courses as $course_item ) { |
|
1132 | + // Loop and update those courses |
|
1133 | + foreach ( $courses as $course_item ) { |
|
1134 | 1134 | |
1135 | - $update_course = Sensei()->woocommerce_course_update( $course_item->ID, $order_user ); |
|
1135 | + $update_course = Sensei()->woocommerce_course_update( $course_item->ID, $order_user ); |
|
1136 | 1136 | |
1137 | - } // End For Loop |
|
1137 | + } // End For Loop |
|
1138 | 1138 | |
1139 | - } // End For Loop |
|
1139 | + } // End For Loop |
|
1140 | 1140 | |
1141 | - } // End If Statement |
|
1142 | - // Add meta to indicate that payment has been completed successfully |
|
1143 | - update_post_meta( $order_id, 'sensei_payment_complete', '1' ); |
|
1141 | + } // End If Statement |
|
1142 | + // Add meta to indicate that payment has been completed successfully |
|
1143 | + update_post_meta( $order_id, 'sensei_payment_complete', '1' ); |
|
1144 | 1144 | |
1145 | - } // End If Statement |
|
1145 | + } // End If Statement |
|
1146 | 1146 | |
1147 | - } // End sensei_woocommerce_complete_order() |
|
1147 | + } // End sensei_woocommerce_complete_order() |
|
1148 | 1148 | |
1149 | - /** |
|
1150 | - * Responds to when an order is cancelled. |
|
1151 | - * |
|
1152 | - * @since 1.2.0 |
|
1153 | - * @since 1.9.0 Move function to the Sensei_WC class |
|
1154 | - * @param integer| WC_Order $order_id order ID |
|
1155 | - * @return void |
|
1156 | - */ |
|
1157 | - public static function cancel_order ( $order_id ) { |
|
1149 | + /** |
|
1150 | + * Responds to when an order is cancelled. |
|
1151 | + * |
|
1152 | + * @since 1.2.0 |
|
1153 | + * @since 1.9.0 Move function to the Sensei_WC class |
|
1154 | + * @param integer| WC_Order $order_id order ID |
|
1155 | + * @return void |
|
1156 | + */ |
|
1157 | + public static function cancel_order ( $order_id ) { |
|
1158 | 1158 | |
1159 | - // Get order object |
|
1160 | - if( is_object( $order_id ) ){ |
|
1159 | + // Get order object |
|
1160 | + if( is_object( $order_id ) ){ |
|
1161 | 1161 | |
1162 | - $order = $order_id; |
|
1162 | + $order = $order_id; |
|
1163 | 1163 | |
1164 | - }else{ |
|
1164 | + }else{ |
|
1165 | 1165 | |
1166 | - $order = new WC_Order( $order_id ); |
|
1167 | - } |
|
1166 | + $order = new WC_Order( $order_id ); |
|
1167 | + } |
|
1168 | 1168 | |
1169 | - // Run through each product ordered |
|
1170 | - if ( 0 < sizeof( $order->get_items() ) ) { |
|
1169 | + // Run through each product ordered |
|
1170 | + if ( 0 < sizeof( $order->get_items() ) ) { |
|
1171 | 1171 | |
1172 | - // Get order user |
|
1173 | - $user_id = $order->__get( 'user_id' ); |
|
1172 | + // Get order user |
|
1173 | + $user_id = $order->__get( 'user_id' ); |
|
1174 | 1174 | |
1175 | - foreach( $order->get_items() as $item ) { |
|
1175 | + foreach( $order->get_items() as $item ) { |
|
1176 | 1176 | |
1177 | - $product_type = ''; |
|
1178 | - if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
1177 | + $product_type = ''; |
|
1178 | + if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
1179 | 1179 | |
1180 | - $item_id = $item['variation_id']; |
|
1181 | - $product_type = 'variation'; |
|
1180 | + $item_id = $item['variation_id']; |
|
1181 | + $product_type = 'variation'; |
|
1182 | 1182 | |
1183 | - } else { |
|
1183 | + } else { |
|
1184 | 1184 | |
1185 | - $item_id = $item['product_id']; |
|
1185 | + $item_id = $item['product_id']; |
|
1186 | 1186 | |
1187 | - } // End If Statement |
|
1187 | + } // End If Statement |
|
1188 | 1188 | |
1189 | - $_product = Sensei_WC::get_product_object( $item_id, $product_type ); |
|
1189 | + $_product = Sensei_WC::get_product_object( $item_id, $product_type ); |
|
1190 | 1190 | |
1191 | - // Get courses that use the WC product |
|
1192 | - $courses = array(); |
|
1193 | - $courses = Sensei()->course->get_product_courses( $item_id ); |
|
1191 | + // Get courses that use the WC product |
|
1192 | + $courses = array(); |
|
1193 | + $courses = Sensei()->course->get_product_courses( $item_id ); |
|
1194 | 1194 | |
1195 | - // Loop and update those courses |
|
1196 | - foreach ($courses as $course_item){ |
|
1195 | + // Loop and update those courses |
|
1196 | + foreach ($courses as $course_item){ |
|
1197 | 1197 | |
1198 | - // Check and Remove course from courses user meta |
|
1199 | - $dataset_changes = Sensei_Utils::sensei_remove_user_from_course( $course_item->ID, $user_id ); |
|
1198 | + // Check and Remove course from courses user meta |
|
1199 | + $dataset_changes = Sensei_Utils::sensei_remove_user_from_course( $course_item->ID, $user_id ); |
|
1200 | 1200 | |
1201 | - } // End For Loop |
|
1201 | + } // End For Loop |
|
1202 | 1202 | |
1203 | - } // End For Loop |
|
1203 | + } // End For Loop |
|
1204 | 1204 | |
1205 | - } // End If Statement |
|
1205 | + } // End If Statement |
|
1206 | 1206 | |
1207 | - } // End sensei_woocommerce_cancel_order() |
|
1207 | + } // End sensei_woocommerce_cancel_order() |
|
1208 | 1208 | |
1209 | - /** |
|
1210 | - * Returns the WooCommerce Product Object |
|
1211 | - * |
|
1212 | - * The code caters for pre and post WooCommerce 2.2 installations. |
|
1213 | - * |
|
1214 | - * @since 1.1.1 |
|
1215 | - * @access public |
|
1216 | - * @param integer $wc_product_id Product ID or Variation ID |
|
1217 | - * @param string $product_type '' or 'variation' |
|
1218 | - * @return WC_Product $wc_product_object |
|
1219 | - */ |
|
1220 | - public static function get_product_object ( $wc_product_id = 0, $product_type = '' ) { |
|
1209 | + /** |
|
1210 | + * Returns the WooCommerce Product Object |
|
1211 | + * |
|
1212 | + * The code caters for pre and post WooCommerce 2.2 installations. |
|
1213 | + * |
|
1214 | + * @since 1.1.1 |
|
1215 | + * @access public |
|
1216 | + * @param integer $wc_product_id Product ID or Variation ID |
|
1217 | + * @param string $product_type '' or 'variation' |
|
1218 | + * @return WC_Product $wc_product_object |
|
1219 | + */ |
|
1220 | + public static function get_product_object ( $wc_product_id = 0, $product_type = '' ) { |
|
1221 | 1221 | |
1222 | - $wc_product_object = false; |
|
1223 | - if ( 0 < intval( $wc_product_id ) ) { |
|
1222 | + $wc_product_object = false; |
|
1223 | + if ( 0 < intval( $wc_product_id ) ) { |
|
1224 | 1224 | |
1225 | - // Get the product |
|
1226 | - if ( function_exists( 'wc_get_product' ) ) { |
|
1225 | + // Get the product |
|
1226 | + if ( function_exists( 'wc_get_product' ) ) { |
|
1227 | 1227 | |
1228 | - $wc_product_object = wc_get_product( $wc_product_id ); // Post WC 2.3 |
|
1228 | + $wc_product_object = wc_get_product( $wc_product_id ); // Post WC 2.3 |
|
1229 | 1229 | |
1230 | - } elseif ( function_exists( 'get_product' ) ) { |
|
1230 | + } elseif ( function_exists( 'get_product' ) ) { |
|
1231 | 1231 | |
1232 | - $wc_product_object = get_product( $wc_product_id ); // Post WC 2.0 |
|
1232 | + $wc_product_object = get_product( $wc_product_id ); // Post WC 2.0 |
|
1233 | 1233 | |
1234 | - } else { |
|
1234 | + } else { |
|
1235 | 1235 | |
1236 | - // Pre WC 2.0 |
|
1237 | - if ( 'variation' == $product_type || 'subscription_variation' == $product_type ) { |
|
1236 | + // Pre WC 2.0 |
|
1237 | + if ( 'variation' == $product_type || 'subscription_variation' == $product_type ) { |
|
1238 | 1238 | |
1239 | - $wc_product_object = new WC_Product_Variation( $wc_product_id ); |
|
1239 | + $wc_product_object = new WC_Product_Variation( $wc_product_id ); |
|
1240 | 1240 | |
1241 | - } else { |
|
1241 | + } else { |
|
1242 | 1242 | |
1243 | - $wc_product_object = new WC_Product( $wc_product_id ); |
|
1243 | + $wc_product_object = new WC_Product( $wc_product_id ); |
|
1244 | 1244 | |
1245 | - } // End If Statement |
|
1245 | + } // End If Statement |
|
1246 | 1246 | |
1247 | - } // End If Statement |
|
1247 | + } // End If Statement |
|
1248 | 1248 | |
1249 | - } // End If Statement |
|
1249 | + } // End If Statement |
|
1250 | 1250 | |
1251 | - return $wc_product_object; |
|
1251 | + return $wc_product_object; |
|
1252 | 1252 | |
1253 | - } // End sensei_get_woocommerce_product_object() |
|
1253 | + } // End sensei_get_woocommerce_product_object() |
|
1254 | 1254 | |
1255 | - /** |
|
1256 | - * If customer has purchased the course, update Sensei to indicate that they are taking the course. |
|
1257 | - * |
|
1258 | - * @since 1.0.0 |
|
1259 | - * @since 1.9.0 move to class Sensei_WC |
|
1260 | - * |
|
1261 | - * @param int $course_id (default: 0) |
|
1262 | - * @param array/Object $order_user (default: array()) Specific user's data. |
|
1263 | - * |
|
1264 | - * @return bool|int |
|
1265 | - */ |
|
1266 | - public static function course_update ( $course_id = 0, $order_user = array() ) { |
|
1255 | + /** |
|
1256 | + * If customer has purchased the course, update Sensei to indicate that they are taking the course. |
|
1257 | + * |
|
1258 | + * @since 1.0.0 |
|
1259 | + * @since 1.9.0 move to class Sensei_WC |
|
1260 | + * |
|
1261 | + * @param int $course_id (default: 0) |
|
1262 | + * @param array/Object $order_user (default: array()) Specific user's data. |
|
1263 | + * |
|
1264 | + * @return bool|int |
|
1265 | + */ |
|
1266 | + public static function course_update ( $course_id = 0, $order_user = array() ) { |
|
1267 | 1267 | |
1268 | - global $current_user; |
|
1268 | + global $current_user; |
|
1269 | 1269 | |
1270 | - if ( ! isset( $current_user ) || !$current_user->ID > 0 ) return false; |
|
1270 | + if ( ! isset( $current_user ) || !$current_user->ID > 0 ) return false; |
|
1271 | 1271 | |
1272 | - $data_update = false; |
|
1272 | + $data_update = false; |
|
1273 | 1273 | |
1274 | - // Get the product ID |
|
1275 | - $wc_post_id = get_post_meta( intval( $course_id ), '_course_woocommerce_product', true ); |
|
1274 | + // Get the product ID |
|
1275 | + $wc_post_id = get_post_meta( intval( $course_id ), '_course_woocommerce_product', true ); |
|
1276 | 1276 | |
1277 | - // Check if in the admin |
|
1278 | - if ( is_admin() ) { |
|
1277 | + // Check if in the admin |
|
1278 | + if ( is_admin() ) { |
|
1279 | 1279 | |
1280 | - $user_login = $order_user['user_login']; |
|
1281 | - $user_email = $order_user['user_email']; |
|
1282 | - $user_url = $order_user['user_url']; |
|
1283 | - $user_id = $order_user['ID']; |
|
1280 | + $user_login = $order_user['user_login']; |
|
1281 | + $user_email = $order_user['user_email']; |
|
1282 | + $user_url = $order_user['user_url']; |
|
1283 | + $user_id = $order_user['ID']; |
|
1284 | 1284 | |
1285 | - } else { |
|
1285 | + } else { |
|
1286 | 1286 | |
1287 | - $user_login = $current_user->user_login; |
|
1288 | - $user_email = $current_user->user_email; |
|
1289 | - $user_url = $current_user->user_url; |
|
1290 | - $user_id = $current_user->ID; |
|
1287 | + $user_login = $current_user->user_login; |
|
1288 | + $user_email = $current_user->user_email; |
|
1289 | + $user_url = $current_user->user_url; |
|
1290 | + $user_id = $current_user->ID; |
|
1291 | 1291 | |
1292 | - } // End If Statement |
|
1292 | + } // End If Statement |
|
1293 | 1293 | |
1294 | - // This doesn't appear to be purely WooCommerce related. Should it be in a separate function? |
|
1295 | - $course_prerequisite_id = (int) get_post_meta( $course_id, '_course_prerequisite', true ); |
|
1296 | - if( 0 < absint( $course_prerequisite_id ) ) { |
|
1294 | + // This doesn't appear to be purely WooCommerce related. Should it be in a separate function? |
|
1295 | + $course_prerequisite_id = (int) get_post_meta( $course_id, '_course_prerequisite', true ); |
|
1296 | + if( 0 < absint( $course_prerequisite_id ) ) { |
|
1297 | 1297 | |
1298 | - $prereq_course_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, intval( $user_id ) ); |
|
1299 | - if ( ! $prereq_course_complete ) { |
|
1298 | + $prereq_course_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, intval( $user_id ) ); |
|
1299 | + if ( ! $prereq_course_complete ) { |
|
1300 | 1300 | |
1301 | - // Remove all course user meta |
|
1302 | - return Sensei_Utils::sensei_remove_user_from_course( $course_id, $user_id ); |
|
1301 | + // Remove all course user meta |
|
1302 | + return Sensei_Utils::sensei_remove_user_from_course( $course_id, $user_id ); |
|
1303 | 1303 | |
1304 | - } |
|
1305 | - } |
|
1304 | + } |
|
1305 | + } |
|
1306 | 1306 | |
1307 | - $is_user_taking_course = Sensei_Utils::user_started_course( intval( $course_id ), intval( $user_id ) ); |
|
1307 | + $is_user_taking_course = Sensei_Utils::user_started_course( intval( $course_id ), intval( $user_id ) ); |
|
1308 | 1308 | |
1309 | - if( ! $is_user_taking_course ) { |
|
1309 | + if( ! $is_user_taking_course ) { |
|
1310 | 1310 | |
1311 | - if ( Sensei_WC::is_woocommerce_active() && Sensei_WC::has_customer_bought_product( $user_id, $wc_post_id ) && ( 0 < $wc_post_id ) ) { |
|
1311 | + if ( Sensei_WC::is_woocommerce_active() && Sensei_WC::has_customer_bought_product( $user_id, $wc_post_id ) && ( 0 < $wc_post_id ) ) { |
|
1312 | 1312 | |
1313 | - $activity_logged = Sensei_Utils::user_start_course( intval( $user_id), intval( $course_id ) ); |
|
1313 | + $activity_logged = Sensei_Utils::user_start_course( intval( $user_id), intval( $course_id ) ); |
|
1314 | 1314 | |
1315 | - $is_user_taking_course = false; |
|
1316 | - if ( true == $activity_logged ) { |
|
1315 | + $is_user_taking_course = false; |
|
1316 | + if ( true == $activity_logged ) { |
|
1317 | 1317 | |
1318 | - $is_user_taking_course = true; |
|
1318 | + $is_user_taking_course = true; |
|
1319 | 1319 | |
1320 | - } // End If Statement |
|
1320 | + } // End If Statement |
|
1321 | 1321 | |
1322 | - } // End If Statement |
|
1323 | - }// end if is user taking course |
|
1322 | + } // End If Statement |
|
1323 | + }// end if is user taking course |
|
1324 | 1324 | |
1325 | - return $is_user_taking_course; |
|
1325 | + return $is_user_taking_course; |
|
1326 | 1326 | |
1327 | - } // End course_update() |
|
1327 | + } // End course_update() |
|
1328 | 1328 | |
1329 | - /** |
|
1330 | - * Disable guest checkout if a course product is in the cart |
|
1331 | - * |
|
1332 | - * @since 1.1.0 |
|
1333 | - * @since 1.9.0 move to class Sensei_WC |
|
1334 | - * |
|
1335 | - * @param boolean $guest_checkout Current guest checkout setting |
|
1336 | - * |
|
1337 | - * @return boolean Modified guest checkout setting |
|
1338 | - */ |
|
1339 | - public static function disable_guest_checkout( $guest_checkout ) { |
|
1329 | + /** |
|
1330 | + * Disable guest checkout if a course product is in the cart |
|
1331 | + * |
|
1332 | + * @since 1.1.0 |
|
1333 | + * @since 1.9.0 move to class Sensei_WC |
|
1334 | + * |
|
1335 | + * @param boolean $guest_checkout Current guest checkout setting |
|
1336 | + * |
|
1337 | + * @return boolean Modified guest checkout setting |
|
1338 | + */ |
|
1339 | + public static function disable_guest_checkout( $guest_checkout ) { |
|
1340 | 1340 | |
1341 | - if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { |
|
1341 | + if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { |
|
1342 | 1342 | |
1343 | - if( isset( WC()->cart->cart_contents ) && count( WC()->cart->cart_contents ) > 0 ) { |
|
1343 | + if( isset( WC()->cart->cart_contents ) && count( WC()->cart->cart_contents ) > 0 ) { |
|
1344 | 1344 | |
1345 | - foreach( WC()->cart->cart_contents as $cart_key => $product ) { |
|
1346 | - if( isset( $product['product_id'] ) ) { |
|
1345 | + foreach( WC()->cart->cart_contents as $cart_key => $product ) { |
|
1346 | + if( isset( $product['product_id'] ) ) { |
|
1347 | 1347 | |
1348 | - $args = array( |
|
1349 | - 'posts_per_page' => -1, |
|
1350 | - 'post_type' => 'course', |
|
1351 | - 'meta_query' => array( |
|
1352 | - array( |
|
1353 | - 'key' => '_course_woocommerce_product', |
|
1354 | - 'value' => $product['product_id'] |
|
1355 | - ) |
|
1356 | - ) |
|
1357 | - ); |
|
1348 | + $args = array( |
|
1349 | + 'posts_per_page' => -1, |
|
1350 | + 'post_type' => 'course', |
|
1351 | + 'meta_query' => array( |
|
1352 | + array( |
|
1353 | + 'key' => '_course_woocommerce_product', |
|
1354 | + 'value' => $product['product_id'] |
|
1355 | + ) |
|
1356 | + ) |
|
1357 | + ); |
|
1358 | 1358 | |
1359 | - $posts = get_posts( $args ); |
|
1359 | + $posts = get_posts( $args ); |
|
1360 | 1360 | |
1361 | - if( $posts && count( $posts ) > 0 ) { |
|
1361 | + if( $posts && count( $posts ) > 0 ) { |
|
1362 | 1362 | |
1363 | - foreach( $posts as $course ) { |
|
1364 | - $guest_checkout = ''; |
|
1365 | - break; |
|
1363 | + foreach( $posts as $course ) { |
|
1364 | + $guest_checkout = ''; |
|
1365 | + break; |
|
1366 | 1366 | |
1367 | - } |
|
1368 | - } |
|
1367 | + } |
|
1368 | + } |
|
1369 | 1369 | |
1370 | - } |
|
1370 | + } |
|
1371 | 1371 | |
1372 | - } |
|
1372 | + } |
|
1373 | 1373 | |
1374 | - } |
|
1375 | - } |
|
1374 | + } |
|
1375 | + } |
|
1376 | 1376 | |
1377 | - return $guest_checkout; |
|
1377 | + return $guest_checkout; |
|
1378 | 1378 | |
1379 | - }// end disable_guest_checkout |
|
1379 | + }// end disable_guest_checkout |
|
1380 | 1380 | |
1381 | - /** |
|
1382 | - * Change order status with virtual products to completed |
|
1383 | - * |
|
1384 | - * @since 1.1.0 |
|
1385 | - * @since 1.9.0 move to class Sensei_WC |
|
1386 | - * |
|
1387 | - * @param string $order_status |
|
1388 | - * @param int $order_id |
|
1389 | - * |
|
1390 | - * @return string |
|
1391 | - **/ |
|
1392 | - public static function virtual_order_payment_complete( $order_status, $order_id ) { |
|
1381 | + /** |
|
1382 | + * Change order status with virtual products to completed |
|
1383 | + * |
|
1384 | + * @since 1.1.0 |
|
1385 | + * @since 1.9.0 move to class Sensei_WC |
|
1386 | + * |
|
1387 | + * @param string $order_status |
|
1388 | + * @param int $order_id |
|
1389 | + * |
|
1390 | + * @return string |
|
1391 | + **/ |
|
1392 | + public static function virtual_order_payment_complete( $order_status, $order_id ) { |
|
1393 | 1393 | |
1394 | - $order = new WC_Order( $order_id ); |
|
1394 | + $order = new WC_Order( $order_id ); |
|
1395 | 1395 | |
1396 | - if ( ! isset ( $order ) ) return ''; |
|
1396 | + if ( ! isset ( $order ) ) return ''; |
|
1397 | 1397 | |
1398 | - if ( $order_status == 'wc-processing' && ( $order->post_status == 'wc-on-hold' || $order->post_status == 'wc-pending' || $order->post_status == 'wc-failed' ) ) { |
|
1398 | + if ( $order_status == 'wc-processing' && ( $order->post_status == 'wc-on-hold' || $order->post_status == 'wc-pending' || $order->post_status == 'wc-failed' ) ) { |
|
1399 | 1399 | |
1400 | - $virtual_order = true; |
|
1400 | + $virtual_order = true; |
|
1401 | 1401 | |
1402 | - if ( count( $order->get_items() ) > 0 ) { |
|
1402 | + if ( count( $order->get_items() ) > 0 ) { |
|
1403 | 1403 | |
1404 | - foreach( $order->get_items() as $item ) { |
|
1404 | + foreach( $order->get_items() as $item ) { |
|
1405 | 1405 | |
1406 | - if ( $item['product_id'] > 0 ) { |
|
1407 | - $_product = $order->get_product_from_item( $item ); |
|
1408 | - if ( ! $_product->is_virtual() ) { |
|
1406 | + if ( $item['product_id'] > 0 ) { |
|
1407 | + $_product = $order->get_product_from_item( $item ); |
|
1408 | + if ( ! $_product->is_virtual() ) { |
|
1409 | 1409 | |
1410 | - $virtual_order = false; |
|
1411 | - break; |
|
1410 | + $virtual_order = false; |
|
1411 | + break; |
|
1412 | 1412 | |
1413 | - } // End If Statement |
|
1413 | + } // End If Statement |
|
1414 | 1414 | |
1415 | - } // End If Statement |
|
1415 | + } // End If Statement |
|
1416 | 1416 | |
1417 | - } // End For Loop |
|
1417 | + } // End For Loop |
|
1418 | 1418 | |
1419 | - } // End If Statement |
|
1419 | + } // End If Statement |
|
1420 | 1420 | |
1421 | - // virtual order, mark as completed |
|
1422 | - if ( $virtual_order ) { |
|
1421 | + // virtual order, mark as completed |
|
1422 | + if ( $virtual_order ) { |
|
1423 | 1423 | |
1424 | - return 'completed'; |
|
1424 | + return 'completed'; |
|
1425 | 1425 | |
1426 | - } // End If Statement |
|
1426 | + } // End If Statement |
|
1427 | 1427 | |
1428 | - } // End If Statement |
|
1428 | + } // End If Statement |
|
1429 | 1429 | |
1430 | - return $order_status; |
|
1430 | + return $order_status; |
|
1431 | 1431 | |
1432 | - }// end virtual_order_payment_complete |
|
1432 | + }// end virtual_order_payment_complete |
|
1433 | 1433 | |
1434 | 1434 | |
1435 | - /** |
|
1436 | - * Determine if the user has and active subscription to give them access |
|
1437 | - * to the requested resource. |
|
1438 | - * |
|
1439 | - * @since 1.9.0 |
|
1440 | - * |
|
1441 | - * @param boolean$user_access_permission |
|
1442 | - * @param integer $user_id |
|
1443 | - * @return boolean $user_access_permission |
|
1444 | - */ |
|
1445 | - public static function get_subscription_permission( $user_access_permission, $user_id ){ |
|
1435 | + /** |
|
1436 | + * Determine if the user has and active subscription to give them access |
|
1437 | + * to the requested resource. |
|
1438 | + * |
|
1439 | + * @since 1.9.0 |
|
1440 | + * |
|
1441 | + * @param boolean$user_access_permission |
|
1442 | + * @param integer $user_id |
|
1443 | + * @return boolean $user_access_permission |
|
1444 | + */ |
|
1445 | + public static function get_subscription_permission( $user_access_permission, $user_id ){ |
|
1446 | 1446 | |
1447 | - global $post; |
|
1447 | + global $post; |
|
1448 | 1448 | |
1449 | - // ignore the current case if the following conditions are met |
|
1450 | - if ( ! class_exists( 'WC_Subscriptions' ) || empty( $user_id ) |
|
1451 | - || ! in_array( $post->post_type, array( 'course','lesson','quiz' ) ) |
|
1452 | - || ! wcs_user_has_subscription( $user_id) ){ |
|
1449 | + // ignore the current case if the following conditions are met |
|
1450 | + if ( ! class_exists( 'WC_Subscriptions' ) || empty( $user_id ) |
|
1451 | + || ! in_array( $post->post_type, array( 'course','lesson','quiz' ) ) |
|
1452 | + || ! wcs_user_has_subscription( $user_id) ){ |
|
1453 | 1453 | |
1454 | - return $user_access_permission; |
|
1454 | + return $user_access_permission; |
|
1455 | 1455 | |
1456 | - } |
|
1456 | + } |
|
1457 | 1457 | |
1458 | - // at this user has a subscription |
|
1459 | - // is the subscription on the the current course? |
|
1458 | + // at this user has a subscription |
|
1459 | + // is the subscription on the the current course? |
|
1460 | 1460 | |
1461 | - $course_id = 0; |
|
1462 | - if ( 'course' == $post->post_type ){ |
|
1461 | + $course_id = 0; |
|
1462 | + if ( 'course' == $post->post_type ){ |
|
1463 | 1463 | |
1464 | - $course_id = $post->ID; |
|
1464 | + $course_id = $post->ID; |
|
1465 | 1465 | |
1466 | - } elseif ( 'lesson' == $post->post_type ) { |
|
1466 | + } elseif ( 'lesson' == $post->post_type ) { |
|
1467 | 1467 | |
1468 | - $course_id = Sensei()->lesson->get_course_id( $post->ID ); |
|
1468 | + $course_id = Sensei()->lesson->get_course_id( $post->ID ); |
|
1469 | 1469 | |
1470 | - } else { |
|
1470 | + } else { |
|
1471 | 1471 | |
1472 | - $lesson_id = Sensei()->quiz->get_lesson_id( $post->ID ); |
|
1473 | - $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
1472 | + $lesson_id = Sensei()->quiz->get_lesson_id( $post->ID ); |
|
1473 | + $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
1474 | 1474 | |
1475 | - } |
|
1475 | + } |
|
1476 | 1476 | |
1477 | - // if the course has no subscription WooCommerce product attached to return the permissions as is |
|
1478 | - $product_id = Sensei_WC::get_course_product_id( $course_id ); |
|
1479 | - $product = wc_get_product( $product_id ); |
|
1480 | - if( ! in_array( $product->get_type(), self::get_subscription_types() ) ){ |
|
1477 | + // if the course has no subscription WooCommerce product attached to return the permissions as is |
|
1478 | + $product_id = Sensei_WC::get_course_product_id( $course_id ); |
|
1479 | + $product = wc_get_product( $product_id ); |
|
1480 | + if( ! in_array( $product->get_type(), self::get_subscription_types() ) ){ |
|
1481 | 1481 | |
1482 | - return $user_access_permission; |
|
1482 | + return $user_access_permission; |
|
1483 | 1483 | |
1484 | - } |
|
1484 | + } |
|
1485 | 1485 | |
1486 | - // give access if user has active subscription on the product otherwise restrict it. |
|
1487 | - // also check if the user was added to the course directly after the subscription started. |
|
1488 | - if( wcs_user_has_subscription( $user_id, $product_id, 'active' ) |
|
1489 | - || wcs_user_has_subscription( $user_id, $product_id, 'pending-cancel' ) |
|
1490 | - || self::was_user_added_without_subscription( $user_id, $product_id, $course_id ) ){ |
|
1486 | + // give access if user has active subscription on the product otherwise restrict it. |
|
1487 | + // also check if the user was added to the course directly after the subscription started. |
|
1488 | + if( wcs_user_has_subscription( $user_id, $product_id, 'active' ) |
|
1489 | + || wcs_user_has_subscription( $user_id, $product_id, 'pending-cancel' ) |
|
1490 | + || self::was_user_added_without_subscription( $user_id, $product_id, $course_id ) ){ |
|
1491 | 1491 | |
1492 | - $user_access_permission = true; |
|
1492 | + $user_access_permission = true; |
|
1493 | 1493 | |
1494 | - }else{ |
|
1494 | + }else{ |
|
1495 | 1495 | |
1496 | - $user_access_permission = false; |
|
1497 | - // do not show the WC permissions message |
|
1498 | - remove_filter( 'sensei_the_no_permissions_message', array( 'Sensei_WC', 'alter_no_permissions_message' ), 20, 2 ); |
|
1499 | - Sensei()->permissions_message['title'] = __( 'No active subscription', 'woothemes-sensei' ); |
|
1500 | - Sensei()->permissions_message['message'] = __( 'Sorry, you do not have an access to this content without an active subscription.', 'woothemes-sensei' ); |
|
1501 | - } |
|
1496 | + $user_access_permission = false; |
|
1497 | + // do not show the WC permissions message |
|
1498 | + remove_filter( 'sensei_the_no_permissions_message', array( 'Sensei_WC', 'alter_no_permissions_message' ), 20, 2 ); |
|
1499 | + Sensei()->permissions_message['title'] = __( 'No active subscription', 'woothemes-sensei' ); |
|
1500 | + Sensei()->permissions_message['message'] = __( 'Sorry, you do not have an access to this content without an active subscription.', 'woothemes-sensei' ); |
|
1501 | + } |
|
1502 | 1502 | |
1503 | - return $user_access_permission; |
|
1503 | + return $user_access_permission; |
|
1504 | 1504 | |
1505 | - } // end get_subscription_permission |
|
1505 | + } // end get_subscription_permission |
|
1506 | 1506 | |
1507 | - /** |
|
1508 | - * Get all the valid subscription types. |
|
1509 | - * |
|
1510 | - * @since 1.9.0 |
|
1511 | - * @return array |
|
1512 | - */ |
|
1513 | - public static function get_subscription_types(){ |
|
1507 | + /** |
|
1508 | + * Get all the valid subscription types. |
|
1509 | + * |
|
1510 | + * @since 1.9.0 |
|
1511 | + * @return array |
|
1512 | + */ |
|
1513 | + public static function get_subscription_types(){ |
|
1514 | 1514 | |
1515 | - return array( 'subscription','subscription_variation','variable-subscription' ); |
|
1515 | + return array( 'subscription','subscription_variation','variable-subscription' ); |
|
1516 | 1516 | |
1517 | - } |
|
1517 | + } |
|
1518 | 1518 | |
1519 | - /** |
|
1520 | - * Compare the user's subscriptions end date with the date |
|
1521 | - * the user was added to the course. If the user was added after |
|
1522 | - * the subscription ended they were manually added and this will return |
|
1523 | - * true. |
|
1524 | - * |
|
1525 | - * Important to note that all subscriptions for the user is compared. |
|
1526 | - * |
|
1527 | - * @since 1.9.0 |
|
1528 | - * |
|
1529 | - * @param $user_id |
|
1530 | - * @param $product_id |
|
1531 | - * @param $course_id |
|
1532 | - * |
|
1533 | - * @return bool |
|
1534 | - */ |
|
1535 | - public static function was_user_added_without_subscription($user_id, $product_id, $course_id ){ |
|
1519 | + /** |
|
1520 | + * Compare the user's subscriptions end date with the date |
|
1521 | + * the user was added to the course. If the user was added after |
|
1522 | + * the subscription ended they were manually added and this will return |
|
1523 | + * true. |
|
1524 | + * |
|
1525 | + * Important to note that all subscriptions for the user is compared. |
|
1526 | + * |
|
1527 | + * @since 1.9.0 |
|
1528 | + * |
|
1529 | + * @param $user_id |
|
1530 | + * @param $product_id |
|
1531 | + * @param $course_id |
|
1532 | + * |
|
1533 | + * @return bool |
|
1534 | + */ |
|
1535 | + public static function was_user_added_without_subscription($user_id, $product_id, $course_id ){ |
|
1536 | 1536 | |
1537 | - $course_start_date = ''; |
|
1538 | - $subscription_start_date = ''; |
|
1539 | - $is_a_subscription =''; |
|
1540 | - $was_user_added_without_subscription = true; |
|
1537 | + $course_start_date = ''; |
|
1538 | + $subscription_start_date = ''; |
|
1539 | + $is_a_subscription =''; |
|
1540 | + $was_user_added_without_subscription = true; |
|
1541 | 1541 | |
1542 | - // if user is not on the course they were not added |
|
1543 | - if( ! Sensei_Utils::user_started_course( $course_id, $user_id ) ){ |
|
1542 | + // if user is not on the course they were not added |
|
1543 | + if( ! Sensei_Utils::user_started_course( $course_id, $user_id ) ){ |
|
1544 | 1544 | |
1545 | - return false; |
|
1545 | + return false; |
|
1546 | 1546 | |
1547 | - } |
|
1547 | + } |
|
1548 | 1548 | |
1549 | - // if user doesn't have a subscription and is taking the course |
|
1550 | - // they were added manually |
|
1551 | - if ( ! wcs_user_has_subscription($user_id, $product_id) |
|
1552 | - && Sensei_Utils::user_started_course( $course_id, get_current_user_id() ) ){ |
|
1549 | + // if user doesn't have a subscription and is taking the course |
|
1550 | + // they were added manually |
|
1551 | + if ( ! wcs_user_has_subscription($user_id, $product_id) |
|
1552 | + && Sensei_Utils::user_started_course( $course_id, get_current_user_id() ) ){ |
|
1553 | 1553 | |
1554 | - return true; |
|
1554 | + return true; |
|
1555 | 1555 | |
1556 | - } |
|
1556 | + } |
|
1557 | 1557 | |
1558 | - $course_status = Sensei_Utils::user_course_status( $course_id, $user_id ); |
|
1558 | + $course_status = Sensei_Utils::user_course_status( $course_id, $user_id ); |
|
1559 | 1559 | |
1560 | - // comparing dates setup data |
|
1561 | - $course_start_date = date_create( $course_status->comment_date ); |
|
1562 | - $subscriptions = wcs_get_users_subscriptions( $user_id ); |
|
1560 | + // comparing dates setup data |
|
1561 | + $course_start_date = date_create( $course_status->comment_date ); |
|
1562 | + $subscriptions = wcs_get_users_subscriptions( $user_id ); |
|
1563 | 1563 | |
1564 | - // comparing every subscription |
|
1565 | - foreach( $subscriptions as $subscription ){ |
|
1564 | + // comparing every subscription |
|
1565 | + foreach( $subscriptions as $subscription ){ |
|
1566 | 1566 | |
1567 | - // for the following statuses we know the user was not added |
|
1568 | - // manually |
|
1569 | - $status = $subscription->get_status(); |
|
1570 | - if ( in_array( $status, array( 'pending-canceled', 'active', 'on-hold', 'pending' ) ) ) { |
|
1567 | + // for the following statuses we know the user was not added |
|
1568 | + // manually |
|
1569 | + $status = $subscription->get_status(); |
|
1570 | + if ( in_array( $status, array( 'pending-canceled', 'active', 'on-hold', 'pending' ) ) ) { |
|
1571 | 1571 | |
1572 | - continue; |
|
1572 | + continue; |
|
1573 | 1573 | |
1574 | - } |
|
1574 | + } |
|
1575 | 1575 | |
1576 | - $current_subscription_start_date = date_create( $subscription->modified_date ); |
|
1576 | + $current_subscription_start_date = date_create( $subscription->modified_date ); |
|
1577 | 1577 | |
1578 | - // is the last updated subscription date newer than course start date |
|
1579 | - if ( $current_subscription_start_date > $course_start_date ) { |
|
1578 | + // is the last updated subscription date newer than course start date |
|
1579 | + if ( $current_subscription_start_date > $course_start_date ) { |
|
1580 | 1580 | |
1581 | - return false; |
|
1581 | + return false; |
|
1582 | 1582 | |
1583 | - } |
|
1583 | + } |
|
1584 | 1584 | |
1585 | - } |
|
1585 | + } |
|
1586 | 1586 | |
1587 | - return $was_user_added_without_subscription; |
|
1588 | - } |
|
1587 | + return $was_user_added_without_subscription; |
|
1588 | + } |
|
1589 | 1589 | |
1590 | 1590 | }// end Sensei_WC |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; // security check, don't load file outside WP |
|
2 | +if ( ! defined('ABSPATH')) exit; // security check, don't load file outside WP |
|
3 | 3 | |
4 | 4 | /** |
5 | 5 | * Sensei WooCommerce class |
@@ -11,15 +11,15 @@ discard block |
||
11 | 11 | * @since 1.9.0 |
12 | 12 | */ |
13 | 13 | |
14 | -Class Sensei_WC{ |
|
14 | +Class Sensei_WC { |
|
15 | 15 | /** |
16 | 16 | * Load the files needed for the woocommerce integration. |
17 | 17 | * |
18 | 18 | * @since 1.9.0 |
19 | 19 | */ |
20 | - public static function load_woocommerce_integration_hooks(){ |
|
20 | + public static function load_woocommerce_integration_hooks() { |
|
21 | 21 | |
22 | - require_once( __DIR__ . '/hooks/woocommerce.php' ); |
|
22 | + require_once(__DIR__.'/hooks/woocommerce.php'); |
|
23 | 23 | |
24 | 24 | } |
25 | 25 | /** |
@@ -28,9 +28,9 @@ discard block |
||
28 | 28 | * @since 1.9.0 |
29 | 29 | * @return bool |
30 | 30 | */ |
31 | - public static function is_woocommerce_active(){ |
|
31 | + public static function is_woocommerce_active() { |
|
32 | 32 | |
33 | - $is_woocommerce_enabled_in_settings = isset( Sensei()->settings->settings['woocommerce_enabled'] ) && Sensei()->settings->settings['woocommerce_enabled']; |
|
33 | + $is_woocommerce_enabled_in_settings = isset(Sensei()->settings->settings['woocommerce_enabled']) && Sensei()->settings->settings['woocommerce_enabled']; |
|
34 | 34 | return self::is_woocommerce_present() && $is_woocommerce_enabled_in_settings; |
35 | 35 | |
36 | 36 | } // end is_woocommerce_active |
@@ -45,19 +45,19 @@ discard block |
||
45 | 45 | * |
46 | 46 | * @return bool |
47 | 47 | */ |
48 | - public static function is_woocommerce_present(){ |
|
48 | + public static function is_woocommerce_present() { |
|
49 | 49 | |
50 | - $active_plugins = (array) get_option( 'active_plugins', array() ); |
|
50 | + $active_plugins = (array) get_option('active_plugins', array()); |
|
51 | 51 | |
52 | - if ( is_multisite() ){ |
|
52 | + if (is_multisite()) { |
|
53 | 53 | |
54 | - $active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) ); |
|
54 | + $active_plugins = array_merge($active_plugins, get_site_option('active_sitewide_plugins', array())); |
|
55 | 55 | |
56 | 56 | } |
57 | 57 | |
58 | - $is_woocommerce_plugin_present_and_activated = in_array( 'woocommerce/woocommerce.php', $active_plugins ) || array_key_exists( 'woocommerce/woocommerce.php', $active_plugins ); |
|
58 | + $is_woocommerce_plugin_present_and_activated = in_array('woocommerce/woocommerce.php', $active_plugins) || array_key_exists('woocommerce/woocommerce.php', $active_plugins); |
|
59 | 59 | |
60 | - return class_exists( 'Woocommerce' ) || $is_woocommerce_plugin_present_and_activated; |
|
60 | + return class_exists('Woocommerce') || $is_woocommerce_plugin_present_and_activated; |
|
61 | 61 | |
62 | 62 | }// end is_woocommerce_present |
63 | 63 | |
@@ -70,48 +70,48 @@ discard block |
||
70 | 70 | * @param $course_id |
71 | 71 | * @return array $user_course_orders |
72 | 72 | */ |
73 | - public static function get_learner_course_active_order_id( $user_id, $course_id ){ |
|
73 | + public static function get_learner_course_active_order_id($user_id, $course_id) { |
|
74 | 74 | |
75 | - $course_product_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
75 | + $course_product_id = get_post_meta($course_id, '_course_woocommerce_product', true); |
|
76 | 76 | |
77 | - $orders_query = new WP_Query( array( |
|
77 | + $orders_query = new WP_Query(array( |
|
78 | 78 | 'post_type' => 'shop_order', |
79 | 79 | 'posts_per_page' => -1, |
80 | - 'post_status' => array( 'wc-processing', 'wc-completed' ), |
|
80 | + 'post_status' => array('wc-processing', 'wc-completed'), |
|
81 | 81 | 'meta_key'=> '_customer_user', |
82 | 82 | 'meta_value'=> $user_id, |
83 | - ) ); |
|
83 | + )); |
|
84 | 84 | |
85 | - if( $orders_query->post_count == 0 ){ |
|
85 | + if ($orders_query->post_count == 0) { |
|
86 | 86 | |
87 | 87 | return false; |
88 | 88 | |
89 | 89 | } |
90 | 90 | |
91 | - foreach( $orders_query->get_posts() as $order ){ |
|
91 | + foreach ($orders_query->get_posts() as $order) { |
|
92 | 92 | |
93 | - $order = new WC_Order( $order->ID ); |
|
93 | + $order = new WC_Order($order->ID); |
|
94 | 94 | $items = $order->get_items(); |
95 | 95 | |
96 | - $user_orders = array(); |
|
96 | + $user_orders = array(); |
|
97 | 97 | |
98 | - foreach( $items as $item ){ |
|
98 | + foreach ($items as $item) { |
|
99 | 99 | |
100 | 100 | // if the product id on the order and the one given to this function |
101 | 101 | // this order has been placed by the given user on the given course. |
102 | - $product = wc_get_product( $item['product_id'] ); |
|
102 | + $product = wc_get_product($item['product_id']); |
|
103 | 103 | |
104 | - if ( $product->is_type( 'variable' )) { |
|
104 | + if ($product->is_type('variable')) { |
|
105 | 105 | |
106 | 106 | $item_product_id = $item['variation_id']; |
107 | 107 | |
108 | 108 | } else { |
109 | 109 | |
110 | - $item_product_id = $item['product_id']; |
|
110 | + $item_product_id = $item['product_id']; |
|
111 | 111 | |
112 | 112 | } |
113 | 113 | |
114 | - if( $course_product_id == $item_product_id ){ |
|
114 | + if ($course_product_id == $item_product_id) { |
|
115 | 115 | |
116 | 116 | return $order->id; |
117 | 117 | |
@@ -135,12 +135,12 @@ discard block |
||
135 | 135 | * @param $filter_links |
136 | 136 | * @return mixed |
137 | 137 | */ |
138 | - public static function add_course_archive_wc_filter_links( $filter_links ){ |
|
138 | + public static function add_course_archive_wc_filter_links($filter_links) { |
|
139 | 139 | |
140 | 140 | $free_courses = self::get_free_courses(); |
141 | 141 | $paid_courses = self::get_paid_courses(); |
142 | 142 | |
143 | - if ( empty( $free_courses ) || empty( $paid_courses ) ){ |
|
143 | + if (empty($free_courses) || empty($paid_courses)) { |
|
144 | 144 | // do not show any WooCommerce filters if all courses are |
145 | 145 | // free or if all courses are paid |
146 | 146 | return $filter_links; |
@@ -148,15 +148,15 @@ discard block |
||
148 | 148 | } |
149 | 149 | |
150 | 150 | $filter_links[] = array( |
151 | - 'id'=>'paid' , |
|
152 | - 'url'=> add_query_arg( array( 'course_filter'=>'paid'), Sensei_Course::get_courses_page_url() ), |
|
153 | - 'title'=>__( 'Paid', 'woothemes-sensei' ) |
|
151 | + 'id'=>'paid', |
|
152 | + 'url'=> add_query_arg(array('course_filter'=>'paid'), Sensei_Course::get_courses_page_url()), |
|
153 | + 'title'=>__('Paid', 'woothemes-sensei') |
|
154 | 154 | ); |
155 | 155 | |
156 | 156 | $filter_links[] = array( |
157 | 157 | 'id'=>'free', |
158 | - 'url'=> add_query_arg( array( 'course_filter'=>'free'), Sensei_Course::get_courses_page_url() ), |
|
159 | - 'title'=>__( 'Free', 'woothemes-sensei' ) |
|
158 | + 'url'=> add_query_arg(array('course_filter'=>'free'), Sensei_Course::get_courses_page_url()), |
|
159 | + 'title'=>__('Free', 'woothemes-sensei') |
|
160 | 160 | ); |
161 | 161 | |
162 | 162 | return $filter_links; |
@@ -173,24 +173,24 @@ discard block |
||
173 | 173 | * @param WP_Query $query |
174 | 174 | * @return WP_Query $query |
175 | 175 | */ |
176 | - public static function course_archive_wc_filter_free( $query ){ |
|
176 | + public static function course_archive_wc_filter_free($query) { |
|
177 | 177 | |
178 | - if( isset( $_GET['course_filter'] ) && 'free' == $_GET['course_filter'] |
|
179 | - && 'course' == $query->get( 'post_type') && $query->is_main_query() ){ |
|
178 | + if (isset($_GET['course_filter']) && 'free' == $_GET['course_filter'] |
|
179 | + && 'course' == $query->get('post_type') && $query->is_main_query()) { |
|
180 | 180 | |
181 | 181 | // setup the course meta query |
182 | 182 | $meta_query = self::get_free_courses_meta_query_args(); |
183 | 183 | |
184 | 184 | // manipulate the query to return free courses |
185 | - $query->set('meta_query', $meta_query ); |
|
185 | + $query->set('meta_query', $meta_query); |
|
186 | 186 | |
187 | 187 | // don't show any paid courses |
188 | 188 | $courses = self::get_paid_courses(); |
189 | 189 | $ids = array(); |
190 | - foreach( $courses as $course ){ |
|
190 | + foreach ($courses as $course) { |
|
191 | 191 | $ids[] = $course->ID; |
192 | 192 | } |
193 | - $query->set( 'post__not_in', $ids ); |
|
193 | + $query->set('post__not_in', $ids); |
|
194 | 194 | |
195 | 195 | }// end if course_filter |
196 | 196 | |
@@ -209,16 +209,16 @@ discard block |
||
209 | 209 | * @param WP_Query $query |
210 | 210 | * @return WP_Query $query |
211 | 211 | */ |
212 | - public static function course_archive_wc_filter_paid( $query ){ |
|
212 | + public static function course_archive_wc_filter_paid($query) { |
|
213 | 213 | |
214 | - if( isset( $_GET['course_filter'] ) && 'paid' == $_GET['course_filter'] |
|
215 | - && 'course' == $query->get( 'post_type') && $query->is_main_query() ){ |
|
214 | + if (isset($_GET['course_filter']) && 'paid' == $_GET['course_filter'] |
|
215 | + && 'course' == $query->get('post_type') && $query->is_main_query()) { |
|
216 | 216 | |
217 | 217 | // setup the course meta query |
218 | 218 | $meta_query = self::get_paid_courses_meta_query_args(); |
219 | 219 | |
220 | 220 | // manipulate the query to return free courses |
221 | - $query->set('meta_query', $meta_query ); |
|
221 | + $query->set('meta_query', $meta_query); |
|
222 | 222 | |
223 | 223 | } |
224 | 224 | |
@@ -231,14 +231,14 @@ discard block |
||
231 | 231 | * single courses if woocommerce is active allowing purchase |
232 | 232 | * information and actions to be hooked from WooCommerce. |
233 | 233 | */ |
234 | - public static function do_single_course_wc_single_product_action(){ |
|
234 | + public static function do_single_course_wc_single_product_action() { |
|
235 | 235 | |
236 | 236 | /** |
237 | 237 | * this hooks is documented within the WooCommerce plugin. |
238 | 238 | */ |
239 | - if ( Sensei_WC::is_woocommerce_active() ) { |
|
239 | + if (Sensei_WC::is_woocommerce_active()) { |
|
240 | 240 | |
241 | - do_action( 'woocommerce_before_single_product' ); |
|
241 | + do_action('woocommerce_before_single_product'); |
|
242 | 242 | |
243 | 243 | } // End If Statement |
244 | 244 | |
@@ -259,23 +259,23 @@ discard block |
||
259 | 259 | * @param $user_id |
260 | 260 | * @return bool |
261 | 261 | */ |
262 | - public static function alter_can_user_view_lesson ( $can_user_view_lesson, $lesson_id, $user_id ){ |
|
262 | + public static function alter_can_user_view_lesson($can_user_view_lesson, $lesson_id, $user_id) { |
|
263 | 263 | |
264 | 264 | // check if the course has a valid product attached to it |
265 | 265 | // which the user should have purchased if they want to access |
266 | 266 | // the current lesson |
267 | - $course_id = get_post_meta( $lesson_id , '_lesson_course', true); |
|
268 | - $wc_post_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
267 | + $course_id = get_post_meta($lesson_id, '_lesson_course', true); |
|
268 | + $wc_post_id = get_post_meta($course_id, '_course_woocommerce_product', true); |
|
269 | 269 | $product = Sensei()->sensei_get_woocommerce_product_object($wc_post_id); |
270 | - if( isset ($product) && is_object($product) ){ |
|
270 | + if (isset ($product) && is_object($product)) { |
|
271 | 271 | |
272 | 272 | // valid product found |
273 | - $order_id = self::get_learner_course_active_order_id( $user_id, $course_id ); |
|
273 | + $order_id = self::get_learner_course_active_order_id($user_id, $course_id); |
|
274 | 274 | |
275 | 275 | // product has a successful order so this user may access the content |
276 | 276 | // this function may only return false or the default |
277 | 277 | // returning true may override other negatives which we don't want |
278 | - if( ! $order_id ){ |
|
278 | + if ( ! $order_id) { |
|
279 | 279 | |
280 | 280 | return false; |
281 | 281 | |
@@ -298,23 +298,23 @@ discard block |
||
298 | 298 | */ |
299 | 299 | public static function course_link_from_order( ) { |
300 | 300 | |
301 | - if( ! is_order_received_page() ){ |
|
301 | + if ( ! is_order_received_page()) { |
|
302 | 302 | return; |
303 | 303 | } |
304 | 304 | |
305 | - $order_id = get_query_var( 'order-received' ); |
|
306 | - $order = new WC_Order( $order_id ); |
|
305 | + $order_id = get_query_var('order-received'); |
|
306 | + $order = new WC_Order($order_id); |
|
307 | 307 | |
308 | 308 | // exit early if not wc-completed or wc-processing |
309 | - if( 'wc-completed' != $order->post_status |
|
310 | - && 'wc-processing' != $order->post_status ) { |
|
309 | + if ('wc-completed' != $order->post_status |
|
310 | + && 'wc-processing' != $order->post_status) { |
|
311 | 311 | return; |
312 | 312 | } |
313 | 313 | |
314 | 314 | $course_links = array(); // store the for links for courses purchased |
315 | - foreach ( $order->get_items() as $item ) { |
|
315 | + foreach ($order->get_items() as $item) { |
|
316 | 316 | |
317 | - if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
317 | + if (isset($item['variation_id']) && (0 < $item['variation_id'])) { |
|
318 | 318 | |
319 | 319 | // If item has variation_id then its a variation of the product |
320 | 320 | $item_id = $item['variation_id']; |
@@ -326,28 +326,28 @@ discard block |
||
326 | 326 | |
327 | 327 | } // End If Statement |
328 | 328 | |
329 | - $user_id = get_post_meta( $order->id, '_customer_user', true ); |
|
329 | + $user_id = get_post_meta($order->id, '_customer_user', true); |
|
330 | 330 | |
331 | - if( $user_id ) { |
|
331 | + if ($user_id) { |
|
332 | 332 | |
333 | 333 | // Get all courses for product |
334 | 334 | $args = Sensei_Course::get_default_query_args(); |
335 | - $args['meta_query'] = array( array( |
|
335 | + $args['meta_query'] = array(array( |
|
336 | 336 | 'key' => '_course_woocommerce_product', |
337 | 337 | 'value' => $item_id |
338 | - ) ); |
|
338 | + )); |
|
339 | 339 | $args['orderby'] = 'menu_order date'; |
340 | 340 | $args['order'] = 'ASC'; |
341 | 341 | |
342 | 342 | // loop through courses |
343 | - $courses = get_posts( $args ); |
|
344 | - if( $courses && count( $courses ) > 0 ) { |
|
343 | + $courses = get_posts($args); |
|
344 | + if ($courses && count($courses) > 0) { |
|
345 | 345 | |
346 | - foreach( $courses as $course ) { |
|
346 | + foreach ($courses as $course) { |
|
347 | 347 | |
348 | 348 | $title = $course->post_title; |
349 | - $permalink = get_permalink( $course->ID ); |
|
350 | - $course_links[] .= '<a href="' . esc_url( $permalink ) . '" >' . $title . '</a> '; |
|
349 | + $permalink = get_permalink($course->ID); |
|
350 | + $course_links[] .= '<a href="'.esc_url($permalink).'" >'.$title.'</a> '; |
|
351 | 351 | |
352 | 352 | } // end for each |
353 | 353 | |
@@ -358,24 +358,24 @@ discard block |
||
358 | 358 | }// end loop through orders |
359 | 359 | |
360 | 360 | // add the courses to the WooCommerce notice |
361 | - if( ! empty( $course_links) ){ |
|
361 | + if ( ! empty($course_links)) { |
|
362 | 362 | |
363 | 363 | $courses_html = _nx( |
364 | 364 | 'You have purchased the following course:', |
365 | 365 | 'You have purchased the following courses:', |
366 | - count( $course_links ), |
|
366 | + count($course_links), |
|
367 | 367 | 'Purchase thank you note on Checkout page. The course link(s) will be show', 'woothemes-sensei' |
368 | 368 | ); |
369 | 369 | |
370 | - foreach( $course_links as $link ){ |
|
370 | + foreach ($course_links as $link) { |
|
371 | 371 | |
372 | - $courses_html .= '<li>' . $link . '</li>'; |
|
372 | + $courses_html .= '<li>'.$link.'</li>'; |
|
373 | 373 | |
374 | 374 | } |
375 | 375 | |
376 | 376 | $courses_html .= ' </ul>'; |
377 | 377 | |
378 | - wc_add_notice( $courses_html, 'success' ); |
|
378 | + wc_add_notice($courses_html, 'success'); |
|
379 | 379 | } |
380 | 380 | |
381 | 381 | } // end course_link_order_form |
@@ -388,20 +388,20 @@ discard block |
||
388 | 388 | * |
389 | 389 | * @since 1.9.0 |
390 | 390 | */ |
391 | - public static function course_in_cart_message(){ |
|
391 | + public static function course_in_cart_message() { |
|
392 | 392 | |
393 | 393 | global $post; |
394 | 394 | |
395 | - if( self::is_course_in_cart( $post->ID ) ){ ?> |
|
395 | + if (self::is_course_in_cart($post->ID)) { ?> |
|
396 | 396 | |
397 | 397 | <div class="sensei-message info"> |
398 | 398 | <?php |
399 | 399 | |
400 | - $cart_link = '<a class="cart-complete" href="' . WC()->cart->get_checkout_url() |
|
401 | - . '" title="' . __('complete purchase', 'woothemes-sensei') . '">' |
|
402 | - . __('complete the purchase', 'woothemes-sensei') . '</a>'; |
|
400 | + $cart_link = '<a class="cart-complete" href="'.WC()->cart->get_checkout_url() |
|
401 | + . '" title="'.__('complete purchase', 'woothemes-sensei').'">' |
|
402 | + . __('complete the purchase', 'woothemes-sensei').'</a>'; |
|
403 | 403 | |
404 | - echo sprintf( __('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei'), $cart_link ); |
|
404 | + echo sprintf(__('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei'), $cart_link); |
|
405 | 405 | |
406 | 406 | ?> |
407 | 407 | </div> |
@@ -415,14 +415,14 @@ discard block |
||
415 | 415 | * @param $course_id |
416 | 416 | * @return bool |
417 | 417 | */ |
418 | - public static function is_course_in_cart( $course_id ){ |
|
418 | + public static function is_course_in_cart($course_id) { |
|
419 | 419 | |
420 | - $wc_post_id = absint( get_post_meta( $course_id, '_course_woocommerce_product', true ) ); |
|
421 | - $user_course_status_id = Sensei_Utils::user_started_course( $course_id , get_current_user_id() ); |
|
420 | + $wc_post_id = absint(get_post_meta($course_id, '_course_woocommerce_product', true)); |
|
421 | + $user_course_status_id = Sensei_Utils::user_started_course($course_id, get_current_user_id()); |
|
422 | 422 | |
423 | - if ( 0 < intval( $wc_post_id ) && ! $user_course_status_id ) { |
|
423 | + if (0 < intval($wc_post_id) && ! $user_course_status_id) { |
|
424 | 424 | |
425 | - if ( self::is_product_in_cart( $wc_post_id ) ) { |
|
425 | + if (self::is_product_in_cart($wc_post_id)) { |
|
426 | 426 | |
427 | 427 | return true; |
428 | 428 | |
@@ -440,20 +440,20 @@ discard block |
||
440 | 440 | * @param $product_id |
441 | 441 | * @return bool |
442 | 442 | */ |
443 | - public static function is_product_in_cart( $product_id ){ |
|
443 | + public static function is_product_in_cart($product_id) { |
|
444 | 444 | |
445 | - if ( 0 < $product_id ) { |
|
445 | + if (0 < $product_id) { |
|
446 | 446 | |
447 | - $product = wc_get_product( $product_id ); |
|
447 | + $product = wc_get_product($product_id); |
|
448 | 448 | |
449 | 449 | $parent_id = ''; |
450 | - if( isset( $product->variation_id ) && 0 < intval( $product->variation_id ) ) { |
|
450 | + if (isset($product->variation_id) && 0 < intval($product->variation_id)) { |
|
451 | 451 | $wc_product_id = $product->parent->id; |
452 | 452 | } |
453 | - foreach( WC()->cart->get_cart() as $cart_item_key => $values ) { |
|
453 | + foreach (WC()->cart->get_cart() as $cart_item_key => $values) { |
|
454 | 454 | |
455 | 455 | $cart_product = $values['data']; |
456 | - if( $product_id == $cart_product->id ) { |
|
456 | + if ($product_id == $cart_product->id) { |
|
457 | 457 | |
458 | 458 | return true; |
459 | 459 | |
@@ -475,9 +475,9 @@ discard block |
||
475 | 475 | * @type int $wp_post_id |
476 | 476 | * } |
477 | 477 | */ |
478 | - public static function get_free_product_ids(){ |
|
478 | + public static function get_free_product_ids() { |
|
479 | 479 | |
480 | - return get_posts( array( |
|
480 | + return get_posts(array( |
|
481 | 481 | 'post_type' => 'product', |
482 | 482 | 'posts_per_page' => '1000', |
483 | 483 | 'fields' => 'ids', |
@@ -502,7 +502,7 @@ discard block |
||
502 | 502 | * @since 1.9.0 |
503 | 503 | * @return array $wp_meta_query_param |
504 | 504 | */ |
505 | - public static function get_free_courses_meta_query_args(){ |
|
505 | + public static function get_free_courses_meta_query_args() { |
|
506 | 506 | |
507 | 507 | return array( |
508 | 508 | 'relation' => 'OR', |
@@ -526,7 +526,7 @@ discard block |
||
526 | 526 | * @since 1.9.0 |
527 | 527 | * @return array $wp_query_meta_query_args_param |
528 | 528 | */ |
529 | - public static function get_paid_courses_meta_query_args(){ |
|
529 | + public static function get_paid_courses_meta_query_args() { |
|
530 | 530 | |
531 | 531 | $paid_product_ids = self::get_paid_product_ids(); |
532 | 532 | |
@@ -535,7 +535,7 @@ discard block |
||
535 | 535 | 'key' => '_course_woocommerce_product', |
536 | 536 | // when empty we give a false post_id to ensure the caller doesn't get any courses for their |
537 | 537 | // query |
538 | - 'value' => empty( $paid_product_ids )? '-1000' : $paid_product_ids, |
|
538 | + 'value' => empty($paid_product_ids) ? '-1000' : $paid_product_ids, |
|
539 | 539 | 'compare' => 'IN', |
540 | 540 | ), |
541 | 541 | ); |
@@ -549,7 +549,7 @@ discard block |
||
549 | 549 | * @since 1.9.0 |
550 | 550 | * @return array $product_query_args |
551 | 551 | */ |
552 | - public static function get_paid_products_on_sale_query_args(){ |
|
552 | + public static function get_paid_products_on_sale_query_args() { |
|
553 | 553 | |
554 | 554 | $args = array( |
555 | 555 | 'post_type' => 'product', |
@@ -559,9 +559,9 @@ discard block |
||
559 | 559 | 'suppress_filters' => 0 |
560 | 560 | ); |
561 | 561 | |
562 | - $args[ 'fields' ] = 'ids'; |
|
562 | + $args['fields'] = 'ids'; |
|
563 | 563 | |
564 | - $args[ 'meta_query' ] = array( |
|
564 | + $args['meta_query'] = array( |
|
565 | 565 | 'relation' => 'AND', |
566 | 566 | array( |
567 | 567 | 'key'=> '_regular_price', |
@@ -588,7 +588,7 @@ discard block |
||
588 | 588 | * |
589 | 589 | * @return array |
590 | 590 | */ |
591 | - public static function get_paid_products_not_on_sale_query_args(){ |
|
591 | + public static function get_paid_products_not_on_sale_query_args() { |
|
592 | 592 | |
593 | 593 | $args = array( |
594 | 594 | 'post_type' => 'product', |
@@ -598,8 +598,8 @@ discard block |
||
598 | 598 | 'suppress_filters' => 0 |
599 | 599 | ); |
600 | 600 | |
601 | - $args[ 'fields' ] = 'ids'; |
|
602 | - $args[ 'meta_query' ] = array( |
|
601 | + $args['fields'] = 'ids'; |
|
602 | + $args['meta_query'] = array( |
|
603 | 603 | 'relation' => 'AND', |
604 | 604 | array( |
605 | 605 | 'key'=> '_regular_price', |
@@ -625,24 +625,24 @@ discard block |
||
625 | 625 | * |
626 | 626 | * @return array $woocommerce_paid_product_ids |
627 | 627 | */ |
628 | - public static function get_paid_product_ids(){ |
|
628 | + public static function get_paid_product_ids() { |
|
629 | 629 | |
630 | 630 | // get all the paid WooCommerce products that has regular |
631 | 631 | // and sale price greater than 0 |
632 | 632 | // will be used later to check for course with the id as meta |
633 | - $paid_product_ids_with_sale = get_posts( self::get_paid_products_on_sale_query_args() ); |
|
633 | + $paid_product_ids_with_sale = get_posts(self::get_paid_products_on_sale_query_args()); |
|
634 | 634 | |
635 | 635 | // get all the paid WooCommerce products that has regular price |
636 | 636 | // greater than 0 without a sale price |
637 | 637 | // will be used later to check for course with the id as meta |
638 | - $paid_product_ids_without_sale = get_posts( self::get_paid_products_not_on_sale_query_args() ); |
|
638 | + $paid_product_ids_without_sale = get_posts(self::get_paid_products_not_on_sale_query_args()); |
|
639 | 639 | |
640 | 640 | // combine products ID's with regular and sale price grater than zero and those without |
641 | 641 | // sale but regular price greater than zero |
642 | - $woocommerce_paid_product_ids = array_merge( $paid_product_ids_with_sale, $paid_product_ids_without_sale ); |
|
642 | + $woocommerce_paid_product_ids = array_merge($paid_product_ids_with_sale, $paid_product_ids_without_sale); |
|
643 | 643 | |
644 | 644 | // if |
645 | - if( empty($woocommerce_paid_product_ids) ){ |
|
645 | + if (empty($woocommerce_paid_product_ids)) { |
|
646 | 646 | return array( ); |
647 | 647 | } |
648 | 648 | return $woocommerce_paid_product_ids; |
@@ -661,20 +661,20 @@ discard block |
||
661 | 661 | * |
662 | 662 | * @return array |
663 | 663 | */ |
664 | - public static function get_free_courses(){ |
|
664 | + public static function get_free_courses() { |
|
665 | 665 | |
666 | 666 | $free_course_query_args = Sensei_Course::get_default_query_args(); |
667 | - $free_course_query_args[ 'meta_query' ] = self::get_free_courses_meta_query_args(); |
|
667 | + $free_course_query_args['meta_query'] = self::get_free_courses_meta_query_args(); |
|
668 | 668 | |
669 | 669 | // don't show any paid courses |
670 | 670 | $courses = self::get_paid_courses(); |
671 | 671 | $ids = array(); |
672 | - foreach( $courses as $course ){ |
|
672 | + foreach ($courses as $course) { |
|
673 | 673 | $ids[] = $course->ID; |
674 | 674 | } |
675 | - $free_course_query_args[ 'post__not_in' ] = $ids; |
|
675 | + $free_course_query_args['post__not_in'] = $ids; |
|
676 | 676 | |
677 | - return get_posts( $free_course_query_args ); |
|
677 | + return get_posts($free_course_query_args); |
|
678 | 678 | |
679 | 679 | } |
680 | 680 | |
@@ -684,13 +684,13 @@ discard block |
||
684 | 684 | * @since 1.9.0 |
685 | 685 | * @return array |
686 | 686 | */ |
687 | - public static function get_paid_courses(){ |
|
687 | + public static function get_paid_courses() { |
|
688 | 688 | |
689 | 689 | $paid_course_query_args = Sensei_Course::get_default_query_args(); |
690 | 690 | |
691 | - $paid_course_query_args[ 'meta_query' ] = self::get_paid_courses_meta_query_args(); |
|
691 | + $paid_course_query_args['meta_query'] = self::get_paid_courses_meta_query_args(); |
|
692 | 692 | |
693 | - return get_posts( $paid_course_query_args ); |
|
693 | + return get_posts($paid_course_query_args); |
|
694 | 694 | } |
695 | 695 | |
696 | 696 | /** |
@@ -705,17 +705,17 @@ discard block |
||
705 | 705 | * @param int $course_id |
706 | 706 | * @return string $html markup for the button or nothing if user not allowed to buy |
707 | 707 | */ |
708 | - public static function the_add_to_cart_button_html( $course_id ){ |
|
708 | + public static function the_add_to_cart_button_html($course_id) { |
|
709 | 709 | |
710 | - if ( ! Sensei_Course::is_prerequisite_complete( $course_id )) { |
|
710 | + if ( ! Sensei_Course::is_prerequisite_complete($course_id)) { |
|
711 | 711 | return ''; |
712 | 712 | } |
713 | 713 | |
714 | - $wc_post_id = self::get_course_product_id( $course_id ); |
|
714 | + $wc_post_id = self::get_course_product_id($course_id); |
|
715 | 715 | |
716 | 716 | // Check if customer purchased the product |
717 | - if ( self::has_customer_bought_product( get_current_user_id(), $wc_post_id ) |
|
718 | - || empty( $wc_post_id ) ) { |
|
717 | + if (self::has_customer_bought_product(get_current_user_id(), $wc_post_id) |
|
718 | + || empty($wc_post_id)) { |
|
719 | 719 | |
720 | 720 | return ''; |
721 | 721 | |
@@ -723,15 +723,15 @@ discard block |
||
723 | 723 | |
724 | 724 | // based on simple.php in WC templates/single-product/add-to-cart/ |
725 | 725 | // Get the product |
726 | - $product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id ); |
|
726 | + $product = Sensei()->sensei_get_woocommerce_product_object($wc_post_id); |
|
727 | 727 | |
728 | 728 | // do not show the button for invalid products, non purchasable products, out |
729 | 729 | // of stock product or if course is already in cart |
730 | - if ( ! isset ( $product ) |
|
731 | - || ! is_object( $product ) |
|
730 | + if ( ! isset ($product) |
|
731 | + || ! is_object($product) |
|
732 | 732 | || ! $product->is_purchasable() |
733 | 733 | || ! $product->is_in_stock() |
734 | - || self::is_course_in_cart( $wc_post_id ) ) { |
|
734 | + || self::is_course_in_cart($wc_post_id)) { |
|
735 | 735 | |
736 | 736 | return ''; |
737 | 737 | |
@@ -742,23 +742,23 @@ discard block |
||
742 | 742 | // |
743 | 743 | ?> |
744 | 744 | |
745 | - <form action="<?php echo esc_url( $product->add_to_cart_url() ); ?>" |
|
745 | + <form action="<?php echo esc_url($product->add_to_cart_url()); ?>" |
|
746 | 746 | class="cart" |
747 | 747 | method="post" |
748 | 748 | enctype="multipart/form-data"> |
749 | 749 | |
750 | - <input type="hidden" name="product_id" value="<?php echo esc_attr( $product->id ); ?>" /> |
|
750 | + <input type="hidden" name="product_id" value="<?php echo esc_attr($product->id); ?>" /> |
|
751 | 751 | |
752 | 752 | <input type="hidden" name="quantity" value="1" /> |
753 | 753 | |
754 | - <?php if ( isset( $product->variation_id ) && 0 < intval( $product->variation_id ) ) { ?> |
|
754 | + <?php if (isset($product->variation_id) && 0 < intval($product->variation_id)) { ?> |
|
755 | 755 | |
756 | 756 | <input type="hidden" name="variation_id" value="<?php echo $product->variation_id; ?>" /> |
757 | - <?php if( isset( $product->variation_data ) && is_array( $product->variation_data ) && count( $product->variation_data ) > 0 ) { ?> |
|
757 | + <?php if (isset($product->variation_data) && is_array($product->variation_data) && count($product->variation_data) > 0) { ?> |
|
758 | 758 | |
759 | - <?php foreach( $product->variation_data as $att => $val ) { ?> |
|
759 | + <?php foreach ($product->variation_data as $att => $val) { ?> |
|
760 | 760 | |
761 | - <input type="hidden" name="<?php echo esc_attr( $att ); ?>" id="<?php echo esc_attr( str_replace( 'attribute_', '', $att ) ); ?>" value="<?php echo esc_attr( $val ); ?>" /> |
|
761 | + <input type="hidden" name="<?php echo esc_attr($att); ?>" id="<?php echo esc_attr(str_replace('attribute_', '', $att)); ?>" value="<?php echo esc_attr($val); ?>" /> |
|
762 | 762 | |
763 | 763 | <?php } ?> |
764 | 764 | |
@@ -786,26 +786,26 @@ discard block |
||
786 | 786 | * |
787 | 787 | * @return string $message |
788 | 788 | */ |
789 | - public static function alter_no_permissions_message( $message, $post_id ){ |
|
789 | + public static function alter_no_permissions_message($message, $post_id) { |
|
790 | 790 | |
791 | - if( empty( $post_id ) || 'course'!=get_post_type( $post_id ) ){ |
|
791 | + if (empty($post_id) || 'course' != get_post_type($post_id)) { |
|
792 | 792 | return $message; |
793 | 793 | } |
794 | 794 | |
795 | - $product_id = self::get_course_product_id( $post_id ); |
|
795 | + $product_id = self::get_course_product_id($post_id); |
|
796 | 796 | |
797 | - if( ! $product_id |
|
798 | - || self::has_customer_bought_product( get_current_user_id(),$product_id ) ){ |
|
797 | + if ( ! $product_id |
|
798 | + || self::has_customer_bought_product(get_current_user_id(), $product_id)) { |
|
799 | 799 | |
800 | 800 | return $message; |
801 | 801 | |
802 | 802 | } |
803 | 803 | |
804 | 804 | ob_start(); |
805 | - self::the_course_no_permissions_message( $post_id ); |
|
805 | + self::the_course_no_permissions_message($post_id); |
|
806 | 806 | $woocommerce_course_no_permissions_message = ob_get_clean(); |
807 | 807 | |
808 | - return $woocommerce_course_no_permissions_message ; |
|
808 | + return $woocommerce_course_no_permissions_message; |
|
809 | 809 | |
810 | 810 | } |
811 | 811 | /** |
@@ -814,16 +814,16 @@ discard block |
||
814 | 814 | * |
815 | 815 | * @since 1.9.0 |
816 | 816 | */ |
817 | - public static function the_course_no_permissions_message( $course_id ){ |
|
817 | + public static function the_course_no_permissions_message($course_id) { |
|
818 | 818 | |
819 | 819 | // login link |
820 | - $my_courses_page_id = intval( Sensei()->settings->settings[ 'my_course_page' ] ); |
|
821 | - $login_link = '<a href="' . esc_url( get_permalink( $my_courses_page_id ) ) . '">' . __( 'log in', 'woothemes-sensei' ) . '</a>'; |
|
820 | + $my_courses_page_id = intval(Sensei()->settings->settings['my_course_page']); |
|
821 | + $login_link = '<a href="'.esc_url(get_permalink($my_courses_page_id)).'">'.__('log in', 'woothemes-sensei').'</a>'; |
|
822 | 822 | |
823 | 823 | ?> |
824 | 824 | |
825 | 825 | <span class="add-to-cart-login"> |
826 | - <?php echo sprintf( __( 'Or %1$s to access your purchased courses', 'woothemes-sensei' ), $login_link ); ?> |
|
826 | + <?php echo sprintf(__('Or %1$s to access your purchased courses', 'woothemes-sensei'), $login_link); ?> |
|
827 | 827 | </span> |
828 | 828 | |
829 | 829 | <?php } |
@@ -838,45 +838,45 @@ discard block |
||
838 | 838 | * |
839 | 839 | * @return bool |
840 | 840 | */ |
841 | - public static function has_customer_bought_product ( $user_id, $product_id ){ |
|
841 | + public static function has_customer_bought_product($user_id, $product_id) { |
|
842 | 842 | |
843 | - $orders = get_posts( array( |
|
843 | + $orders = get_posts(array( |
|
844 | 844 | 'numberposts' => -1, |
845 | 845 | 'post_type' => 'shope_order', |
846 | 846 | 'meta_key' => '_customer_user', |
847 | - 'meta_value' => intval( $user_id ), |
|
848 | - 'post_status' => array( 'wc-complete','wc-processing' ), |
|
849 | - ) ); |
|
847 | + 'meta_value' => intval($user_id), |
|
848 | + 'post_status' => array('wc-complete', 'wc-processing'), |
|
849 | + )); |
|
850 | 850 | |
851 | - foreach ( $orders as $order_id ) { |
|
851 | + foreach ($orders as $order_id) { |
|
852 | 852 | |
853 | - $order = new WC_Order( $order_id->ID ); |
|
853 | + $order = new WC_Order($order_id->ID); |
|
854 | 854 | |
855 | 855 | // wc-active is the subscriptions complete status |
856 | - if ( ! in_array( $order->post_status, array( 'wc-complete','wc-processing' ) ) ){ |
|
856 | + if ( ! in_array($order->post_status, array('wc-complete', 'wc-processing'))) { |
|
857 | 857 | |
858 | 858 | continue; |
859 | 859 | |
860 | 860 | } |
861 | 861 | |
862 | - if ( ! ( 0 < sizeof( $order->get_items() ) ) ) { |
|
862 | + if ( ! (0 < sizeof($order->get_items()))) { |
|
863 | 863 | |
864 | 864 | continue; |
865 | 865 | |
866 | 866 | } |
867 | 867 | |
868 | - foreach( $order->get_items() as $item ) { |
|
868 | + foreach ($order->get_items() as $item) { |
|
869 | 869 | |
870 | 870 | // Check if user has bought product |
871 | - if ( $item['product_id'] == $product_id || $item['variation_id'] == $product_id ) { |
|
871 | + if ($item['product_id'] == $product_id || $item['variation_id'] == $product_id) { |
|
872 | 872 | |
873 | 873 | // Check if user has an active subscription for product |
874 | - if( class_exists( 'WC_Subscriptions_Manager' ) ) { |
|
875 | - $sub_key = wcs_get_subscription( $order ); |
|
876 | - if( $sub_key ) { |
|
877 | - $sub = wcs_get_subscription( $sub_key ); |
|
878 | - if( $sub && isset( $sub['status'] ) ) { |
|
879 | - if( 'active' == $sub['status'] ) { |
|
874 | + if (class_exists('WC_Subscriptions_Manager')) { |
|
875 | + $sub_key = wcs_get_subscription($order); |
|
876 | + if ($sub_key) { |
|
877 | + $sub = wcs_get_subscription($sub_key); |
|
878 | + if ($sub && isset($sub['status'])) { |
|
879 | + if ('active' == $sub['status']) { |
|
880 | 880 | return true; |
881 | 881 | } else { |
882 | 882 | return false; |
@@ -905,11 +905,11 @@ discard block |
||
905 | 905 | * @return string $woocommerce_product_id or false if none exist |
906 | 906 | * |
907 | 907 | */ |
908 | - public static function get_course_product_id( $course_id ){ |
|
908 | + public static function get_course_product_id($course_id) { |
|
909 | 909 | |
910 | - $product_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
910 | + $product_id = get_post_meta($course_id, '_course_woocommerce_product', true); |
|
911 | 911 | |
912 | - if( empty( $product_id ) || 'product' != get_post_type( $product_id ) ){ |
|
912 | + if (empty($product_id) || 'product' != get_post_type($product_id)) { |
|
913 | 913 | return false; |
914 | 914 | } |
915 | 915 | |
@@ -923,11 +923,11 @@ discard block |
||
923 | 923 | * @param array $classes |
924 | 924 | * @return array |
925 | 925 | */ |
926 | - public static function add_woocommerce_body_class( $classes ){ |
|
926 | + public static function add_woocommerce_body_class($classes) { |
|
927 | 927 | |
928 | - if( ! in_array( 'woocommerce', $classes ) ){ |
|
928 | + if ( ! in_array('woocommerce', $classes)) { |
|
929 | 929 | |
930 | - $classes[] ='woocommerce'; |
|
930 | + $classes[] = 'woocommerce'; |
|
931 | 931 | |
932 | 932 | } |
933 | 933 | |
@@ -945,7 +945,7 @@ discard block |
||
945 | 945 | * |
946 | 946 | * @return void |
947 | 947 | */ |
948 | - public static function activate_subscription( $order ) { |
|
948 | + public static function activate_subscription($order) { |
|
949 | 949 | |
950 | 950 | $order_user = get_user_by('id', $order->user_id); |
951 | 951 | $user['ID'] = $order_user->ID; |
@@ -954,13 +954,13 @@ discard block |
||
954 | 954 | $user['user_url'] = $order_user->user_url; |
955 | 955 | |
956 | 956 | // Run through each product ordered |
957 | - if ( ! sizeof($order->get_items() )>0 ) { |
|
957 | + if ( ! sizeof($order->get_items()) > 0) { |
|
958 | 958 | |
959 | 959 | return; |
960 | 960 | |
961 | 961 | } |
962 | 962 | |
963 | - foreach($order->get_items() as $item) { |
|
963 | + foreach ($order->get_items() as $item) { |
|
964 | 964 | |
965 | 965 | $product_type = ''; |
966 | 966 | |
@@ -975,21 +975,21 @@ discard block |
||
975 | 975 | |
976 | 976 | } // End If Statement |
977 | 977 | |
978 | - $_product = self::get_product_object( $item_id, $product_type ); |
|
978 | + $_product = self::get_product_object($item_id, $product_type); |
|
979 | 979 | |
980 | 980 | // Get courses that use the WC product |
981 | 981 | $courses = array(); |
982 | 982 | |
983 | - if ( ! in_array( $product_type, self::get_subscription_types() ) ) { |
|
983 | + if ( ! in_array($product_type, self::get_subscription_types())) { |
|
984 | 984 | |
985 | - $courses = Sensei()->course->get_product_courses( $item_id ); |
|
985 | + $courses = Sensei()->course->get_product_courses($item_id); |
|
986 | 986 | |
987 | 987 | } // End If Statement |
988 | 988 | |
989 | 989 | // Loop and add the user to the course. |
990 | - foreach ( $courses as $course_item ){ |
|
990 | + foreach ($courses as $course_item) { |
|
991 | 991 | |
992 | - Sensei_Utils::user_start_course( intval( $user['ID'] ), $course_item->ID ); |
|
992 | + Sensei_Utils::user_start_course(intval($user['ID']), $course_item->ID); |
|
993 | 993 | |
994 | 994 | } // End For Loop |
995 | 995 | |
@@ -1007,13 +1007,13 @@ discard block |
||
1007 | 1007 | * |
1008 | 1008 | * @return void |
1009 | 1009 | */ |
1010 | - public static function email_course_details( $order ){ |
|
1010 | + public static function email_course_details($order) { |
|
1011 | 1011 | |
1012 | 1012 | global $woocommerce; |
1013 | 1013 | |
1014 | 1014 | // exit early if not wc-completed or wc-processing |
1015 | - if( 'wc-completed' != $order->post_status |
|
1016 | - && 'wc-processing' != $order->post_status ) { |
|
1015 | + if ('wc-completed' != $order->post_status |
|
1016 | + && 'wc-processing' != $order->post_status) { |
|
1017 | 1017 | return; |
1018 | 1018 | } |
1019 | 1019 | |
@@ -1021,16 +1021,16 @@ discard block |
||
1021 | 1021 | $order_id = $order->id; |
1022 | 1022 | |
1023 | 1023 | //If object have items go through them all to find course |
1024 | - if ( 0 < sizeof( $order_items ) ) { |
|
1024 | + if (0 < sizeof($order_items)) { |
|
1025 | 1025 | |
1026 | - $course_details_html = '<h2>' . __( 'Course details', 'woothemes-sensei' ) . '</h2>'; |
|
1026 | + $course_details_html = '<h2>'.__('Course details', 'woothemes-sensei').'</h2>'; |
|
1027 | 1027 | $order_contains_courses = false; |
1028 | 1028 | |
1029 | 1029 | |
1030 | - foreach ( $order_items as $item ) { |
|
1030 | + foreach ($order_items as $item) { |
|
1031 | 1031 | |
1032 | 1032 | $product_type = ''; |
1033 | - if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
1033 | + if (isset($item['variation_id']) && (0 < $item['variation_id'])) { |
|
1034 | 1034 | // If item has variation_id then its from variation |
1035 | 1035 | $item_id = $item['variation_id']; |
1036 | 1036 | $product_type = 'variation'; |
@@ -1039,9 +1039,9 @@ discard block |
||
1039 | 1039 | $item_id = $item['product_id']; |
1040 | 1040 | } // End If Statement |
1041 | 1041 | |
1042 | - $user_id = get_post_meta( $order_id, '_customer_user', true ); |
|
1042 | + $user_id = get_post_meta($order_id, '_customer_user', true); |
|
1043 | 1043 | |
1044 | - if( $user_id ) { |
|
1044 | + if ($user_id) { |
|
1045 | 1045 | |
1046 | 1046 | // Get all courses for product |
1047 | 1047 | $args = array( |
@@ -1056,16 +1056,16 @@ discard block |
||
1056 | 1056 | 'orderby' => 'menu_order date', |
1057 | 1057 | 'order' => 'ASC', |
1058 | 1058 | ); |
1059 | - $courses = get_posts( $args ); |
|
1059 | + $courses = get_posts($args); |
|
1060 | 1060 | |
1061 | - if( $courses && count( $courses ) > 0 ) { |
|
1061 | + if ($courses && count($courses) > 0) { |
|
1062 | 1062 | |
1063 | - foreach( $courses as $course ) { |
|
1063 | + foreach ($courses as $course) { |
|
1064 | 1064 | |
1065 | 1065 | $title = $course->post_title; |
1066 | - $permalink = get_permalink( $course->ID ); |
|
1066 | + $permalink = get_permalink($course->ID); |
|
1067 | 1067 | $order_contains_courses = true; |
1068 | - $course_details_html .= '<p><strong>' . sprintf( __( 'View course: %1$s', 'woothemes-sensei' ), '</strong><a href="' . esc_url( $permalink ) . '">' . $title . '</a>' ) . '</p>'; |
|
1068 | + $course_details_html .= '<p><strong>'.sprintf(__('View course: %1$s', 'woothemes-sensei'), '</strong><a href="'.esc_url($permalink).'">'.$title.'</a>').'</p>'; |
|
1069 | 1069 | } |
1070 | 1070 | |
1071 | 1071 | |
@@ -1076,7 +1076,7 @@ discard block |
||
1076 | 1076 | } // end for each order item |
1077 | 1077 | |
1078 | 1078 | // Output Course details |
1079 | - if( $order_contains_courses ){ |
|
1079 | + if ($order_contains_courses) { |
|
1080 | 1080 | |
1081 | 1081 | echo $course_details_html; |
1082 | 1082 | |
@@ -1094,26 +1094,26 @@ discard block |
||
1094 | 1094 | * @param int $order_id WC order ID |
1095 | 1095 | * @return void |
1096 | 1096 | */ |
1097 | - public static function complete_order ( $order_id = 0 ) { |
|
1097 | + public static function complete_order($order_id = 0) { |
|
1098 | 1098 | |
1099 | 1099 | $order_user = array(); |
1100 | 1100 | |
1101 | 1101 | // Check for WooCommerce |
1102 | - if ( Sensei_WC::is_woocommerce_active() && ( 0 < $order_id ) ) { |
|
1102 | + if (Sensei_WC::is_woocommerce_active() && (0 < $order_id)) { |
|
1103 | 1103 | // Get order object |
1104 | - $order = new WC_Order( $order_id ); |
|
1105 | - $user = get_user_by( 'id', $order->get_user_id() ); |
|
1104 | + $order = new WC_Order($order_id); |
|
1105 | + $user = get_user_by('id', $order->get_user_id()); |
|
1106 | 1106 | $order_user['ID'] = $user->ID; |
1107 | 1107 | $order_user['user_login'] = $user->user_login; |
1108 | 1108 | $order_user['user_email'] = $user->user_email; |
1109 | 1109 | $order_user['user_url'] = $user->user_url; |
1110 | 1110 | // Run through each product ordered |
1111 | - if ( 0 < sizeof( $order->get_items() ) ) { |
|
1111 | + if (0 < sizeof($order->get_items())) { |
|
1112 | 1112 | |
1113 | - foreach( $order->get_items() as $item ) { |
|
1113 | + foreach ($order->get_items() as $item) { |
|
1114 | 1114 | |
1115 | 1115 | $product_type = ''; |
1116 | - if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
1116 | + if (isset($item['variation_id']) && (0 < $item['variation_id'])) { |
|
1117 | 1117 | |
1118 | 1118 | $item_id = $item['variation_id']; |
1119 | 1119 | $product_type = 'variation'; |
@@ -1124,15 +1124,15 @@ discard block |
||
1124 | 1124 | |
1125 | 1125 | } // End If Statement |
1126 | 1126 | |
1127 | - $_product = Sensei_WC::get_product_object( $item_id, $product_type ); |
|
1127 | + $_product = Sensei_WC::get_product_object($item_id, $product_type); |
|
1128 | 1128 | |
1129 | 1129 | // Get courses that use the WC product |
1130 | - $courses = Sensei()->course->get_product_courses( $_product->id ); |
|
1130 | + $courses = Sensei()->course->get_product_courses($_product->id); |
|
1131 | 1131 | |
1132 | 1132 | // Loop and update those courses |
1133 | - foreach ( $courses as $course_item ) { |
|
1133 | + foreach ($courses as $course_item) { |
|
1134 | 1134 | |
1135 | - $update_course = Sensei()->woocommerce_course_update( $course_item->ID, $order_user ); |
|
1135 | + $update_course = Sensei()->woocommerce_course_update($course_item->ID, $order_user); |
|
1136 | 1136 | |
1137 | 1137 | } // End For Loop |
1138 | 1138 | |
@@ -1140,7 +1140,7 @@ discard block |
||
1140 | 1140 | |
1141 | 1141 | } // End If Statement |
1142 | 1142 | // Add meta to indicate that payment has been completed successfully |
1143 | - update_post_meta( $order_id, 'sensei_payment_complete', '1' ); |
|
1143 | + update_post_meta($order_id, 'sensei_payment_complete', '1'); |
|
1144 | 1144 | |
1145 | 1145 | } // End If Statement |
1146 | 1146 | |
@@ -1154,28 +1154,28 @@ discard block |
||
1154 | 1154 | * @param integer| WC_Order $order_id order ID |
1155 | 1155 | * @return void |
1156 | 1156 | */ |
1157 | - public static function cancel_order ( $order_id ) { |
|
1157 | + public static function cancel_order($order_id) { |
|
1158 | 1158 | |
1159 | 1159 | // Get order object |
1160 | - if( is_object( $order_id ) ){ |
|
1160 | + if (is_object($order_id)) { |
|
1161 | 1161 | |
1162 | 1162 | $order = $order_id; |
1163 | 1163 | |
1164 | - }else{ |
|
1164 | + } else { |
|
1165 | 1165 | |
1166 | - $order = new WC_Order( $order_id ); |
|
1166 | + $order = new WC_Order($order_id); |
|
1167 | 1167 | } |
1168 | 1168 | |
1169 | 1169 | // Run through each product ordered |
1170 | - if ( 0 < sizeof( $order->get_items() ) ) { |
|
1170 | + if (0 < sizeof($order->get_items())) { |
|
1171 | 1171 | |
1172 | 1172 | // Get order user |
1173 | - $user_id = $order->__get( 'user_id' ); |
|
1173 | + $user_id = $order->__get('user_id'); |
|
1174 | 1174 | |
1175 | - foreach( $order->get_items() as $item ) { |
|
1175 | + foreach ($order->get_items() as $item) { |
|
1176 | 1176 | |
1177 | 1177 | $product_type = ''; |
1178 | - if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
1178 | + if (isset($item['variation_id']) && (0 < $item['variation_id'])) { |
|
1179 | 1179 | |
1180 | 1180 | $item_id = $item['variation_id']; |
1181 | 1181 | $product_type = 'variation'; |
@@ -1186,17 +1186,17 @@ discard block |
||
1186 | 1186 | |
1187 | 1187 | } // End If Statement |
1188 | 1188 | |
1189 | - $_product = Sensei_WC::get_product_object( $item_id, $product_type ); |
|
1189 | + $_product = Sensei_WC::get_product_object($item_id, $product_type); |
|
1190 | 1190 | |
1191 | 1191 | // Get courses that use the WC product |
1192 | 1192 | $courses = array(); |
1193 | - $courses = Sensei()->course->get_product_courses( $item_id ); |
|
1193 | + $courses = Sensei()->course->get_product_courses($item_id); |
|
1194 | 1194 | |
1195 | 1195 | // Loop and update those courses |
1196 | - foreach ($courses as $course_item){ |
|
1196 | + foreach ($courses as $course_item) { |
|
1197 | 1197 | |
1198 | 1198 | // Check and Remove course from courses user meta |
1199 | - $dataset_changes = Sensei_Utils::sensei_remove_user_from_course( $course_item->ID, $user_id ); |
|
1199 | + $dataset_changes = Sensei_Utils::sensei_remove_user_from_course($course_item->ID, $user_id); |
|
1200 | 1200 | |
1201 | 1201 | } // End For Loop |
1202 | 1202 | |
@@ -1217,30 +1217,30 @@ discard block |
||
1217 | 1217 | * @param string $product_type '' or 'variation' |
1218 | 1218 | * @return WC_Product $wc_product_object |
1219 | 1219 | */ |
1220 | - public static function get_product_object ( $wc_product_id = 0, $product_type = '' ) { |
|
1220 | + public static function get_product_object($wc_product_id = 0, $product_type = '') { |
|
1221 | 1221 | |
1222 | 1222 | $wc_product_object = false; |
1223 | - if ( 0 < intval( $wc_product_id ) ) { |
|
1223 | + if (0 < intval($wc_product_id)) { |
|
1224 | 1224 | |
1225 | 1225 | // Get the product |
1226 | - if ( function_exists( 'wc_get_product' ) ) { |
|
1226 | + if (function_exists('wc_get_product')) { |
|
1227 | 1227 | |
1228 | - $wc_product_object = wc_get_product( $wc_product_id ); // Post WC 2.3 |
|
1228 | + $wc_product_object = wc_get_product($wc_product_id); // Post WC 2.3 |
|
1229 | 1229 | |
1230 | - } elseif ( function_exists( 'get_product' ) ) { |
|
1230 | + } elseif (function_exists('get_product')) { |
|
1231 | 1231 | |
1232 | - $wc_product_object = get_product( $wc_product_id ); // Post WC 2.0 |
|
1232 | + $wc_product_object = get_product($wc_product_id); // Post WC 2.0 |
|
1233 | 1233 | |
1234 | 1234 | } else { |
1235 | 1235 | |
1236 | 1236 | // Pre WC 2.0 |
1237 | - if ( 'variation' == $product_type || 'subscription_variation' == $product_type ) { |
|
1237 | + if ('variation' == $product_type || 'subscription_variation' == $product_type) { |
|
1238 | 1238 | |
1239 | - $wc_product_object = new WC_Product_Variation( $wc_product_id ); |
|
1239 | + $wc_product_object = new WC_Product_Variation($wc_product_id); |
|
1240 | 1240 | |
1241 | 1241 | } else { |
1242 | 1242 | |
1243 | - $wc_product_object = new WC_Product( $wc_product_id ); |
|
1243 | + $wc_product_object = new WC_Product($wc_product_id); |
|
1244 | 1244 | |
1245 | 1245 | } // End If Statement |
1246 | 1246 | |
@@ -1263,19 +1263,19 @@ discard block |
||
1263 | 1263 | * |
1264 | 1264 | * @return bool|int |
1265 | 1265 | */ |
1266 | - public static function course_update ( $course_id = 0, $order_user = array() ) { |
|
1266 | + public static function course_update($course_id = 0, $order_user = array()) { |
|
1267 | 1267 | |
1268 | 1268 | global $current_user; |
1269 | 1269 | |
1270 | - if ( ! isset( $current_user ) || !$current_user->ID > 0 ) return false; |
|
1270 | + if ( ! isset($current_user) || ! $current_user->ID > 0) return false; |
|
1271 | 1271 | |
1272 | 1272 | $data_update = false; |
1273 | 1273 | |
1274 | 1274 | // Get the product ID |
1275 | - $wc_post_id = get_post_meta( intval( $course_id ), '_course_woocommerce_product', true ); |
|
1275 | + $wc_post_id = get_post_meta(intval($course_id), '_course_woocommerce_product', true); |
|
1276 | 1276 | |
1277 | 1277 | // Check if in the admin |
1278 | - if ( is_admin() ) { |
|
1278 | + if (is_admin()) { |
|
1279 | 1279 | |
1280 | 1280 | $user_login = $order_user['user_login']; |
1281 | 1281 | $user_email = $order_user['user_email']; |
@@ -1292,28 +1292,28 @@ discard block |
||
1292 | 1292 | } // End If Statement |
1293 | 1293 | |
1294 | 1294 | // This doesn't appear to be purely WooCommerce related. Should it be in a separate function? |
1295 | - $course_prerequisite_id = (int) get_post_meta( $course_id, '_course_prerequisite', true ); |
|
1296 | - if( 0 < absint( $course_prerequisite_id ) ) { |
|
1295 | + $course_prerequisite_id = (int) get_post_meta($course_id, '_course_prerequisite', true); |
|
1296 | + if (0 < absint($course_prerequisite_id)) { |
|
1297 | 1297 | |
1298 | - $prereq_course_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, intval( $user_id ) ); |
|
1299 | - if ( ! $prereq_course_complete ) { |
|
1298 | + $prereq_course_complete = Sensei_Utils::user_completed_course($course_prerequisite_id, intval($user_id)); |
|
1299 | + if ( ! $prereq_course_complete) { |
|
1300 | 1300 | |
1301 | 1301 | // Remove all course user meta |
1302 | - return Sensei_Utils::sensei_remove_user_from_course( $course_id, $user_id ); |
|
1302 | + return Sensei_Utils::sensei_remove_user_from_course($course_id, $user_id); |
|
1303 | 1303 | |
1304 | 1304 | } |
1305 | 1305 | } |
1306 | 1306 | |
1307 | - $is_user_taking_course = Sensei_Utils::user_started_course( intval( $course_id ), intval( $user_id ) ); |
|
1307 | + $is_user_taking_course = Sensei_Utils::user_started_course(intval($course_id), intval($user_id)); |
|
1308 | 1308 | |
1309 | - if( ! $is_user_taking_course ) { |
|
1309 | + if ( ! $is_user_taking_course) { |
|
1310 | 1310 | |
1311 | - if ( Sensei_WC::is_woocommerce_active() && Sensei_WC::has_customer_bought_product( $user_id, $wc_post_id ) && ( 0 < $wc_post_id ) ) { |
|
1311 | + if (Sensei_WC::is_woocommerce_active() && Sensei_WC::has_customer_bought_product($user_id, $wc_post_id) && (0 < $wc_post_id)) { |
|
1312 | 1312 | |
1313 | - $activity_logged = Sensei_Utils::user_start_course( intval( $user_id), intval( $course_id ) ); |
|
1313 | + $activity_logged = Sensei_Utils::user_start_course(intval($user_id), intval($course_id)); |
|
1314 | 1314 | |
1315 | 1315 | $is_user_taking_course = false; |
1316 | - if ( true == $activity_logged ) { |
|
1316 | + if (true == $activity_logged) { |
|
1317 | 1317 | |
1318 | 1318 | $is_user_taking_course = true; |
1319 | 1319 | |
@@ -1336,14 +1336,14 @@ discard block |
||
1336 | 1336 | * |
1337 | 1337 | * @return boolean Modified guest checkout setting |
1338 | 1338 | */ |
1339 | - public static function disable_guest_checkout( $guest_checkout ) { |
|
1339 | + public static function disable_guest_checkout($guest_checkout) { |
|
1340 | 1340 | |
1341 | - if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { |
|
1341 | + if ( ! is_admin() || (defined('DOING_AJAX') && DOING_AJAX)) { |
|
1342 | 1342 | |
1343 | - if( isset( WC()->cart->cart_contents ) && count( WC()->cart->cart_contents ) > 0 ) { |
|
1343 | + if (isset(WC()->cart->cart_contents) && count(WC()->cart->cart_contents) > 0) { |
|
1344 | 1344 | |
1345 | - foreach( WC()->cart->cart_contents as $cart_key => $product ) { |
|
1346 | - if( isset( $product['product_id'] ) ) { |
|
1345 | + foreach (WC()->cart->cart_contents as $cart_key => $product) { |
|
1346 | + if (isset($product['product_id'])) { |
|
1347 | 1347 | |
1348 | 1348 | $args = array( |
1349 | 1349 | 'posts_per_page' => -1, |
@@ -1356,11 +1356,11 @@ discard block |
||
1356 | 1356 | ) |
1357 | 1357 | ); |
1358 | 1358 | |
1359 | - $posts = get_posts( $args ); |
|
1359 | + $posts = get_posts($args); |
|
1360 | 1360 | |
1361 | - if( $posts && count( $posts ) > 0 ) { |
|
1361 | + if ($posts && count($posts) > 0) { |
|
1362 | 1362 | |
1363 | - foreach( $posts as $course ) { |
|
1363 | + foreach ($posts as $course) { |
|
1364 | 1364 | $guest_checkout = ''; |
1365 | 1365 | break; |
1366 | 1366 | |
@@ -1389,23 +1389,23 @@ discard block |
||
1389 | 1389 | * |
1390 | 1390 | * @return string |
1391 | 1391 | **/ |
1392 | - public static function virtual_order_payment_complete( $order_status, $order_id ) { |
|
1392 | + public static function virtual_order_payment_complete($order_status, $order_id) { |
|
1393 | 1393 | |
1394 | - $order = new WC_Order( $order_id ); |
|
1394 | + $order = new WC_Order($order_id); |
|
1395 | 1395 | |
1396 | - if ( ! isset ( $order ) ) return ''; |
|
1396 | + if ( ! isset ($order)) return ''; |
|
1397 | 1397 | |
1398 | - if ( $order_status == 'wc-processing' && ( $order->post_status == 'wc-on-hold' || $order->post_status == 'wc-pending' || $order->post_status == 'wc-failed' ) ) { |
|
1398 | + if ($order_status == 'wc-processing' && ($order->post_status == 'wc-on-hold' || $order->post_status == 'wc-pending' || $order->post_status == 'wc-failed')) { |
|
1399 | 1399 | |
1400 | 1400 | $virtual_order = true; |
1401 | 1401 | |
1402 | - if ( count( $order->get_items() ) > 0 ) { |
|
1402 | + if (count($order->get_items()) > 0) { |
|
1403 | 1403 | |
1404 | - foreach( $order->get_items() as $item ) { |
|
1404 | + foreach ($order->get_items() as $item) { |
|
1405 | 1405 | |
1406 | - if ( $item['product_id'] > 0 ) { |
|
1407 | - $_product = $order->get_product_from_item( $item ); |
|
1408 | - if ( ! $_product->is_virtual() ) { |
|
1406 | + if ($item['product_id'] > 0) { |
|
1407 | + $_product = $order->get_product_from_item($item); |
|
1408 | + if ( ! $_product->is_virtual()) { |
|
1409 | 1409 | |
1410 | 1410 | $virtual_order = false; |
1411 | 1411 | break; |
@@ -1419,7 +1419,7 @@ discard block |
||
1419 | 1419 | } // End If Statement |
1420 | 1420 | |
1421 | 1421 | // virtual order, mark as completed |
1422 | - if ( $virtual_order ) { |
|
1422 | + if ($virtual_order) { |
|
1423 | 1423 | |
1424 | 1424 | return 'completed'; |
1425 | 1425 | |
@@ -1442,14 +1442,14 @@ discard block |
||
1442 | 1442 | * @param integer $user_id |
1443 | 1443 | * @return boolean $user_access_permission |
1444 | 1444 | */ |
1445 | - public static function get_subscription_permission( $user_access_permission, $user_id ){ |
|
1445 | + public static function get_subscription_permission($user_access_permission, $user_id) { |
|
1446 | 1446 | |
1447 | 1447 | global $post; |
1448 | 1448 | |
1449 | 1449 | // ignore the current case if the following conditions are met |
1450 | - if ( ! class_exists( 'WC_Subscriptions' ) || empty( $user_id ) |
|
1451 | - || ! in_array( $post->post_type, array( 'course','lesson','quiz' ) ) |
|
1452 | - || ! wcs_user_has_subscription( $user_id) ){ |
|
1450 | + if ( ! class_exists('WC_Subscriptions') || empty($user_id) |
|
1451 | + || ! in_array($post->post_type, array('course', 'lesson', 'quiz')) |
|
1452 | + || ! wcs_user_has_subscription($user_id)) { |
|
1453 | 1453 | |
1454 | 1454 | return $user_access_permission; |
1455 | 1455 | |
@@ -1459,25 +1459,25 @@ discard block |
||
1459 | 1459 | // is the subscription on the the current course? |
1460 | 1460 | |
1461 | 1461 | $course_id = 0; |
1462 | - if ( 'course' == $post->post_type ){ |
|
1462 | + if ('course' == $post->post_type) { |
|
1463 | 1463 | |
1464 | 1464 | $course_id = $post->ID; |
1465 | 1465 | |
1466 | - } elseif ( 'lesson' == $post->post_type ) { |
|
1466 | + } elseif ('lesson' == $post->post_type) { |
|
1467 | 1467 | |
1468 | - $course_id = Sensei()->lesson->get_course_id( $post->ID ); |
|
1468 | + $course_id = Sensei()->lesson->get_course_id($post->ID); |
|
1469 | 1469 | |
1470 | 1470 | } else { |
1471 | 1471 | |
1472 | - $lesson_id = Sensei()->quiz->get_lesson_id( $post->ID ); |
|
1473 | - $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
1472 | + $lesson_id = Sensei()->quiz->get_lesson_id($post->ID); |
|
1473 | + $course_id = Sensei()->lesson->get_course_id($lesson_id); |
|
1474 | 1474 | |
1475 | 1475 | } |
1476 | 1476 | |
1477 | 1477 | // if the course has no subscription WooCommerce product attached to return the permissions as is |
1478 | - $product_id = Sensei_WC::get_course_product_id( $course_id ); |
|
1479 | - $product = wc_get_product( $product_id ); |
|
1480 | - if( ! in_array( $product->get_type(), self::get_subscription_types() ) ){ |
|
1478 | + $product_id = Sensei_WC::get_course_product_id($course_id); |
|
1479 | + $product = wc_get_product($product_id); |
|
1480 | + if ( ! in_array($product->get_type(), self::get_subscription_types())) { |
|
1481 | 1481 | |
1482 | 1482 | return $user_access_permission; |
1483 | 1483 | |
@@ -1485,19 +1485,19 @@ discard block |
||
1485 | 1485 | |
1486 | 1486 | // give access if user has active subscription on the product otherwise restrict it. |
1487 | 1487 | // also check if the user was added to the course directly after the subscription started. |
1488 | - if( wcs_user_has_subscription( $user_id, $product_id, 'active' ) |
|
1489 | - || wcs_user_has_subscription( $user_id, $product_id, 'pending-cancel' ) |
|
1490 | - || self::was_user_added_without_subscription( $user_id, $product_id, $course_id ) ){ |
|
1488 | + if (wcs_user_has_subscription($user_id, $product_id, 'active') |
|
1489 | + || wcs_user_has_subscription($user_id, $product_id, 'pending-cancel') |
|
1490 | + || self::was_user_added_without_subscription($user_id, $product_id, $course_id)) { |
|
1491 | 1491 | |
1492 | 1492 | $user_access_permission = true; |
1493 | 1493 | |
1494 | - }else{ |
|
1494 | + } else { |
|
1495 | 1495 | |
1496 | 1496 | $user_access_permission = false; |
1497 | 1497 | // do not show the WC permissions message |
1498 | - remove_filter( 'sensei_the_no_permissions_message', array( 'Sensei_WC', 'alter_no_permissions_message' ), 20, 2 ); |
|
1499 | - Sensei()->permissions_message['title'] = __( 'No active subscription', 'woothemes-sensei' ); |
|
1500 | - Sensei()->permissions_message['message'] = __( 'Sorry, you do not have an access to this content without an active subscription.', 'woothemes-sensei' ); |
|
1498 | + remove_filter('sensei_the_no_permissions_message', array('Sensei_WC', 'alter_no_permissions_message'), 20, 2); |
|
1499 | + Sensei()->permissions_message['title'] = __('No active subscription', 'woothemes-sensei'); |
|
1500 | + Sensei()->permissions_message['message'] = __('Sorry, you do not have an access to this content without an active subscription.', 'woothemes-sensei'); |
|
1501 | 1501 | } |
1502 | 1502 | |
1503 | 1503 | return $user_access_permission; |
@@ -1510,9 +1510,9 @@ discard block |
||
1510 | 1510 | * @since 1.9.0 |
1511 | 1511 | * @return array |
1512 | 1512 | */ |
1513 | - public static function get_subscription_types(){ |
|
1513 | + public static function get_subscription_types() { |
|
1514 | 1514 | |
1515 | - return array( 'subscription','subscription_variation','variable-subscription' ); |
|
1515 | + return array('subscription', 'subscription_variation', 'variable-subscription'); |
|
1516 | 1516 | |
1517 | 1517 | } |
1518 | 1518 | |
@@ -1532,15 +1532,15 @@ discard block |
||
1532 | 1532 | * |
1533 | 1533 | * @return bool |
1534 | 1534 | */ |
1535 | - public static function was_user_added_without_subscription($user_id, $product_id, $course_id ){ |
|
1535 | + public static function was_user_added_without_subscription($user_id, $product_id, $course_id) { |
|
1536 | 1536 | |
1537 | 1537 | $course_start_date = ''; |
1538 | 1538 | $subscription_start_date = ''; |
1539 | - $is_a_subscription =''; |
|
1539 | + $is_a_subscription = ''; |
|
1540 | 1540 | $was_user_added_without_subscription = true; |
1541 | 1541 | |
1542 | 1542 | // if user is not on the course they were not added |
1543 | - if( ! Sensei_Utils::user_started_course( $course_id, $user_id ) ){ |
|
1543 | + if ( ! Sensei_Utils::user_started_course($course_id, $user_id)) { |
|
1544 | 1544 | |
1545 | 1545 | return false; |
1546 | 1546 | |
@@ -1549,34 +1549,34 @@ discard block |
||
1549 | 1549 | // if user doesn't have a subscription and is taking the course |
1550 | 1550 | // they were added manually |
1551 | 1551 | if ( ! wcs_user_has_subscription($user_id, $product_id) |
1552 | - && Sensei_Utils::user_started_course( $course_id, get_current_user_id() ) ){ |
|
1552 | + && Sensei_Utils::user_started_course($course_id, get_current_user_id())) { |
|
1553 | 1553 | |
1554 | 1554 | return true; |
1555 | 1555 | |
1556 | 1556 | } |
1557 | 1557 | |
1558 | - $course_status = Sensei_Utils::user_course_status( $course_id, $user_id ); |
|
1558 | + $course_status = Sensei_Utils::user_course_status($course_id, $user_id); |
|
1559 | 1559 | |
1560 | 1560 | // comparing dates setup data |
1561 | - $course_start_date = date_create( $course_status->comment_date ); |
|
1562 | - $subscriptions = wcs_get_users_subscriptions( $user_id ); |
|
1561 | + $course_start_date = date_create($course_status->comment_date); |
|
1562 | + $subscriptions = wcs_get_users_subscriptions($user_id); |
|
1563 | 1563 | |
1564 | 1564 | // comparing every subscription |
1565 | - foreach( $subscriptions as $subscription ){ |
|
1565 | + foreach ($subscriptions as $subscription) { |
|
1566 | 1566 | |
1567 | 1567 | // for the following statuses we know the user was not added |
1568 | 1568 | // manually |
1569 | 1569 | $status = $subscription->get_status(); |
1570 | - if ( in_array( $status, array( 'pending-canceled', 'active', 'on-hold', 'pending' ) ) ) { |
|
1570 | + if (in_array($status, array('pending-canceled', 'active', 'on-hold', 'pending'))) { |
|
1571 | 1571 | |
1572 | 1572 | continue; |
1573 | 1573 | |
1574 | 1574 | } |
1575 | 1575 | |
1576 | - $current_subscription_start_date = date_create( $subscription->modified_date ); |
|
1576 | + $current_subscription_start_date = date_create($subscription->modified_date); |
|
1577 | 1577 | |
1578 | 1578 | // is the last updated subscription date newer than course start date |
1579 | - if ( $current_subscription_start_date > $course_start_date ) { |
|
1579 | + if ($current_subscription_start_date > $course_start_date) { |
|
1580 | 1580 | |
1581 | 1581 | return false; |
1582 | 1582 |
@@ -7,20 +7,20 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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); |