|
1
|
|
|
<?php |
|
2
|
|
|
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* Responsible for loading Sensei and setting up the Main WordPress hooks. |
|
6
|
|
|
* |
|
7
|
|
|
* @package Core |
|
8
|
|
|
* @author Automattic |
|
9
|
|
|
* @since 1.0.0 |
|
10
|
|
|
*/ |
|
11
|
|
|
class Sensei_Main { |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @var string |
|
15
|
|
|
* Reference to the main plugin file |
|
16
|
|
|
*/ |
|
17
|
|
|
private $file; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var Sensei_Main $_instance to the the main and only instance of the Sensei class. |
|
21
|
|
|
* @since 1.8.0 |
|
22
|
|
|
*/ |
|
23
|
|
|
protected static $_instance = null; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Main reference to the plugins current version |
|
27
|
|
|
*/ |
|
28
|
|
|
public $version; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Public token, referencing for the text domain. |
|
32
|
|
|
*/ |
|
33
|
|
|
public $token = 'woothemes-sensei'; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Plugin url and path for use when access resources. |
|
37
|
|
|
*/ |
|
38
|
|
|
public $plugin_url; |
|
39
|
|
|
public $plugin_path; |
|
40
|
|
|
public $template_url; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @var Sensei_PostTypes |
|
44
|
|
|
* All Sensei sub classes. Currently used to access functionality contained within |
|
45
|
|
|
* within Sensei sub classes e.g. Sensei()->course->all_courses() |
|
46
|
|
|
*/ |
|
47
|
|
|
public $post_types; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @var WooThemes_Sensei_Settings |
|
51
|
|
|
*/ |
|
52
|
|
|
public $settings; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @var WooThemes_Sensei_Course_Results |
|
56
|
|
|
*/ |
|
57
|
|
|
public $course_results; |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @var Sensei_Updates |
|
61
|
|
|
*/ |
|
62
|
|
|
public $updates; |
|
63
|
|
|
/** |
|
64
|
|
|
* @var WooThemes_Sensei_Course |
|
65
|
|
|
*/ |
|
66
|
|
|
public $course; |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @var WooThemes_Sensei_Lesson |
|
70
|
|
|
*/ |
|
71
|
|
|
public $lesson; |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @var WooThemes_Sensei_Quiz |
|
75
|
|
|
*/ |
|
76
|
|
|
public $quiz; |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @var WooThemes_Sensei_Question |
|
80
|
|
|
*/ |
|
81
|
|
|
public $question; |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @var WooThemes_Sensei_Admin |
|
85
|
|
|
*/ |
|
86
|
|
|
public $admin; |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @var WooThemes_Sensei_Frontend |
|
90
|
|
|
*/ |
|
91
|
|
|
public $frontend; |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @var Sensei_Notices |
|
95
|
|
|
*/ |
|
96
|
|
|
public $notices; |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* @var WooThemes_Sensei_Grading |
|
100
|
|
|
*/ |
|
101
|
|
|
public $grading; |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @var WooThemes_Sensei_Emails |
|
105
|
|
|
*/ |
|
106
|
|
|
public $emails; |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @var WooThemes_Sensei_Learner_Profiles |
|
110
|
|
|
*/ |
|
111
|
|
|
public $learner_profiles; |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* @var Sensei_Teacher |
|
115
|
|
|
*/ |
|
116
|
|
|
public $teacher; |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* @var WooThemes_Sensei_Learners |
|
120
|
|
|
*/ |
|
121
|
|
|
public $learners; |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* @var array |
|
125
|
|
|
* Global instance for access to the permissions message shown |
|
126
|
|
|
* when users do not have the right privileges to access resources. |
|
127
|
|
|
*/ |
|
128
|
|
|
public $permissions_message; |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* @var Sensei_Core_Modules Sensei Modules functionality |
|
132
|
|
|
*/ |
|
133
|
|
|
public $modules; |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* @var Sensei_Analysis |
|
137
|
|
|
*/ |
|
138
|
|
|
public $analysis; |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* Constructor method. |
|
142
|
|
|
* @param string $file The base file of the plugin. |
|
143
|
|
|
* @since 1.0.0 |
|
144
|
|
|
*/ |
|
145
|
|
|
public function __construct ( $file ) { |
|
146
|
|
|
|
|
147
|
|
|
// Setup object data |
|
148
|
|
|
$this->file = $file; |
|
149
|
|
|
$this->plugin_url = trailingslashit( plugins_url( '', $plugin = $file ) ); |
|
150
|
|
|
$this->plugin_path = trailingslashit( dirname( $file ) ); |
|
151
|
|
|
$this->template_url = apply_filters( 'sensei_template_url', 'sensei/' ); |
|
152
|
|
|
$this->permissions_message = array( 'title' => __( 'Permission Denied', 'woothemes-sensei' ), 'message' => __( 'Unfortunately you do not have permissions to access this page.', 'woothemes-sensei' ) ); |
|
153
|
|
|
|
|
154
|
|
|
// Initialize the core Sensei functionality |
|
155
|
|
|
$this->init(); |
|
156
|
|
|
|
|
157
|
|
|
// Installation |
|
158
|
|
|
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) $this->install(); |
|
159
|
|
|
|
|
160
|
|
|
// Run this on activation. |
|
161
|
|
|
register_activation_hook( $this->file, array( $this, 'activation' ) ); |
|
162
|
|
|
|
|
163
|
|
|
// Image Sizes |
|
164
|
|
|
$this->init_image_sizes(); |
|
165
|
|
|
|
|
166
|
|
|
// load all hooks |
|
167
|
|
|
$this->load_hooks(); |
|
168
|
|
|
|
|
169
|
|
|
} // End __construct() |
|
170
|
|
|
|
|
171
|
|
|
/** |
|
172
|
|
|
* Load the foundations of Sensei. |
|
173
|
|
|
* @since 1.9.0 |
|
174
|
|
|
*/ |
|
175
|
|
|
protected function init(){ |
|
176
|
|
|
|
|
177
|
|
|
// Localisation |
|
178
|
|
|
$this->load_plugin_textdomain(); |
|
179
|
|
|
add_action( 'init', array( $this, 'load_localisation' ), 0 ); |
|
180
|
|
|
|
|
181
|
|
|
// Setup settings |
|
182
|
|
|
$this->settings = new Sensei_Settings(); |
|
183
|
|
|
|
|
184
|
|
|
// load the shortcode loader into memory, so as to listen to all for |
|
185
|
|
|
// all shortcodes on the front end |
|
186
|
|
|
new Sensei_Shortcode_Loader(); |
|
187
|
|
|
|
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
/** |
|
191
|
|
|
* Global Sensei Instance |
|
192
|
|
|
* |
|
193
|
|
|
* Ensure that only one instance of the main Sensei class can be loaded. |
|
194
|
|
|
* |
|
195
|
|
|
* @since 1.8.0 |
|
196
|
|
|
* @static |
|
197
|
|
|
* @see WC() |
|
198
|
|
|
* @return WooThemes_Sensei Instance. |
|
199
|
|
|
*/ |
|
200
|
|
|
public static function instance() { |
|
201
|
|
|
|
|
202
|
|
|
if ( is_null( self::$_instance ) ) { |
|
203
|
|
|
|
|
204
|
|
|
//Sensei requires a reference to the main Sensei plugin file |
|
205
|
|
|
$sensei_main_plugin_file = dirname ( dirname( __FILE__ ) ) . '/woothemes-sensei.php'; |
|
206
|
|
|
|
|
207
|
|
|
self::$_instance = new self( $sensei_main_plugin_file ); |
|
208
|
|
|
|
|
209
|
|
|
// load the global class objects needed throughout Sensei |
|
210
|
|
|
self::$_instance->initialize_global_objects(); |
|
211
|
|
|
|
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
return self::$_instance; |
|
215
|
|
|
|
|
216
|
|
|
} // end instance() |
|
217
|
|
|
|
|
218
|
|
|
/** |
|
219
|
|
|
* This function is linked into the activation |
|
220
|
|
|
* hook to reset flush the urls to ensure Sensei post types show up. |
|
221
|
|
|
* |
|
222
|
|
|
* @since 1.9.0 |
|
223
|
|
|
* |
|
224
|
|
|
* @param $plugin |
|
225
|
|
|
*/ |
|
226
|
|
|
public static function activation_flush_rules( $plugin ){ |
|
227
|
|
|
|
|
228
|
|
|
if( strpos( $plugin, '/woothemes-sensei.php' ) > 0 ){ |
|
229
|
|
|
|
|
230
|
|
|
flush_rewrite_rules(true); |
|
231
|
|
|
|
|
232
|
|
|
} |
|
233
|
|
|
|
|
234
|
|
|
} |
|
235
|
|
|
|
|
236
|
|
|
/** |
|
237
|
|
|
* Cloning is forbidden. |
|
238
|
|
|
* @since 1.8.0 |
|
239
|
|
|
*/ |
|
240
|
|
|
public function __clone() { |
|
241
|
|
|
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woothemes-sensei' ), '1.8' ); |
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
|
|
/** |
|
245
|
|
|
* Unserializing instances of this class is forbidden. |
|
246
|
|
|
* @since 1.8.0 |
|
247
|
|
|
*/ |
|
248
|
|
|
public function __wakeup() { |
|
249
|
|
|
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woothemes-sensei' ), '1.8' ); |
|
250
|
|
|
} |
|
251
|
|
|
|
|
252
|
|
|
/** |
|
253
|
|
|
* Load the properties for the main Sensei object |
|
254
|
|
|
* |
|
255
|
|
|
* @since 1.9.0 |
|
256
|
|
|
*/ |
|
257
|
|
|
public function initialize_global_objects(){ |
|
258
|
|
|
|
|
259
|
|
|
// Setup post types. |
|
260
|
|
|
$this->post_types = new Sensei_PostTypes(); |
|
261
|
|
|
|
|
262
|
|
|
// Lad the updates class |
|
263
|
|
|
$this->updates = new Sensei_Updates( $this ); |
|
|
|
|
|
|
264
|
|
|
|
|
265
|
|
|
// Load Course Results Class |
|
266
|
|
|
$this->course_results = new Sensei_Course_Results(); |
|
267
|
|
|
|
|
268
|
|
|
// Load the teacher role |
|
269
|
|
|
$this->teacher = new Sensei_Teacher(); |
|
270
|
|
|
|
|
271
|
|
|
// Add the Course class |
|
272
|
|
|
$this->course = $this->post_types->course; |
|
|
|
|
|
|
273
|
|
|
|
|
274
|
|
|
// Add the lesson class |
|
275
|
|
|
$this->lesson = $this->post_types->lesson; |
|
|
|
|
|
|
276
|
|
|
|
|
277
|
|
|
// Add the question class |
|
278
|
|
|
$this->question = $this->post_types->question; |
|
|
|
|
|
|
279
|
|
|
|
|
280
|
|
|
//Add the quiz class |
|
281
|
|
|
$this->quiz = $this->post_types->quiz; |
|
|
|
|
|
|
282
|
|
|
|
|
283
|
|
|
// load the modules class after all plugsin are loaded |
|
284
|
|
|
add_action( 'plugins_loaded', array( $this, 'load_modules_class' ) ); |
|
285
|
|
|
|
|
286
|
|
|
// Load Learner Management Functionality |
|
287
|
|
|
$this->learners = new Sensei_Learner_Management( $this->file ); |
|
288
|
|
|
|
|
289
|
|
|
// Differentiate between administration and frontend logic. |
|
290
|
|
|
if ( is_admin() ) { |
|
291
|
|
|
|
|
292
|
|
|
// Load Admin Welcome class |
|
293
|
|
|
new Sensei_Welcome(); |
|
294
|
|
|
|
|
295
|
|
|
// Load Admin Class |
|
296
|
|
|
$this->admin = new Sensei_Admin( $this->file ); |
|
|
|
|
|
|
297
|
|
|
|
|
298
|
|
|
// Load Analysis Reports |
|
299
|
|
|
$this->analysis = new Sensei_Analysis( $this->file ); |
|
300
|
|
|
|
|
301
|
|
|
} else { |
|
302
|
|
|
|
|
303
|
|
|
// Load Frontend Class |
|
304
|
|
|
$this->frontend = new Sensei_Frontend(); |
|
305
|
|
|
|
|
306
|
|
|
// Load notice Class |
|
307
|
|
|
$this->notices = new Sensei_Notices(); |
|
308
|
|
|
|
|
309
|
|
|
// Load built in themes support integration |
|
310
|
|
|
new Sensei_Theme_Integration_Loader(); |
|
311
|
|
|
|
|
312
|
|
|
|
|
313
|
|
|
} |
|
314
|
|
|
|
|
315
|
|
|
// Load Grading Functionality |
|
316
|
|
|
$this->grading = new Sensei_Grading( $this->file ); |
|
317
|
|
|
|
|
318
|
|
|
// Load Email Class |
|
319
|
|
|
$this->emails = new Sensei_Emails( $this->file ); |
|
320
|
|
|
|
|
321
|
|
|
// Load Learner Profiles Class |
|
322
|
|
|
$this->learner_profiles = new Sensei_Learner_Profiles(); |
|
323
|
|
|
|
|
324
|
|
|
} |
|
325
|
|
|
|
|
326
|
|
|
/** |
|
327
|
|
|
* Initialize all Sensei hooks |
|
328
|
|
|
* |
|
329
|
|
|
* @since 1.9.0 |
|
330
|
|
|
*/ |
|
331
|
|
|
public function load_hooks(){ |
|
332
|
|
|
|
|
333
|
|
|
add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
334
|
|
|
add_action( 'after_setup_theme', array( $this, 'ensure_post_thumbnails_support' ) ); |
|
335
|
|
|
|
|
336
|
|
|
// Filter comment counts |
|
337
|
|
|
add_filter( 'wp_count_comments', array( $this, 'sensei_count_comments' ), 10, 2 ); |
|
338
|
|
|
|
|
339
|
|
|
add_action( 'body_class', array( $this, 'body_class' ) ); |
|
340
|
|
|
|
|
341
|
|
|
// Check for and activate JetPack LaTeX support |
|
342
|
|
|
add_action( 'plugins_loaded', array( $this, 'jetpack_latex_support'), 200 ); // Runs after Jetpack has loaded it's modules |
|
343
|
|
|
|
|
344
|
|
|
// check flush the rewrite rules if the option sensei_flush_rewrite_rules option is 1 |
|
345
|
|
|
add_action( 'init', array( $this, 'flush_rewrite_rules'), 101 ); |
|
346
|
|
|
|
|
347
|
|
|
} |
|
348
|
|
|
|
|
349
|
|
|
/** |
|
350
|
|
|
* Run Sensei updates. |
|
351
|
|
|
* @access public |
|
352
|
|
|
* @since 1.1.0 |
|
353
|
|
|
* @return void |
|
354
|
|
|
*/ |
|
355
|
|
|
public function run_updates() { |
|
356
|
|
|
// Run updates if administrator |
|
357
|
|
|
if ( current_user_can( 'manage_options' ) || current_user_can( 'manage_sensei' ) ) { |
|
358
|
|
|
|
|
359
|
|
|
$this->updates->update(); |
|
360
|
|
|
|
|
361
|
|
|
} // End If Statement |
|
362
|
|
|
} // End run_updates() |
|
363
|
|
|
|
|
364
|
|
|
/** |
|
365
|
|
|
* Register the widgets. |
|
366
|
|
|
* @access public |
|
367
|
|
|
* @since 1.0.0 |
|
368
|
|
|
* @return void |
|
369
|
|
|
*/ |
|
370
|
|
|
public function register_widgets () { |
|
371
|
|
|
// Widget List (key => value is filename => widget class). |
|
372
|
|
|
$widget_list = apply_filters( 'sensei_registered_widgets_list', array( 'course-component' => 'Course_Component', |
|
373
|
|
|
'lesson-component' => 'Lesson_Component', |
|
374
|
|
|
'course-categories' => 'Course_Categories', |
|
375
|
|
|
'category-courses' => 'Category_Courses' ) |
|
376
|
|
|
); |
|
377
|
|
|
foreach ( $widget_list as $key => $value ) { |
|
378
|
|
|
if ( file_exists( $this->plugin_path . 'widgets/widget-woothemes-sensei-' . $key . '.php' ) ) { |
|
379
|
|
|
require_once( $this->plugin_path . 'widgets/widget-woothemes-sensei-' . $key . '.php' ); |
|
380
|
|
|
register_widget( 'WooThemes_Sensei_' . $value . '_Widget' ); |
|
381
|
|
|
} |
|
382
|
|
|
} // End For Loop |
|
383
|
|
|
|
|
384
|
|
|
do_action( 'sensei_register_widgets' ); |
|
385
|
|
|
|
|
386
|
|
|
} // End register_widgets() |
|
387
|
|
|
|
|
388
|
|
|
/** |
|
389
|
|
|
* Load the plugin's localisation file. |
|
390
|
|
|
* @access public |
|
391
|
|
|
* @since 1.0.0 |
|
392
|
|
|
* @return void |
|
393
|
|
|
*/ |
|
394
|
|
|
public function load_localisation () { |
|
395
|
|
|
|
|
396
|
|
|
load_plugin_textdomain( 'woothemes-sensei', false, dirname( plugin_basename( $this->file ) ) . '/lang/' ); |
|
397
|
|
|
|
|
398
|
|
|
} // End load_localisation() |
|
399
|
|
|
|
|
400
|
|
|
/** |
|
401
|
|
|
* Load the plugin textdomain from the main WordPress "languages" folder. |
|
402
|
|
|
* @access public |
|
403
|
|
|
* @since 1.0.0 |
|
404
|
|
|
* @return void |
|
405
|
|
|
*/ |
|
406
|
|
|
public function load_plugin_textdomain () { |
|
407
|
|
|
|
|
408
|
|
|
$domain = 'woothemes-sensei'; |
|
409
|
|
|
// The "plugin_locale" filter is also used in load_plugin_textdomain() |
|
410
|
|
|
$locale = apply_filters( 'plugin_locale', get_locale(), $domain ); |
|
411
|
|
|
load_textdomain( $domain, WP_LANG_DIR . '/' . $domain . '/' . $domain . '-' . $locale . '.mo' ); |
|
412
|
|
|
load_plugin_textdomain( $domain, FALSE, dirname( plugin_basename( $this->file ) ) . '/lang/' ); |
|
413
|
|
|
|
|
414
|
|
|
} // End load_plugin_textdomain() |
|
415
|
|
|
|
|
416
|
|
|
/** |
|
417
|
|
|
* Run on activation. |
|
418
|
|
|
* @access public |
|
419
|
|
|
* @since 1.0.0 |
|
420
|
|
|
* @return void |
|
421
|
|
|
*/ |
|
422
|
|
|
public function activation () { |
|
423
|
|
|
|
|
424
|
|
|
$this->register_plugin_version(); |
|
425
|
|
|
|
|
426
|
|
|
} // End activation() |
|
427
|
|
|
|
|
428
|
|
|
|
|
429
|
|
|
/** |
|
430
|
|
|
* Register activation hooks. |
|
431
|
|
|
* @access public |
|
432
|
|
|
* @since 1.0.0 |
|
433
|
|
|
* @return void |
|
434
|
|
|
*/ |
|
435
|
|
|
public function install () { |
|
436
|
|
|
|
|
437
|
|
|
register_activation_hook( $this->file, array( $this, 'activate_sensei' ) ); |
|
438
|
|
|
register_activation_hook( $this->file, 'flush_rewrite_rules' ); |
|
439
|
|
|
|
|
440
|
|
|
} // End install() |
|
441
|
|
|
|
|
442
|
|
|
|
|
443
|
|
|
/** |
|
444
|
|
|
* Run on activation of the plugin. |
|
445
|
|
|
* @access public |
|
446
|
|
|
* @since 1.0.0 |
|
447
|
|
|
* @return void |
|
448
|
|
|
*/ |
|
449
|
|
|
public function activate_sensei () { |
|
450
|
|
|
|
|
451
|
|
|
update_option( 'skip_install_sensei_pages', 0 ); |
|
452
|
|
|
update_option( 'sensei_installed', 1 ); |
|
453
|
|
|
|
|
454
|
|
|
} // End activate_sensei() |
|
455
|
|
|
|
|
456
|
|
|
/** |
|
457
|
|
|
* Register the plugin's version. |
|
458
|
|
|
* @access public |
|
459
|
|
|
* @since 1.0.0 |
|
460
|
|
|
* @return void |
|
461
|
|
|
*/ |
|
462
|
|
|
private function register_plugin_version () { |
|
463
|
|
|
if ( $this->version != '' ) { |
|
464
|
|
|
|
|
465
|
|
|
update_option( 'woothemes-sensei-version', $this->version ); |
|
466
|
|
|
|
|
467
|
|
|
} |
|
468
|
|
|
} // End register_plugin_version() |
|
469
|
|
|
|
|
470
|
|
|
/** |
|
471
|
|
|
* Ensure that "post-thumbnails" support is available for those themes that don't register it. |
|
472
|
|
|
* @access public |
|
473
|
|
|
* @since 1.0.1 |
|
474
|
|
|
* @return void |
|
475
|
|
|
*/ |
|
476
|
|
|
public function ensure_post_thumbnails_support () { |
|
477
|
|
|
|
|
478
|
|
|
if ( ! current_theme_supports( 'post-thumbnails' ) ) { add_theme_support( 'post-thumbnails' ); } |
|
479
|
|
|
|
|
480
|
|
|
} // End ensure_post_thumbnails_support() |
|
481
|
|
|
|
|
482
|
|
|
/** |
|
483
|
|
|
* template_loader function. |
|
484
|
|
|
* |
|
485
|
|
|
* @access public |
|
486
|
|
|
* @param mixed $template |
|
487
|
|
|
* @return void |
|
488
|
|
|
* @deprecated |
|
489
|
|
|
*/ |
|
490
|
|
|
public function template_loader ( $template = '' ) { |
|
491
|
|
|
|
|
492
|
|
|
_deprecated_function( 'Sensei()->template_loader', '1.9.0', 'Use Sensei_Templates::template_loader( $template ) instead' ); |
|
493
|
|
|
Sensei_Templates::template_loader( $template ); |
|
494
|
|
|
|
|
495
|
|
|
} // End template_loader() |
|
496
|
|
|
|
|
497
|
|
|
/** |
|
498
|
|
|
* Determine the relative path to the plugin's directory. |
|
499
|
|
|
* @access public |
|
500
|
|
|
* @since 1.0.0 |
|
501
|
|
|
* @return string $sensei_plugin_path |
|
502
|
|
|
*/ |
|
503
|
|
|
public function plugin_path () { |
|
504
|
|
|
|
|
505
|
|
|
if ( $this->plugin_path ) { |
|
506
|
|
|
|
|
507
|
|
|
$sensei_plugin_path = $this->plugin_path; |
|
508
|
|
|
|
|
509
|
|
|
}else{ |
|
510
|
|
|
|
|
511
|
|
|
$sensei_plugin_path = plugin_dir_path( __FILE__ ); |
|
512
|
|
|
|
|
513
|
|
|
} |
|
514
|
|
|
|
|
515
|
|
|
return $sensei_plugin_path; |
|
516
|
|
|
|
|
517
|
|
|
} // End plugin_path() |
|
518
|
|
|
|
|
519
|
|
|
/** |
|
520
|
|
|
* Retrieve the ID of a specified page setting. |
|
521
|
|
|
* @access public |
|
522
|
|
|
* @since 1.0.0 |
|
523
|
|
|
* @param string $page |
|
524
|
|
|
* @return int |
|
525
|
|
|
*/ |
|
526
|
|
|
public function get_page_id ( $page ) { |
|
527
|
|
|
$page = apply_filters( 'sensei_get_' . esc_attr( $page ) . '_page_id', get_option( 'sensei_' . esc_attr( $page ) . '_page_id' ) ); |
|
528
|
|
|
return ( $page ) ? $page : -1; |
|
529
|
|
|
} // End get_page_id() |
|
530
|
|
|
|
|
531
|
|
|
/** |
|
532
|
|
|
* check_user_permissions function. |
|
533
|
|
|
* |
|
534
|
|
|
* @access public |
|
535
|
|
|
* @param string $page (default: '') |
|
536
|
|
|
* |
|
537
|
|
|
* @return bool |
|
538
|
|
|
*/ |
|
539
|
|
|
public function check_user_permissions ( $page = '' ) { |
|
540
|
|
|
|
|
541
|
|
|
global $current_user, $post; |
|
542
|
|
|
|
|
543
|
|
|
// if user is not logged in skipped for single lesson |
|
544
|
|
|
if ( empty( $current_user->caps ) && Sensei()->settings->get('access_permission') |
|
545
|
|
|
&& 'lesson-single' != $page ){ |
|
546
|
|
|
|
|
547
|
|
|
$this->permissions_message['title'] = __('Restricted Access', 'woothemes-sensei' ); |
|
548
|
|
|
$this->permissions_message['message'] = sprintf( __('You must be logged in to view this %s'), get_post_type() ); |
|
549
|
|
|
|
|
550
|
|
|
return false; |
|
551
|
|
|
} |
|
552
|
|
|
|
|
553
|
|
|
$user_allowed = false; |
|
554
|
|
|
|
|
555
|
|
|
switch ( $page ) { |
|
556
|
|
|
case 'course-single': |
|
557
|
|
|
// check for prerequisite course or lesson, |
|
558
|
|
|
$course_prerequisite_id = (int) get_post_meta( $post->ID, '_course_prerequisite', true); |
|
559
|
|
|
$update_course = Sensei_WC::course_update( $post->ID ); |
|
|
|
|
|
|
560
|
|
|
// Count completed lessons |
|
561
|
|
|
if ( 0 < absint( $course_prerequisite_id ) ) { |
|
562
|
|
|
|
|
563
|
|
|
$prerequisite_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, $current_user->ID ); |
|
564
|
|
|
|
|
565
|
|
|
} |
|
566
|
|
|
else { |
|
567
|
|
|
$prerequisite_complete = true; |
|
568
|
|
|
} // End If Statement |
|
569
|
|
|
// Handles restrictions |
|
570
|
|
View Code Duplication |
if ( !$prerequisite_complete && 0 < absint( $course_prerequisite_id ) ) { |
|
|
|
|
|
|
571
|
|
|
$this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
572
|
|
|
$course_link = '<a href="' . esc_url( get_permalink( $course_prerequisite_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
573
|
|
|
$this->permissions_message['message'] = sprintf( __('Please complete the previous %1$s before taking this course.', 'woothemes-sensei' ), $course_link ); |
|
574
|
|
|
} else { |
|
575
|
|
|
$user_allowed = true; |
|
576
|
|
|
} // End If Statement |
|
577
|
|
|
break; |
|
578
|
|
|
case 'lesson-single': |
|
579
|
|
|
// Check for WC purchase |
|
580
|
|
|
$lesson_course_id = get_post_meta( $post->ID, '_lesson_course',true ); |
|
581
|
|
|
|
|
582
|
|
|
$update_course = Sensei_WC::course_update( $lesson_course_id ); |
|
|
|
|
|
|
583
|
|
|
$is_preview = Sensei_Utils::is_preview_lesson( $post->ID ); |
|
584
|
|
|
|
|
585
|
|
|
if ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) { |
|
|
|
|
|
|
586
|
|
|
$user_allowed = true; |
|
587
|
|
|
} elseif( $this->access_settings() && false == $is_preview ) { |
|
|
|
|
|
|
588
|
|
|
|
|
589
|
|
|
$user_allowed = true; |
|
590
|
|
|
|
|
591
|
|
|
} else { |
|
592
|
|
|
$this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
593
|
|
|
$course_link = '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
594
|
|
|
$wc_post_id = get_post_meta( $lesson_course_id, '_course_woocommerce_product',true ); |
|
595
|
|
|
if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) { |
|
596
|
|
View Code Duplication |
if ( $is_preview ) { |
|
|
|
|
|
|
597
|
|
|
$this->permissions_message['message'] = sprintf( __('This is a preview lesson. Please purchase the %1$s to access all lessons.', 'woothemes-sensei' ), $course_link ); |
|
598
|
|
|
} else { |
|
599
|
|
|
$this->permissions_message['message'] = sprintf( __('Please purchase the %1$s before starting this Lesson.', 'woothemes-sensei' ), $course_link ); |
|
600
|
|
|
} |
|
601
|
|
View Code Duplication |
} else { |
|
|
|
|
|
|
602
|
|
|
if ( $is_preview ) { |
|
603
|
|
|
$this->permissions_message['message'] = sprintf( __('This is a preview lesson. Please sign up for the %1$s to access all lessons.', 'woothemes-sensei' ), $course_link ); |
|
604
|
|
|
} else { |
|
605
|
|
|
/** This filter is documented in class-woothemes-sensei-frontend.php */ |
|
606
|
|
|
$this->permissions_message['message'] = sprintf( __( 'Please sign up for the %1$s before starting the lesson.', 'woothemes-sensei' ), $course_link ); |
|
607
|
|
|
} |
|
608
|
|
|
} // End If Statement |
|
609
|
|
|
} // End If Statement |
|
610
|
|
|
break; |
|
611
|
|
|
case 'quiz-single': |
|
612
|
|
|
$lesson_id = get_post_meta( $post->ID, '_quiz_lesson',true ); |
|
613
|
|
|
$lesson_course_id = get_post_meta( $lesson_id, '_lesson_course',true ); |
|
614
|
|
|
|
|
615
|
|
|
$update_course = Sensei_WC::course_update( $lesson_course_id ); |
|
|
|
|
|
|
616
|
|
|
if ( ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) || sensei_all_access() ) { |
|
|
|
|
|
|
617
|
|
|
|
|
618
|
|
|
// Check for prerequisite lesson for this quiz |
|
619
|
|
|
$lesson_prerequisite_id = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true); |
|
620
|
|
|
$user_lesson_prerequisite_complete = Sensei_Utils::user_completed_lesson( $lesson_prerequisite_id, $current_user->ID); |
|
621
|
|
|
|
|
622
|
|
|
// Handle restrictions |
|
623
|
|
|
if( sensei_all_access() ) { |
|
624
|
|
|
|
|
625
|
|
|
$user_allowed = true; |
|
626
|
|
|
|
|
627
|
|
View Code Duplication |
} else { |
|
|
|
|
|
|
628
|
|
|
|
|
629
|
|
|
if ( 0 < absint( $lesson_prerequisite_id ) && ( !$user_lesson_prerequisite_complete ) ) { |
|
630
|
|
|
|
|
631
|
|
|
$this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
632
|
|
|
$lesson_link = '<a href="' . esc_url( get_permalink( $lesson_prerequisite_id ) ) . '">' . __( 'lesson', 'woothemes-sensei' ) . '</a>'; |
|
633
|
|
|
$this->permissions_message['message'] = sprintf( __('Please complete the previous %1$s before taking this Quiz.', 'woothemes-sensei' ), $lesson_link ); |
|
634
|
|
|
|
|
635
|
|
|
} else { |
|
636
|
|
|
|
|
637
|
|
|
$user_allowed = true; |
|
638
|
|
|
|
|
639
|
|
|
} // End If Statement |
|
640
|
|
|
} // End If Statement |
|
641
|
|
|
} elseif( $this->access_settings() ) { |
|
642
|
|
|
// Check if the user has started the course |
|
643
|
|
|
|
|
644
|
|
|
if ( is_user_logged_in() && ! Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) && ( isset( $this->settings->settings['access_permission'] ) && ( true == $this->settings->settings['access_permission'] ) ) ) { |
|
|
|
|
|
|
645
|
|
|
|
|
646
|
|
|
$user_allowed = false; |
|
647
|
|
|
$this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
648
|
|
|
$course_link = '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
649
|
|
|
$wc_post_id = get_post_meta( $lesson_course_id, '_course_woocommerce_product',true ); |
|
650
|
|
View Code Duplication |
if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) { |
|
|
|
|
|
|
651
|
|
|
$this->permissions_message['message'] = sprintf( __('Please purchase the %1$s before starting this Quiz.', 'woothemes-sensei' ), $course_link ); |
|
652
|
|
|
} else { |
|
653
|
|
|
$this->permissions_message['message'] = sprintf( __('Please sign up for the %1$s before starting this Quiz.', 'woothemes-sensei' ), $course_link ); |
|
654
|
|
|
} // End If Statement |
|
655
|
|
|
} else { |
|
656
|
|
|
$user_allowed = true; |
|
657
|
|
|
} // End If Statement |
|
658
|
|
|
} else { |
|
659
|
|
|
$this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
660
|
|
|
$course_link = '<a href="' . esc_url( get_permalink( get_post_meta( get_post_meta( $post->ID, '_quiz_lesson', true ), '_lesson_course', true ) ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
661
|
|
|
$this->permissions_message['message'] = sprintf( __('Please sign up for the %1$s before taking this Quiz.', 'woothemes-sensei' ), $course_link ); |
|
662
|
|
|
} // End If Statement |
|
663
|
|
|
break; |
|
664
|
|
|
default: |
|
665
|
|
|
$user_allowed = true; |
|
666
|
|
|
break; |
|
667
|
|
|
|
|
668
|
|
|
} // End Switch Statement |
|
669
|
|
|
|
|
670
|
|
|
/** |
|
671
|
|
|
* filter the permissions message shown on sensei post types. |
|
672
|
|
|
* |
|
673
|
|
|
* @since 1.8.7 |
|
674
|
|
|
* |
|
675
|
|
|
* @param array $permissions_message{ |
|
676
|
|
|
* |
|
677
|
|
|
* @type string $title |
|
678
|
|
|
* @type string $message |
|
679
|
|
|
* |
|
680
|
|
|
* } |
|
681
|
|
|
* @param string $post_id |
|
682
|
|
|
*/ |
|
683
|
|
|
$this->permissions_message = apply_filters( 'sensei_permissions_message', $this->permissions_message, $post->ID ); |
|
684
|
|
|
|
|
685
|
|
|
|
|
686
|
|
|
if( sensei_all_access() || Sensei_Utils::is_preview_lesson( $post->ID ) ) { |
|
687
|
|
|
$user_allowed = true; |
|
688
|
|
|
} |
|
689
|
|
|
|
|
690
|
|
|
/** |
|
691
|
|
|
* Filter the permissions check final result. Which determines if the user has |
|
692
|
|
|
* access to the given page. |
|
693
|
|
|
* |
|
694
|
|
|
* @since 1.0 |
|
695
|
|
|
* |
|
696
|
|
|
* @param boolean $user_allowed |
|
697
|
|
|
* @param integer $user_id |
|
698
|
|
|
* |
|
699
|
|
|
*/ |
|
700
|
|
|
return apply_filters( 'sensei_access_permissions', $user_allowed, $current_user->ID ); |
|
701
|
|
|
|
|
702
|
|
|
} // End get_placeholder_image() |
|
703
|
|
|
|
|
704
|
|
|
|
|
705
|
|
|
/** |
|
706
|
|
|
* Check if visitors have access permission. If the "access_permission" setting is active, do a log in check. |
|
707
|
|
|
* @since 1.0.0 |
|
708
|
|
|
* @access public |
|
709
|
|
|
* @return bool |
|
710
|
|
|
*/ |
|
711
|
|
|
public function access_settings () { |
|
712
|
|
|
|
|
713
|
|
|
if( sensei_all_access() ) return true; |
|
714
|
|
|
|
|
715
|
|
|
if ( isset( $this->settings->settings['access_permission'] ) && ( true == $this->settings->settings['access_permission'] ) ) { |
|
716
|
|
|
if ( is_user_logged_in() ) { |
|
717
|
|
|
return true; |
|
718
|
|
|
} else { |
|
719
|
|
|
return false; |
|
720
|
|
|
} // End If Statement |
|
721
|
|
|
} else { |
|
722
|
|
|
return true; |
|
723
|
|
|
} // End If Statement |
|
724
|
|
|
} // End access_settings() |
|
725
|
|
|
|
|
726
|
|
|
/** |
|
727
|
|
|
* load_class loads in class files |
|
728
|
|
|
* @since 1.2.0 |
|
729
|
|
|
* @access public |
|
730
|
|
|
* @return void |
|
731
|
|
|
*/ |
|
732
|
|
|
public function load_class ( $class_name = '' ) { |
|
733
|
|
|
if ( '' != $class_name && '' != $this->token ) { |
|
734
|
|
|
require_once( 'class-' . esc_attr( $this->token ) . '-' . esc_attr( $class_name ) . '.php' ); |
|
735
|
|
|
} // End If Statement |
|
736
|
|
|
} // End load_class() |
|
737
|
|
|
|
|
738
|
|
|
/** |
|
739
|
|
|
* Filtering wp_count_comments to ensure that Sensei comments are ignored |
|
740
|
|
|
* @since 1.4.0 |
|
741
|
|
|
* @access public |
|
742
|
|
|
* @param array $comments |
|
743
|
|
|
* @param integer $post_id |
|
744
|
|
|
* @return array |
|
745
|
|
|
*/ |
|
746
|
|
|
public function sensei_count_comments( $comments, $post_id ) { |
|
747
|
|
|
global $wpdb; |
|
748
|
|
|
|
|
749
|
|
|
$post_id = (int) $post_id; |
|
750
|
|
|
|
|
751
|
|
|
$count = wp_cache_get("comments-{$post_id}", 'counts'); |
|
752
|
|
|
|
|
753
|
|
|
if ( false !== $count ) { |
|
754
|
|
|
return $count; |
|
755
|
|
|
} |
|
756
|
|
|
|
|
757
|
|
|
$statuses = array( '' ); // Default to the WP normal comments |
|
758
|
|
|
$stati = $wpdb->get_results( "SELECT comment_type FROM {$wpdb->comments} GROUP BY comment_type", ARRAY_A ); |
|
759
|
|
|
foreach ( (array) $stati AS $status ) { |
|
760
|
|
|
if ( 'sensei_' != substr($status['comment_type'], 0, 7 ) ) { |
|
761
|
|
|
$statuses[] = $status['comment_type']; |
|
762
|
|
|
} |
|
763
|
|
|
} |
|
764
|
|
|
$where = "WHERE comment_type IN ('" . join("', '", array_unique( $statuses ) ) . "')"; |
|
765
|
|
|
|
|
766
|
|
|
if ( $post_id > 0 ) |
|
767
|
|
|
$where .= $wpdb->prepare( " AND comment_post_ID = %d", $post_id ); |
|
768
|
|
|
|
|
769
|
|
|
$count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A ); |
|
770
|
|
|
|
|
771
|
|
|
$total = 0; |
|
772
|
|
|
$approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash', 'post-trashed' => 'post-trashed'); |
|
773
|
|
|
foreach ( (array) $count as $row ) { |
|
774
|
|
|
// Don't count post-trashed toward totals |
|
775
|
|
|
if ( 'post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'] ) |
|
776
|
|
|
$total += $row['num_comments']; |
|
777
|
|
|
if ( isset( $approved[$row['comment_approved']] ) ) |
|
778
|
|
|
$stats[$approved[$row['comment_approved']]] = $row['num_comments']; |
|
|
|
|
|
|
779
|
|
|
} |
|
780
|
|
|
|
|
781
|
|
|
$stats['total_comments'] = $total; |
|
|
|
|
|
|
782
|
|
|
foreach ( $approved as $key ) { |
|
783
|
|
|
if ( empty($stats[$key]) ) |
|
784
|
|
|
$stats[$key] = 0; |
|
785
|
|
|
} |
|
786
|
|
|
|
|
787
|
|
|
$stats = (object) $stats; |
|
788
|
|
|
wp_cache_set("comments-{$post_id}", $stats, 'counts'); |
|
789
|
|
|
|
|
790
|
|
|
return $stats; |
|
791
|
|
|
} |
|
792
|
|
|
|
|
793
|
|
|
/** |
|
794
|
|
|
* Init images. |
|
795
|
|
|
* |
|
796
|
|
|
* @since 1.4.5 |
|
797
|
|
|
* @access public |
|
798
|
|
|
* @return void |
|
799
|
|
|
*/ |
|
800
|
|
|
public function init_image_sizes() { |
|
801
|
|
|
$course_archive_thumbnail = $this->get_image_size( 'course_archive_image' ); |
|
802
|
|
|
$course_single_thumbnail = $this->get_image_size( 'course_single_image' ); |
|
803
|
|
|
$lesson_archive_thumbnail = $this->get_image_size( 'lesson_archive_image' ); |
|
804
|
|
|
$lesson_single_thumbnail = $this->get_image_size( 'lesson_single_image' ); |
|
805
|
|
|
|
|
806
|
|
|
add_image_size( 'course_archive_thumbnail', $course_archive_thumbnail['width'], $course_archive_thumbnail['height'], $course_archive_thumbnail['crop'] ); |
|
807
|
|
|
add_image_size( 'course_single_thumbnail', $course_single_thumbnail['width'], $course_single_thumbnail['height'], $course_single_thumbnail['crop'] ); |
|
808
|
|
|
add_image_size( 'lesson_archive_thumbnail', $lesson_archive_thumbnail['width'], $lesson_archive_thumbnail['height'], $lesson_archive_thumbnail['crop'] ); |
|
809
|
|
|
add_image_size( 'lesson_single_thumbnail', $lesson_single_thumbnail['width'], $lesson_single_thumbnail['height'], $lesson_single_thumbnail['crop'] ); |
|
810
|
|
|
} |
|
811
|
|
|
|
|
812
|
|
|
/** |
|
813
|
|
|
* Get an image size. |
|
814
|
|
|
* |
|
815
|
|
|
* Variable is filtered by sensei_get_image_size_{image_size} |
|
816
|
|
|
* |
|
817
|
|
|
* @since 1.4.5 |
|
818
|
|
|
* @access public |
|
819
|
|
|
* @param mixed $image_size |
|
820
|
|
|
* @return string |
|
821
|
|
|
*/ |
|
822
|
|
|
public function get_image_size( $image_size ) { |
|
823
|
|
|
|
|
824
|
|
|
// Only return sizes we define in settings |
|
825
|
|
|
if ( ! in_array( $image_size, array( 'course_archive_image', 'course_single_image', 'lesson_archive_image', 'lesson_single_image' ) ) ) |
|
826
|
|
|
return apply_filters( 'sensei_get_image_size_' . $image_size, '' ); |
|
827
|
|
|
|
|
828
|
|
|
if( ! isset( $this->settings->settings[ $image_size . '_width' ] ) ) { |
|
829
|
|
|
$this->settings->settings[ $image_size . '_width' ] = false; |
|
830
|
|
|
} |
|
831
|
|
|
if( ! isset( $this->settings->settings[ $image_size . '_height' ] ) ) { |
|
832
|
|
|
$this->settings->settings[ $image_size . '_height' ] = false; |
|
833
|
|
|
} |
|
834
|
|
|
if( ! isset( $this->settings->settings[ $image_size . '_hard_crop' ] ) ) { |
|
835
|
|
|
$this->settings->settings[ $image_size . '_hard_crop' ] = false; |
|
836
|
|
|
} |
|
837
|
|
|
|
|
838
|
|
|
$size = array_filter( array( |
|
839
|
|
|
'width' => $this->settings->settings[ $image_size . '_width' ], |
|
840
|
|
|
'height' => $this->settings->settings[ $image_size . '_height' ], |
|
841
|
|
|
'crop' => $this->settings->settings[ $image_size . '_hard_crop' ] |
|
842
|
|
|
) ); |
|
843
|
|
|
|
|
844
|
|
|
$size['width'] = isset( $size['width'] ) ? $size['width'] : '100'; |
|
845
|
|
|
$size['height'] = isset( $size['height'] ) ? $size['height'] : '100'; |
|
846
|
|
|
$size['crop'] = isset( $size['crop'] ) ? $size['crop'] : 0; |
|
847
|
|
|
|
|
848
|
|
|
return apply_filters( 'sensei_get_image_size_' . $image_size, $size ); |
|
849
|
|
|
} |
|
850
|
|
|
|
|
851
|
|
|
public function body_class( $classes ) { |
|
852
|
|
|
if( is_sensei() ) { |
|
853
|
|
|
$classes[] = 'sensei'; |
|
854
|
|
|
} |
|
855
|
|
|
return $classes; |
|
856
|
|
|
} |
|
857
|
|
|
|
|
858
|
|
|
/** |
|
859
|
|
|
* Checks that the Jetpack Beautiful Maths module has been activated to support LaTeX within question titles and answers |
|
860
|
|
|
* |
|
861
|
|
|
* @return null |
|
862
|
|
|
* @since 1.7.0 |
|
863
|
|
|
*/ |
|
864
|
|
|
public function jetpack_latex_support() { |
|
865
|
|
|
if ( function_exists( 'latex_markup') ) { |
|
866
|
|
|
add_filter( 'sensei_question_title', 'latex_markup' ); |
|
867
|
|
|
add_filter( 'sensei_answer_text', 'latex_markup' ); |
|
868
|
|
|
} |
|
869
|
|
|
} |
|
870
|
|
|
|
|
871
|
|
|
/** |
|
872
|
|
|
* Load the module functionality. |
|
873
|
|
|
* |
|
874
|
|
|
* This function is hooked into plugins_loaded to avoid conflicts with |
|
875
|
|
|
* the retired modules extension. |
|
876
|
|
|
* |
|
877
|
|
|
* @since 1.8.0 |
|
878
|
|
|
*/ |
|
879
|
|
|
public function load_modules_class(){ |
|
880
|
|
|
global $sensei_modules; |
|
881
|
|
|
|
|
882
|
|
|
if( !class_exists( 'Sensei_Modules' ) |
|
883
|
|
|
&& 'Sensei_Modules' != get_class( $sensei_modules ) ) { |
|
884
|
|
|
|
|
885
|
|
|
//Load the modules class |
|
886
|
|
|
require_once( 'class-sensei-modules.php'); |
|
887
|
|
|
Sensei()->modules = new Sensei_Core_Modules( $this->file ); |
|
888
|
|
|
|
|
889
|
|
|
}else{ |
|
890
|
|
|
// fallback for people still using the modules extension. |
|
891
|
|
|
global $sensei_modules; |
|
892
|
|
|
Sensei()->modules = $sensei_modules; |
|
893
|
|
|
add_action( 'admin_notices', array( $this, 'disable_sensei_modules_extension'), 30 ); |
|
894
|
|
|
} |
|
895
|
|
|
} |
|
896
|
|
|
|
|
897
|
|
|
/** |
|
898
|
|
|
* Tell the user to that the modules extension is no longer needed. |
|
899
|
|
|
* |
|
900
|
|
|
* @since 1.8.0 |
|
901
|
|
|
*/ |
|
902
|
|
|
public function disable_sensei_modules_extension(){ ?> |
|
903
|
|
|
<div class="notice updated fade"> |
|
904
|
|
|
<p> |
|
905
|
|
|
<?php |
|
906
|
|
|
$plugin_manage_url = admin_url().'plugins.php#sensei-modules'; |
|
907
|
|
|
$plugin_link_element = '<a href="' . $plugin_manage_url . '" >plugins page</a> '; |
|
908
|
|
|
?> |
|
909
|
|
|
<strong> Modules are now included in Sensei,</strong> so you no longer need the Sensei Modules extension. |
|
910
|
|
|
Please deactivate and delete it from your <?php echo $plugin_link_element; ?>. (This will not affect your existing modules). |
|
911
|
|
|
</p> |
|
912
|
|
|
</div> |
|
913
|
|
|
|
|
914
|
|
|
<?php }// end function |
|
915
|
|
|
|
|
916
|
|
|
/** |
|
917
|
|
|
* Sensei wide rewrite flush call. |
|
918
|
|
|
* |
|
919
|
|
|
* To use this simply update the option 'sensei_flush_rewrite_rules' to 1 |
|
920
|
|
|
* |
|
921
|
|
|
* After the option is one the Rules will be flushed. |
|
922
|
|
|
* |
|
923
|
|
|
* @since 1.9.0 |
|
924
|
|
|
*/ |
|
925
|
|
|
public function flush_rewrite_rules(){ |
|
926
|
|
|
|
|
927
|
|
|
// ensures that the rewrite rules are flushed on the second |
|
928
|
|
|
// attempt. This ensure that the settings for any other process |
|
929
|
|
|
// have been completed and saved to the database before we refresh the |
|
930
|
|
|
// rewrite rules. |
|
931
|
|
|
$option = get_option('sensei_flush_rewrite_rules'); |
|
932
|
|
|
if( '1' == $option ) { |
|
933
|
|
|
|
|
934
|
|
|
update_option('sensei_flush_rewrite_rules', '2'); |
|
935
|
|
|
|
|
936
|
|
|
}elseif( '2' == $option ) { |
|
937
|
|
|
|
|
938
|
|
|
flush_rewrite_rules(); |
|
939
|
|
|
update_option('sensei_flush_rewrite_rules', '0'); |
|
940
|
|
|
|
|
941
|
|
|
} |
|
942
|
|
|
|
|
943
|
|
|
} // end flush_rewrite_rules |
|
944
|
|
|
|
|
945
|
|
|
/** |
|
946
|
|
|
* Calling this function will tell Sensei to flush rewrite |
|
947
|
|
|
* rules on the next load. |
|
948
|
|
|
* |
|
949
|
|
|
* @since 1.9.0 |
|
950
|
|
|
*/ |
|
951
|
|
|
public function initiate_rewrite_rules_flush(){ |
|
952
|
|
|
|
|
953
|
|
|
update_option('sensei_flush_rewrite_rules', '1'); |
|
954
|
|
|
|
|
955
|
|
|
} |
|
956
|
|
|
|
|
957
|
|
|
/** |
|
958
|
|
|
* sensei_woocommerce_email_course_details adds detail to email |
|
959
|
|
|
* |
|
960
|
|
|
* @deprecated since 1.9.0 use Sensei_WC::email_course_details |
|
961
|
|
|
* |
|
962
|
|
|
* @since 1.4.5 |
|
963
|
|
|
* @access public |
|
964
|
|
|
* @param WC_Order $order |
|
965
|
|
|
* |
|
966
|
|
|
* @return void |
|
967
|
|
|
*/ |
|
968
|
|
|
public function sensei_woocommerce_email_course_details( $order ) { |
|
969
|
|
|
|
|
970
|
|
|
Sensei_WC::email_course_details( $order ); |
|
971
|
|
|
|
|
972
|
|
|
} // end func email course details |
|
973
|
|
|
|
|
974
|
|
|
/** |
|
975
|
|
|
* @deprecated since 1.9.0, movde to the Sensei_WC class |
|
976
|
|
|
* @param $user_id |
|
977
|
|
|
* @param $subscription_key |
|
978
|
|
|
*/ |
|
979
|
|
|
public function sensei_woocommerce_reactivate_subscription( $user_id, $subscription_key ){ |
|
980
|
|
|
|
|
981
|
|
|
Sensei_WC::reactivate_subscription( $user_id, $subscription_key ); |
|
|
|
|
|
|
982
|
|
|
} |
|
983
|
|
|
|
|
984
|
|
|
/** |
|
985
|
|
|
* @deprecated since 1.9.0, movde to the Sensei_WC class |
|
986
|
|
|
* @param $user_id |
|
987
|
|
|
* @param $subscription_key |
|
988
|
|
|
*/ |
|
989
|
|
|
public function sensei_woocommerce_subscription_ended( $user_id, $subscription_key ){ |
|
990
|
|
|
|
|
991
|
|
|
Sensei_WC::end_subscription( $user_id, $subscription_key ); |
|
|
|
|
|
|
992
|
|
|
} |
|
993
|
|
|
|
|
994
|
|
|
/** |
|
995
|
|
|
* sensei_woocommerce_complete_order description |
|
996
|
|
|
* |
|
997
|
|
|
* @deprecated since 1.9.0 use Sensei_WC::complete_order( $order_id ); |
|
998
|
|
|
* @since 1.0.3 |
|
999
|
|
|
* @access public |
|
1000
|
|
|
* @param int $order_id WC order ID |
|
1001
|
|
|
* |
|
1002
|
|
|
* @return void |
|
1003
|
|
|
*/ |
|
1004
|
|
|
public function sensei_woocommerce_complete_order ( $order_id = 0 ) { |
|
1005
|
|
|
|
|
1006
|
|
|
Sensei_WC::complete_order( $order_id ); |
|
1007
|
|
|
|
|
1008
|
|
|
} // End sensei_woocommerce_complete_order() |
|
1009
|
|
|
|
|
1010
|
|
|
/** |
|
1011
|
|
|
* Runs when an order is cancelled. |
|
1012
|
|
|
* |
|
1013
|
|
|
* @deprecated since 1.9.0 |
|
1014
|
|
|
* |
|
1015
|
|
|
* @since 1.2.0 |
|
1016
|
|
|
* @param integer $order_id order ID |
|
1017
|
|
|
* @return void |
|
1018
|
|
|
*/ |
|
1019
|
|
|
public function sensei_woocommerce_cancel_order ( $order_id ) { |
|
1020
|
|
|
|
|
1021
|
|
|
Sensei_WC::cancel_order( $order_id ); |
|
1022
|
|
|
|
|
1023
|
|
|
} // End sensei_woocommerce_cancel_order() |
|
1024
|
|
|
|
|
1025
|
|
|
/** |
|
1026
|
|
|
* sensei_activate_subscription runs when a subscription product is purchased |
|
1027
|
|
|
* @deprecated since 1.9.0 |
|
1028
|
|
|
* @since 1.2.0 |
|
1029
|
|
|
* @access public |
|
1030
|
|
|
* @param integer $order_id order ID |
|
1031
|
|
|
* @return void |
|
1032
|
|
|
*/ |
|
1033
|
|
|
public function sensei_activate_subscription( $order_id = 0 ) { |
|
1034
|
|
|
|
|
1035
|
|
|
Sensei_WC::activate_subscription( $order_id ); |
|
|
|
|
|
|
1036
|
|
|
|
|
1037
|
|
|
} // End sensei_activate_subscription() |
|
1038
|
|
|
|
|
1039
|
|
|
/** |
|
1040
|
|
|
* If WooCommerce is activated and the customer has purchased the course, update Sensei to indicate that they are taking the course. |
|
1041
|
|
|
* @deprecated since 1.9.0 |
|
1042
|
|
|
* @since 1.0.0 |
|
1043
|
|
|
* @param int $course_id (default: 0) |
|
1044
|
|
|
* @param array/Object $order_user (default: array()) Specific user's data. |
|
|
|
|
|
|
1045
|
|
|
* @return bool|int |
|
1046
|
|
|
*/ |
|
1047
|
|
|
public function woocommerce_course_update ( $course_id = 0, $order_user = array() ) { |
|
1048
|
|
|
|
|
1049
|
|
|
return Sensei_WC::course_update( $course_id, $order_user ); |
|
1050
|
|
|
|
|
1051
|
|
|
} // End woocommerce_course_update() |
|
1052
|
|
|
|
|
1053
|
|
|
/** |
|
1054
|
|
|
* Returns the WooCommerce Product Object |
|
1055
|
|
|
* |
|
1056
|
|
|
* The code caters for pre and post WooCommerce 2.2 installations. |
|
1057
|
|
|
* |
|
1058
|
|
|
* @deprecated since 1.9.0 |
|
1059
|
|
|
* @since 1.1.1 |
|
1060
|
|
|
* |
|
1061
|
|
|
* @param integer $wc_product_id Product ID or Variation ID |
|
1062
|
|
|
* @param string $product_type '' or 'variation' |
|
1063
|
|
|
* |
|
1064
|
|
|
* @return WC_Product $wc_product_object |
|
1065
|
|
|
*/ |
|
1066
|
|
|
public function sensei_get_woocommerce_product_object ( $wc_product_id = 0, $product_type = '' ) { |
|
1067
|
|
|
|
|
1068
|
|
|
return Sensei_WC::get_product_object( $wc_product_id, $product_type ); |
|
1069
|
|
|
|
|
1070
|
|
|
} // End sensei_get_woocommerce_product_object() |
|
1071
|
|
|
|
|
1072
|
|
|
/** |
|
1073
|
|
|
* Setup required WooCommerce settings. |
|
1074
|
|
|
* @access public |
|
1075
|
|
|
* @since 1.1.0 |
|
1076
|
|
|
* @return void |
|
1077
|
|
|
*/ |
|
1078
|
|
|
public function set_woocommerce_functionality() { |
|
1079
|
|
|
|
|
1080
|
|
|
_deprecated_function('Sensei()->set_woocommerce_functionality', 'Sensei 1.9.0'); |
|
1081
|
|
|
|
|
1082
|
|
|
} // End set_woocommerce_functionality() |
|
1083
|
|
|
|
|
1084
|
|
|
/** |
|
1085
|
|
|
* Disable guest checkout if a course product is in the cart |
|
1086
|
|
|
* @deprecated since 1.9.0 |
|
1087
|
|
|
* @param boolean $guest_checkout Current guest checkout setting |
|
1088
|
|
|
* @return boolean Modified guest checkout setting |
|
1089
|
|
|
*/ |
|
1090
|
|
|
public function disable_guest_checkout( $guest_checkout ) { |
|
1091
|
|
|
|
|
1092
|
|
|
return Sensei_WC::disable_guest_checkout( $guest_checkout ); |
|
1093
|
|
|
|
|
1094
|
|
|
}// end disable_guest_checkout |
|
1095
|
|
|
|
|
1096
|
|
|
/** |
|
1097
|
|
|
* Change order status with virtual products to completed |
|
1098
|
|
|
* |
|
1099
|
|
|
* @deprecated since 1.9.0 use Sensei_WC::virtual_order_payment_complete( $order_status, $order_id ) |
|
1100
|
|
|
* |
|
1101
|
|
|
* @since 1.1.0 |
|
1102
|
|
|
* @param string $order_status |
|
1103
|
|
|
* @param int $order_id |
|
1104
|
|
|
* @return string |
|
1105
|
|
|
**/ |
|
1106
|
|
|
public function virtual_order_payment_complete( $order_status, $order_id ) { |
|
1107
|
|
|
|
|
1108
|
|
|
return Sensei_WC::virtual_order_payment_complete( $order_status, $order_id ); |
|
1109
|
|
|
} |
|
1110
|
|
|
|
|
1111
|
|
|
} // End Class |
|
1112
|
|
|
|
|
1113
|
|
|
/** |
|
1114
|
|
|
* Class Woothemes_Sensei |
|
1115
|
|
|
* @ignore only for backward compatibility |
|
1116
|
|
|
* @since 1.9.0 |
|
1117
|
|
|
*/ |
|
1118
|
|
|
class Woothemes_Sensei extends Sensei_Main{ } |
|
1119
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: