forked from gocodebox/lifterlms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlifterlms.php
557 lines (444 loc) · 15 KB
/
lifterlms.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
<?php
/**
* Plugin Name: LifterLMS
* Plugin URI: https://lifterlms.com/
* Description: LifterLMS, the #1 WordPress LMS solution, makes it easy to create, sell, and protect engaging online courses.
* Version: 3.23.0
* Author: LifterLMS
* Author URI: https://lifterlms.com/
* Text Domain: lifterlms
* Domain Path: /languages
* License: GPLv3
* License URI: https://www.gnu.org/licenses/gpl-3.0.html
* Requires at least: 4.8
* Tested up to: 4.9.8
*/
defined( 'ABSPATH' ) || exit;
/**
* Autoloader
*/
require_once 'vendor/autoload.php';
/**
* Main LifterLMS Class
* @class LifterLMS
*/
final class LifterLMS {
public $version = '3.23.0';
protected static $_instance = null;
public $course_factory = null;
public $person = null;
public $query = null;
public $session = null;
/**
* Main Instance of LifterLMS
* Ensures only one instance of LifterLMS is loaded or can be loaded.
* @see LLMS()
* @return LifterLMS - Main instance
* @since 1.0.0
* @version 1.0.0
*/
public static function instance() {
if ( is_null( self::$_instance ) ) {
self::$_instance = new self();
}
return self::$_instance;
}
/**
* LifterLMS Constructor.
* @return LifterLMS
* @since 1.0.0
* @version 3.21.1
*/
private function __construct() {
if ( function_exists( '__autoload' ) ) {
spl_autoload_register( '__autoload' );
}
spl_autoload_register( array( $this, 'autoload' ) );
// Define constants
$this->define_constants();
// localize as early as possible
// since 4.6 the "just_in_time" l10n will load the default (not custom) file first
// so we must localize before any l10n functions (like `__()`) are used
// so that our custom "safe" location will always load first
$this->localize();
//Include required files
$this->includes();
// setup session stuff
$this->session = new LLMS_Session();
// Hooks
register_activation_hook( __FILE__, array( 'LLMS_Install', 'install' ) );
add_action( 'init', array( $this, 'init' ), 0 );
add_action( 'init', array( $this, 'integrations' ), 1 );
add_action( 'init', array( $this, 'processors' ), 5 );
add_action( 'init', array( $this, 'include_template_functions' ) );
add_action( 'init', array( 'LLMS_Shortcodes', 'init' ) );
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'add_action_links' ), 10, 1 );
// tracking
if ( defined( 'DOING_CRON' ) && DOING_CRON && 'yes' === get_option( 'llms_allow_tracking', 'no' ) ) {
LLMS_Tracker::init();
}
// Loaded action
do_action( 'lifterlms_loaded' );
}
/**
* Auto-load LLMS classes.
* @param string $class class name being called
* @return void
* @since 1.0.0
* @version 3.15.0
*/
public function autoload( $class ) {
$class = strtolower( $class );
// if ( false === strpos( $class, 'llms' ) ) {
// return;
// }
$path = null;
$fileize = str_replace( '_', '.', $class );
$file = 'class.' . $fileize . '.php';
if ( strpos( $class, 'llms_meta_box' ) === 0 ) {
$path = $this->plugin_path() . '/includes/admin/post-types/meta-boxes/';
} elseif ( strpos( $class, 'llms_widget_' ) === 0 ) {
$path = $this->plugin_path() . '/includes/widgets/';
} elseif ( strpos( $class, 'llms_integration_' ) === 0 ) {
$path = $this->plugin_path() . '/includes/integrations/';
} elseif ( strpos( $class, 'llms_controller_' ) === 0 ) {
$path = $this->plugin_path() . '/includes/controllers/';
} elseif ( 0 === strpos( $class, 'llms_abstract' ) ) {
$path = $this->plugin_path() . '/includes/abstracts/';
$file = $fileize . '.php';
} elseif ( 0 === strpos( $class, 'llms_interface' ) ) {
$path = $this->plugin_path() . '/includes/interfaces/';
$file = $fileize . '.php';
} elseif ( strpos( $class, 'llms_' ) === 0 ) {
$path = $this->plugin_path() . '/includes/';
}
if ( $path && is_readable( $path . $file ) ) {
include_once( $path . $file );
return;
}
}
/**
* Define LifterLMS Constants
* @since 1.0.0
* @version 3.17.8
*/
private function define_constants() {
if ( ! defined( 'LLMS_PLUGIN_FILE' ) ) {
define( 'LLMS_PLUGIN_FILE', __FILE__ );
}
if ( ! defined( 'LLMS_VERSION' ) ) {
define( 'LLMS_VERSION', $this->version );
}
if ( ! defined( 'LLMS_TEMPLATE_PATH' ) ) {
define( 'LLMS_TEMPLATE_PATH', $this->template_path() );
}
if ( ! defined( 'LLMS_PLUGIN_DIR' ) ) {
define( 'LLMS_PLUGIN_DIR', WP_PLUGIN_DIR . '/' . plugin_basename( dirname( __FILE__ ) ) . '/' );
}
if ( ! defined( 'LLMS_SVG_DIR' ) ) {
define( 'LLMS_SVG_DIR', plugins_url( '/assets/svg/svg.svg', LLMS_PLUGIN_FILE ) );
}
$upload_dir = wp_upload_dir();
if ( ! defined( 'LLMS_LOG_DIR' ) ) {
define( 'LLMS_LOG_DIR', $upload_dir['basedir'] . '/llms-logs/' );
}
if ( ! defined( 'LLMS_TMP_DIR' ) ) {
define( 'LLMS_TMP_DIR', $upload_dir['basedir'] . '/llms-tmp/' );
}
if ( ! defined( 'LLMS_PLUGIN_URL' ) ) {
/**
* URL to the plugin directory for assets, etc
* @since 3.17.8
* @version 3.17.8
*/
define( 'LLMS_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
}
if ( ! defined( 'LLMS_ASSETS_SUFFIX' ) ) {
// if we're loading in debug mode
$debug = ( defined( 'SCRIPT_DEBUG' ) ) ? SCRIPT_DEBUG : false;
/* if debugging, load the unminified version
* on production, load the minified one
*/
$min = ( $debug ) ? '' : '.min';
/**
* Assets suffix
* Defines if minified versions of assets should be loaded
* @since 3.17.8
* @version 3.17.8
*/
define( 'LLMS_ASSETS_SUFFIX', $min );
}
}
/**
* Include required core classes
* @since 1.0.0
* @version 3.22.0
*/
private function includes() {
require_once 'includes/llms.functions.core.php';
require_once 'includes/class.llms.install.php';
require_once 'includes/class.llms.session.php';
require_once 'includes/class.llms.cache.helper.php';
require_once 'vendor/gocodebox/action-scheduler/action-scheduler.php';
require_once 'includes/class.llms.hasher.php';
require_once 'includes/processors/class.llms.processors.php';
include_once 'includes/abstracts/abstract.llms.admin.table.php';
include_once 'includes/admin/class.llms.admin.assets.php';
// privacy components
require_once 'includes/privacy/class-llms-privacy.php';
if ( is_admin() ) {
include_once 'includes/class.llms.dot.com.api.php';
include_once 'includes/class.llms.generator.php';
include_once 'includes/admin/class.llms.admin.import.php';
include_once 'includes/controllers/class.llms.controller.admin.quiz.attempts.php';
include_once 'includes/admin/post-types/tables/class.llms.table.student.management.php';
require_once 'includes/admin/llms.functions.admin.php';
include_once 'includes/admin/class.llms.admin.menus.php';
include_once 'includes/admin/class.llms.admin.notices.php';
include_once 'includes/admin/class.llms.admin.notices.core.php';
include_once 'includes/admin/class.llms.admin.post-types.php';
include_once 'includes/admin/post-types/class.llms.post.tables.php';
if ( ! empty( $_GET['page'] ) && 'llms-setup' === $_GET['page'] ) {
require_once 'includes/admin/class.llms.admin.setup.wizard.php';
}
include_once( 'includes/admin/reporting/widgets/class.llms.analytics.widget.ajax.php' );
include_once( 'includes/admin/post-types/meta-boxes/fields/llms.class.meta.box.fields.php' );
include_once( 'includes/admin/post-types/meta-boxes/fields/llms.interface.meta.box.field.php' );
include_once( 'includes/class.llms.analytics.php' );
include_once( 'includes/admin/class.llms.admin.reviews.php' );
require 'includes/abstracts/abstract.llms.admin.metabox.php';
include_once( 'includes/admin/class.llms.admin.user.custom.fields.php' );
include_once( 'includes/admin/class.llms.student.bulk.enroll.php' );
}
// legacy
include_once( 'includes/class.llms.quiz.legacy.php' );
// nav menus
require_once 'includes/class.llms.nav.menus.php';
include 'includes/notifications/class.llms.notifications.php';
// Date, Number and language formatting
include_once( 'includes/class.llms.date.php' );
include_once( 'includes/class.llms.number.php' );
// oembed
include_once( 'includes/class.llms.oembed.php' );
// svg management
include_once( 'includes/class.llms.svg.php' );
// Post types
include_once( 'includes/class.llms.post-types.php' );
// sidebars
require_once 'includes/class.llms.sidebars.php';
// Payment Gateway
require_once 'includes/abstracts/abstract.llms.payment.gateway.php';
require_once 'includes/class.llms.gateway.manual.php';
// Ajax
include_once( 'includes/class.llms.ajax.php' );
include_once( 'includes/class.llms.ajax.handler.php' );
// Hooks
include_once( 'includes/llms.template.hooks.php' );
// Models
require_once 'includes/abstracts/abstract.llms.post.model.php';
foreach ( glob( LLMS_PLUGIN_DIR . 'includes/models/*.php', GLOB_NOSORT ) as $model ) {
require_once $model;
}
// queries
include_once( 'includes/abstracts/abstract.llms.database.query.php' );
include_once( 'includes/class.llms.query.quiz.attempt.php' );
include_once( 'includes/class.llms.query.user.postmeta.php' );
include_once( 'includes/class.llms.student.query.php' );
include_once( 'includes/notifications/class.llms.notifications.query.php' );
// Classes
include_once( 'includes/class.llms.lesson.handler.php' );
include_once( 'includes/class.llms.course.factory.php' );
include_once( 'includes/class.llms.question.types.php' );
include_once( 'includes/class.llms.post.relationships.php' );
include_once( 'includes/class.llms.review.php' );
include_once( 'includes/class.llms.student.dashboard.php' );
include_once( 'includes/class.llms.user.permissions.php' );
include_once( 'includes/class.llms.view.manager.php' );
include_once( 'includes/class.llms.l10n.js.php' );
//handler classes
require_once 'includes/class.llms.person.handler.php';
require_once 'includes/class.llms.post.handler.php';
include_once( 'includes/widgets/class.llms.widgets.php' );
include_once( 'includes/widgets/class.llms.widget.php' );
include_once( 'includes/class.llms.query.php' );
// controllers
include_once 'includes/controllers/class.llms.controller.achievements.php';
include_once 'includes/controllers/class.llms.controller.certificates.php';
include_once 'includes/controllers/class.llms.controller.lesson.progression.php';
include_once 'includes/controllers/class.llms.controller.orders.php';
include_once 'includes/controllers/class.llms.controller.quizzes.php';
// form controllers
include_once 'includes/forms/controllers/class.llms.controller.account.php';
include_once 'includes/forms/controllers/class.llms.controller.login.php';
include_once 'includes/forms/controllers/class.llms.controller.registration.php';
// comments
include_once( 'includes/class.llms.comments.php' );
// shortcodes
require_once 'includes/shortcodes/class.llms.shortcodes.php';
require_once 'includes/shortcodes/class.llms.shortcode.my.account.php';
require_once 'includes/shortcodes/class.llms.shortcode.checkout.php';
$this->query = new LLMS_Query();
$this->course_factory = new LLMS_Course_Factory();
if ( ! is_admin() ) {
require_once 'includes/class.llms.https.php';
include_once( 'includes/class.llms.template.loader.php' );
include_once( 'includes/class.llms.frontend.assets.php' );
// form classes
include_once( 'includes/forms/frontend/class.llms.frontend.forms.php' );
include_once( 'includes/forms/frontend/class.llms.frontend.password.php' );
include_once( 'includes/class.llms.person.php' );
}
include_once 'includes/class-llms-grades.php';
require_once 'includes/class.llms.playnice.php';
}
/**
* Load Hooks
*/
public function include_template_functions() {
// if ( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
include_once( 'includes/llms.template.functions.php' );
// }
}
/**
* Init LifterLMS when WordPress Initialises.
* @return void [<description>]
* @since 1.0.0
* @version 3.21.1
*/
public function init() {
do_action( 'before_lifterlms_init' );
if ( ! is_admin() ) {
$this->person = new LLMS_Person();
}
$this->engagements();
$this->notifications();
do_action( 'lifterlms_init' );
}
/**
* Get the plugin url.
*
* @return string
*/
public function plugin_url() {
return untrailingslashit( plugins_url( '/', __FILE__ ) );
}
/**
* Get the plugin path.
*
* @return string
*/
public function plugin_path() {
return untrailingslashit( plugin_dir_path( __FILE__ ) );
}
/**
* Get the template path.
*
* @return string
*/
public function template_path() {
return apply_filters( 'llms_template_path', 'lifterlms/' );
}
public function mailer() {
return LLMS_Emails::instance();
}
public function achievements() {
return LLMS_Achievements::instance();
}
public function certificates() {
return LLMS_Certificates::instance();
}
public function engagements() {
return LLMS_Engagements::instance();
}
/**
* Grading instance
* @return obj
* @since [version]
* @version [version]
*/
public function grades() {
return LLMS_Grades::instance();
}
/**
* get integrations
* @return object instance
*/
public function integrations() {
return LLMS_Integrations::instance();
}
/**
* Retrieve an instance of the notifications class
* @return obj
* @since 3.8.0
* @version 3.8.0
*/
public function notifications() {
return LLMS_Notifications::instance();
}
/**
* get payment gateways.
* @return array
*/
public function payment_gateways() {
return LLMS_Payment_Gateways::instance();
}
/**
* Load all background processors and
* access to them programattically a processor via LLMS()->processors()->get( $processor )
* @return LLMS_Processors
* @since 3.15.0
* @version 3.15.0
*/
public function processors() {
return LLMS_Processors::instance();
}
/**
* Add Action Links
* Settings action links
*
* @param array $links [array of links]
*/
public function add_action_links( $links ) {
$lifter_links = array(
'<a href="' . admin_url( 'admin.php?page=llms-settings' ) . '">' . __( 'Settings', 'lifterlms' ) . '</a>'
);
if ( count( $links ) == 3 ) {
return $links;
}
return array_merge( $links, $lifter_links );
}
/**
* Load Localization files
*
* The first loaded file takes priority
*
* Files can be found in the following order:
* WP_LANG_DIR/lifterlms/lifterlms-LOCALE.mo
* WP_LANG_DIR/plugins/lifterlms-LOCALE.mo
*
* @return void
*/
public function localize() {
// load locale
$locale = apply_filters( 'plugin_locale', get_locale(), 'lifterlms' );
// load a lifterlms specific locale file if one exists
load_textdomain( 'lifterlms', WP_LANG_DIR . '/lifterlms/lifterlms-' . $locale . '.mo' );
// load localization files
load_plugin_textdomain( 'lifterlms', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
}
}
/**
* shame shame shame...
* http://i.giphy.com/c2YyNySJ1CbFC.gif
*/
// @codingStandardsIgnoreStart
/**
* Returns the main instance of LLMS
*
* @return LifterLMS
*/
function LLMS() {
return LifterLMS::instance();
}
// @codingStandardsIgnoreEnd
return LLMS();