forked from actual-saurabh/lifterlms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlifterlms.php
694 lines (570 loc) · 18.1 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
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
<?php
/**
* LifterLMS WordPress Plugin
*
* @package LifterLMS/Main
*
* @since 1.0.0
* @version 3.37.0
*
* Plugin Name: LifterLMS
* Plugin URI: https://lifterlms.com/
* Description: LifterLMS is a powerful WordPress learning management system plugin that makes it easy to create, sell, and protect engaging online courses and training based membership websites.
* Version: 3.37.9
* 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: 5.3.0
*
* * * * * * * * * * * * * * * * * * * * * *
* *
* Reporting a Security Vulnerability *
* *
* Please disclose any security issues or *
* vulnerabilities to [email protected] *
* *
* See our full Security Policy at *
* https://lifterlms.com/security-policy *
* *
* * * * * * * * * * * * * * * * * * * * * *
*/
defined( 'ABSPATH' ) || exit;
// Autoloader.
require_once 'vendor/autoload.php';
/**
* Main LifterLMS Class
*
* @since 1.0.0
* @since 3.32.0 Update action-scheduler to latest version; load staging class on the admin panel.
* @since 3.34.0 Include the LLMS_Admin_Users_Table class.
* @since 3.36.0 Added events classes and methods.
* @since 3.36.1 Include SendWP Connector.
* @since 3.37.0 Move theme support methods to LLMS_Theme_Support.
*/
final class LifterLMS {
/**
* LifterLMS Plugin Version.
*
* @var string
*/
public $version = '3.37.9';
/**
* Singleton instance of LifterLMS.
*
* @var LifterLMS
*/
protected static $_instance = null;
/**
* LifterLMS Course Factory
*
* @var LLMS_Course_Factory
*/
public $course_factory = null;
/**
* LLMS_Person instance
*
* @var LLMS_Person
*/
public $person = null;
/**
* LLMS_Query instance
*
* @var LLMS_Query
*/
public $query = null;
/**
* Session instance
*
* @var LLMS_Session
*/
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, 'events' ), 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.
*
* @since 1.0.0
* @since 3.15.0 Unknown.
*
* @param string $class Class name being called.
* @return void
*/
public function autoload( $class ) {
$class = strtolower( $class );
$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 versionon production, load the minified one.
$min = ( $debug ) ? '' : '.min';
/**
* Assets suffix
*
* Defines if minified versions of assets should be loaded.
*
* @since 3.17.8
*/
define( 'LLMS_ASSETS_SUFFIX', $min );
}
}
/**
* Include required core classes
*
* @since 1.0.0
* @since 3.31.0 Add theme support includes.
* @since 3.32.0-beta.2 Update action-scheduler to latest version; load staging class on the admin panel.
* @since 3.34.0 Include LLMS_Admin_Users Table class.
* @since 3.35.0 Access $_GET variable via `llms_filter_input()`.
* @since 3.36.0 Include events classes.
* @since 3.36.1 Include SendWP Connector.
* @since 3.37.0 Include LLMS_Theme_Support class.
*
* @return void
*/
private function includes() {
if ( function_exists( 'has_blocks' ) && ! defined( 'LLMS_BLOCKS_VERSION' ) ) {
require_once 'vendor/lifterlms/lifterlms-blocks/lifterlms-blocks.php';
}
// Only load bundled REST API if the plugin version doesn't exist.
if ( ! class_exists( 'LifterLMS_REST_API' ) ) {
require_once 'vendor/lifterlms/lifterlms-rest/lifterlms-rest.php';
}
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/prospress/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/admin/class-llms-admin-users-table.php';
include_once 'includes/class-llms-staging.php';
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 ( 'llms-setup' === llms_filter_input( INPUT_GET, 'page', FILTER_SANITIZE_STRING ) ) {
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';
require_once 'includes/admin/class-llms-admin-review.php';
require_once 'includes/admin/class-llms-admin-export-download.php';
require_once 'includes/admin/class-llms-sendwp.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/class-llms-events-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';
}
require_once 'includes/class-llms-grades.php';
require_once 'includes/class-llms-events.php';
require_once 'includes/class-llms-events-core.php';
require_once 'includes/class-llms-sessions.php';
require_once 'includes/class.llms.playnice.php';
require_once 'includes/theme-support/class-llms-theme-support.php';
}
/**
* Load Hooks
*
* @since Unknown
*
* @return void
*/
public function include_template_functions() {
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/' );
}
/**
* Retrieve the LLMS_Emails singleton.
*
* @since Unknown
*
* @return LLMS_Emails
*/
public function mailer() {
return LLMS_Emails::instance();
}
/**
* Retrieve the LLMS_Achievements singleton.
*
* @since Unknown
*
* @return LLMS_Achievements
*/
public function achievements() {
return LLMS_Achievements::instance();
}
/**
* Retrieve the LLMS_Certificates singleton.
*
* @since Unknown
*
* @return LLMS_Certificates
*/
public function certificates() {
return LLMS_Certificates::instance();
}
/**
* Retrieve the LLMS_Engagements singleton.
*
* @since Unknown
*
* @return LLMS_Engagements
*/
public function engagements() {
return LLMS_Engagements::instance();
}
/**
* Events instance.
*
* @since 3.36.0
*
* @return LLMS_Events
*/
public function events() {
return LLMS_Events::instance();
}
/**
* Grading instance
*
* @since 3.24.0
*
* @return LLMS_Grades
*/
public function grades() {
return LLMS_Grades::instance();
}
/**
* Get integrations
*
* @return LLMS_Integrations instance
*/
public function integrations() {
return LLMS_Integrations::instance();
}
/**
* Retrieve an instance of the notifications class
*
* @return LLMS_Notifications
* @since 3.8.0
* @version 3.8.0
*/
public function notifications() {
return LLMS_Notifications::instance();
}
/**
* Get payment gateways.
*
* @return LLMS_Payment_Gateways
*/
public function payment_gateways() {
return LLMS_Payment_Gateways::instance();
}
/**
* Load all background processors and
* access to them programmatically a processor via LLMS()->processors()->get( $processor )
*
* @since 3.15.0
*
* @return LLMS_Processors
*/
public function processors() {
return LLMS_Processors::instance();
}
/**
* Add plugin settings Action Links
*
* @since Unknown
*
* @param string[] $links Existing action links.
* @return string[]
*/
public function add_action_links( $links ) {
$lifter_links = array(
'<a href="' . admin_url( 'admin.php?page=llms-settings' ) . '">' . __( 'Settings', 'lifterlms' ) . '</a>',
);
if ( 3 === count( $links ) ) {
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' );
}
}
// @codingStandardsIgnoreStart
/**
* Returns the main instance of LLMS
*
* @return LifterLMS
*/
function LLMS() {
return LifterLMS::instance();
}
// @codingStandardsIgnoreEnd
return LLMS();