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