-
Notifications
You must be signed in to change notification settings - Fork 140
/
learnpress.php
947 lines (802 loc) · 26.2 KB
/
learnpress.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
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
<?php
/**
* Plugin Name: LearnPress
* Plugin URI: http://thimpress.com/learnpress
* Description: LearnPress is a WordPress complete solution for creating a Learning Management System (LMS). It can help you to create courses, lessons and quizzes.
* Author: ThimPress
* Version: 4.2.7.3
* Author URI: http://thimpress.com
* Requires at least: 6.0
* Requires PHP: 7.0
* Text Domain: learnpress
* Domain Path: /languages/
*
* @package LearnPress
*/
use LearnPress\ExternalPlugin\Elementor\LPElementor;
use LearnPress\ExternalPlugin\YoastSeo\LPYoastSeo;
use LearnPress\Shortcodes\Course\FilterCourseShortcode;
//use LearnPress\Shortcodes\Course\ListCourseRecentShortcode;
use LearnPress\Shortcodes\ListInstructorsShortcode;
use LearnPress\Shortcodes\SingleInstructorShortcode;
use LearnPress\Shortcodes\CourseMaterialShortcode;
use LearnPress\TemplateHooks\Course\FilterCourseTemplate;
use LearnPress\TemplateHooks\Course\ListCoursesRelatedTemplate;
use LearnPress\TemplateHooks\Course\ListCoursesTemplate;
use LearnPress\TemplateHooks\Course\SingleCourseOfflineTemplate;
use LearnPress\TemplateHooks\Course\SingleCourseTemplate;
use LearnPress\TemplateHooks\Instructor\ListInstructorsTemplate;
use LearnPress\TemplateHooks\Instructor\SingleInstructorTemplate;
use LearnPress\TemplateHooks\Profile\ProfileGeneralInfoTemplate;
use LearnPress\TemplateHooks\Profile\ProfileInstructorStatisticsTemplate;
use LearnPress\TemplateHooks\Profile\ProfileOrdersTemplate;
use LearnPress\TemplateHooks\Profile\ProfileOrderTemplate;
use LearnPress\TemplateHooks\Profile\ProfileStudentStatisticsTemplate;
use LearnPress\TemplateHooks\Course\CourseMaterialTemplate;
use LearnPress\Widgets\LPRegisterWidget;
defined( 'ABSPATH' ) || exit();
if ( ! defined( 'LP_PLUGIN_FILE' ) ) {
define( 'LP_PLUGIN_FILE', __FILE__ );
include_once 'inc/lp-constants.php';
}
if ( ! class_exists( 'LearnPress' ) ) {
/**
* Class LearnPress
*
* Version 3.0.1
*/
class LearnPress {
/**
* Current version of the plugin
*
* @var string
*/
public $version = LEARNPRESS_VERSION;
/**
* Version database require, use for this LP source
*
* @var int
*/
public $db_version = 5;
/**
* The single instance of the class
*
* @var LearnPress object
*/
private static $_instance = null;
/**
* Store the session class
*
* @var LP_Session_Handler
*/
public $session = null;
/**
* @var LP_Profile
*/
public $profile = null;
/**
* @var LP_Cart object
*/
public $cart = false;
/**
* @var LP_Settings
*/
public $settings = null;
/**
* @var null
*/
public $schedule = null;
/**
* @var array
*/
public $query_vars = array();
/**
* Table prefixes
*
* @var array
*/
protected $_table_prefixes = array();
/**
* @var null
*/
public $query = null;
/**
* @var array
*/
public $global = array();
/**
* @var LP_Template
*/
public $template = null;
/**
* @var LP_Core_API
*/
public $api = null;
/**
* @var LP_Admin_Core_API
*/
public $admin_api = null;
/**
* @var string
*/
public $thim_core_version_require = '2.0.0';
/**
*
*/
public $theme_support = null;
public $gateways = null;
/**
* LearnPress constructor.
*/
public function __construct() {
/*if ( isset( $_POST['action'] ) && 'heartbeat' === $_POST['action'] ) {
return;
}*/
try {
if ( self::$_instance ) {
return;
}
self::$_instance = $this;
// Update for case compare version of LP if LEARNPRESS_VERSION undefined
if ( is_admin() ) {
update_option( 'learnpress_version', $this->version );
}
// Define constant .
$this->plugin_defines();
// define table prefixes .
$this->define_tables();
// Include files .
$this->includes();
// hooks .
$this->init_hooks();
} catch ( Throwable $e ) {
error_log( __METHOD__ . ': ' . $e->getMessage() );
}
}
/**
* Define constant.
*/
protected function plugin_defines() {
}
/**
* Defines database table names.
*/
public function define_tables() {
global $wpdb;
$tables = array(
'sessions',
'sections',
'section_items',
'user_items',
'user_itemmeta',
'user_item_results',
'order_items',
'order_itemmeta',
'quiz_questions',
'question_answers',
'question_answermeta',
);
foreach ( $tables as $short_name ) {
$table_name = $wpdb->prefix . LP_TABLE_PREFIX . $short_name;
$this->_table_prefixes[ 'tbl_' . $short_name ] = $table_name;
$backward_key = 'learnpress_' . $short_name;
$wpdb->{$backward_key} = $table_name;
}
}
/**
* Includes needed files.
*/
public function includes() {
include_once LP_PLUGIN_PATH . 'vendor/autoload.php';
// Include required files load anywhere, both frontend and backend.
$this->include_files_global();
// include files when LP ready run - after setup success .
if ( ! LP_Install::instance()->tables_install_done() ) {
return;
}
// Include required files Backend.
$this->include_files_admin();
// Include required files Frontend.
$this->include_files_frontend();
new LP_Query();
}
/**
* load files anywhere, both frontend and backend
*
* @return void
*/
private function include_files_global() {
include_once 'inc/class-lp-multi-language.php';
// Filter query .
include_once 'inc/Filters/class-lp-filter.php';
include_once 'inc/Filters/class-lp-post-type-filter.php';
include_once 'inc/Filters/class-lp-post-meta-filter.php';
include_once 'inc/Filters/class-lp-user-filter.php';
include_once 'inc/Filters/class-lp-course-filter.php';
include_once 'inc/Filters/class-lp-course-json-filter.php';
include_once 'inc/Filters/class-lp-order-filter.php';
include_once 'inc/Filters/class-lp-session-filter.php';
include_once 'inc/Filters/class-lp-section-filter.php';
include_once 'inc/Filters/class-lp-section-items-filter.php';
include_once 'inc/Filters/class-lp-question-filter.php';
include_once 'inc/Filters/class-lp-user-items-filter.php';
include_once 'inc/Filters/class-lp-user-item-meta-filter.php';
include_once 'inc/Filters/class-lp-quiz-questions-filter.php';
include_once 'inc/Filters/class-lp-question-answers-filter.php';
include_once 'inc/Filters/class-lp-question-answermeta-filter.php';
// Query Database .
include_once 'inc/Databases/class-lp-db.php';
include_once 'inc/Databases/class-lp-course-json-db.php';
include_once 'inc/Databases/class-lp-order-db.php';
include_once 'inc/Databases/class-lp-post-db.php';
include_once 'inc/Databases/class-lp-post-meta-db.php';
include_once 'inc/Databases/class-lp-user-db.php';
include_once 'inc/Databases/class-lp-course-db.php';
include_once 'inc/Databases/class-lp-lesson-db.php';
include_once 'inc/Databases/class-lp-section-db.php';
include_once 'inc/Databases/class-lp-section-items-db.php';
include_once 'inc/Databases/class-lp-quiz-db.php';
include_once 'inc/Databases/class-lp-quiz-questions-db.php';
include_once 'inc/Databases/class-lp-question-answers-db.php';
include_once 'inc/Databases/class-lp-sessions-db.php';
include_once 'inc/Databases/class-lp-question-db.php';
include_once 'inc/Databases/class-lp-user-items-db.php';
include_once 'inc/Databases/class-lp-user-item-meta-db.php';
include_once 'inc/Databases/class-lp-user-item-results-db.php';
include_once 'inc/Databases/class-thim-cache-db.php';
include_once 'inc/Databases/class-lp-material-db.php';
include_once 'inc/Databases/class-lp-statistics-db.php';
// File system .
include_once 'inc/class-lp-file-system.php';
// File helper
include_once 'inc/class-lp-helper.php';
// Template Hooks.
ListCoursesTemplate::instance();
ListCoursesRelatedTemplate::instance();
ListInstructorsTemplate::instance();
SingleCourseTemplate::instance();
SingleCourseOfflineTemplate::instance();
SingleInstructorTemplate::instance();
ProfileInstructorStatisticsTemplate::instance();
ProfileStudentStatisticsTemplate::instance();
ProfileOrdersTemplate::instance();
ProfileOrderTemplate::instance();
ProfileGeneralInfoTemplate::instance();
FilterCourseTemplate::instance();
CourseMaterialTemplate::instance();
// Models
include_once 'inc/Models/class-lp-rest-response.php';
include_once 'inc/Models/steps/class-lp-group-step.php';
include_once 'inc/Models/steps/class-lp-step.php';
include_once 'inc/Models/class-lp-course-extra-info-fast-query-model.php';
// Handle steps.
include_once 'inc/handle-steps/class-lp-handle-steps.php';
include_once 'inc/handle-steps/class-lp-handle-upgrade-db-steps.php';
// LP Cache
include_once 'inc/cache/class-lp-cache.php';
include_once 'inc/cache/class-lp-courses-cache.php';
include_once 'inc/cache/class-lp-course-cache.php';
include_once 'inc/cache/class-lp-quiz-cache.php';
include_once 'inc/cache/class-lp-question-cache.php';
include_once 'inc/cache/class-lp-session-cache.php';
include_once 'inc/cache/class-lp-settings-cache.php';
include_once 'inc/cache/class-lp-user-items-cache.php';
// Background processes.
include_once 'inc/libraries/wp-background-process/wp-background-processing.php';
include_once 'inc/background-process/abstract-lp-async-request.php';
//include_once 'inc/background-process/abstract-lp-async-task.php';
include_once 'inc/background-process/class-lp-background-single-course.php';
include_once 'inc/background-process/class-lp-background-single-email.php';
include_once 'inc/background-process/class-lp-background-thim-cache.php';
// Assets object
include_once 'inc/class-lp-asset-key.php';
include_once 'inc/abstracts/abstract-assets.php';
// Debug class
include_once 'inc/class-lp-debug.php';
include_once 'inc/class-lp-settings.php';
include_once 'inc/abstract-settings.php';
include_once 'inc/settings/abstract-settings-page.php';
include_once 'inc/settings/class-lp-settings-courses.php';
include_once 'inc/class-lp-global.php';
include_once 'inc/class-lp-datetime.php';
// Register custom-post-type and taxonomies .
include_once 'inc/custom-post-types/abstract.php';
include_once 'inc/custom-post-types/course.php';
include_once 'inc/custom-post-types/lesson.php';
include_once 'inc/custom-post-types/quiz.php';
include_once 'inc/custom-post-types/question.php';
include_once 'inc/custom-post-types/order.php';
include_once 'inc/interfaces/interface-curd.php';
include_once 'inc/abstracts/abstract-array-access.php';
include_once 'inc/abstracts/abstract-object-data.php';
include_once 'inc/abstracts/abstract-post-data.php';
include_once 'inc/curds/class-lp-course-curd.php';
include_once 'inc/curds/class-lp-section-curd.php';
include_once 'inc/curds/class-lp-lesson-curd.php';
include_once 'inc/curds/class-lp-quiz-curd.php';
include_once 'inc/curds/class-lp-question-curd.php';
include_once 'inc/curds/class-lp-order-curd.php';
include_once 'inc/curds/class-lp-user-curd.php';
include_once 'inc/curds/class-lp-user-item-curd.php';
include_once 'inc/course/class-lp-course-item.php';
include_once 'inc/question/class-lp-question.php';
include_once 'inc/course/class-lp-course-section.php';
include_once 'inc/course/class-lp-course-no-required-enroll.php';
include_once 'inc/user-item/class-lp-user-item.php';
include_once 'inc/user-item/class-lp-user-item-course.php';
include_once 'inc/lp-deprecated.php'; // Will remove if Eduma and guest update all 4.0.0
include_once 'inc/lp-core-functions.php';
include_once 'inc/class-lp-autoloader.php';
include_once 'inc/lp-webhooks.php'; // Addon learnpress-2checkout-payment v4.0.1 is using, when update v4.0.2 don't need load it.
include_once 'inc/class-lp-request-handler.php';
include_once 'inc/admin/helpers/class-lp-plugins-helper.php';
// Todo: tungnx check those files.
include_once 'inc/abstracts/abstract-object-query.php';
include_once 'inc/class-lp-course-query.php';
include_once 'inc/abstracts/abstract-addon.php';
include_once 'inc/class-lp-thumbnail-helper.php';
include_once 'inc/cache.php';
// Class handle check db of LP need to upgrade?
include_once 'inc/admin/class-lp-updater.php';
include_once 'inc/course/lp-course-functions.php';
include_once 'inc/course/abstract-course.php';
include_once 'inc/course/class-lp-course.php';
include_once 'inc/quiz/lp-quiz-functions.php';
include_once 'inc/quiz/class-lp-quiz.php';
include_once 'inc/lesson/lp-lesson-functions.php';
include_once 'inc/order/lp-order-functions.php';
include_once 'inc/order/class-lp-order.php';
include_once 'inc/user/lp-user-functions.php';
include_once 'inc/user/class-lp-user-factory.php';
include_once 'inc/user/abstract-lp-user.php';
include_once 'inc/user/class-lp-user.php';
include_once 'inc/user/class-lp-profile.php';
include_once 'inc/user-item/class-lp-user-item.php';
include_once 'inc/user-item/class-lp-user-item-course.php';
include_once 'inc/user-item/class-lp-user-item-quiz.php';
include_once 'inc/user-item/class-lp-quiz-results.php';
// Shortcodes.
SingleInstructorShortcode::instance();
ListInstructorsShortcode::instance();
CourseMaterialShortcode::instance();
FilterCourseShortcode::instance();
//ListCourseRecentShortcode::instance();
include_once 'inc/class-lp-shortcodes.php';
// include template functions .
include_once 'inc/lp-template-functions.php';
include_once 'inc/templates/abstract-template.php';
//include_once 'inc/class-lp-template.php';
// Cart
include_once 'inc/cart/class-lp-cart.php';
include_once 'inc/cart/lp-cart-functions.php';
// Block Templates
include_once 'inc/block-template/class-abstract-block-template.php';
include_once 'inc/block-template/class-block-template-handle.php';
// API
include_once 'inc/abstracts/abstract-rest-api.php';
include_once 'inc/abstracts/abstract-rest-controller.php';
include_once 'inc/rest-api/class-lp-core-api.php';
include_once 'inc/rest-api/class-lp-admin-core-api.php';
/** Jwt */
include_once 'inc/jwt/class-jwt-auth.php';
LPRegisterWidget::instance();
include_once 'inc/class-lp-widget.php';
include_once 'inc/lp-widget-functions.php';
// TODO: update frontend editor before move to function include_files_admin.
include_once 'inc/admin/views/meta-boxes/class-lp-meta-box.php';
include_once 'inc/class-lp-page-controller.php';
include_once 'inc/gateways/class-lp-gateway-abstract.php';
include_once 'inc/gateways/class-lp-gateways.php';
new LP_Gateways();
}
/**
* Include file run on backend
*/
private function include_files_admin() {
if ( ! is_admin() ) {
return;
}
include_once 'inc/admin/class-lp-admin-ajax.php';
include_once 'inc/admin/class-lp-admin-notice.php';
// File handle install LP
include_once 'inc/class-lp-install.php';
// Meta box helper
include_once 'inc/admin/meta-box/class-lp-meta-box-helper.php';
include_once 'inc/admin/class-lp-admin.php';
// include_once 'inc/admin/settings/abstract-settings-page.php';
}
/**
* Include file run on frontend
*/
private function include_files_frontend() {
if ( is_admin() ) {
return;
}
include_once 'inc/class-lp-assets.php';
include_once 'inc/course/class-model-user-can-view-course-item.php';
include_once 'inc/class-lp-ajax.php';
include_once 'inc/class-lp-session-handler.php';
}
/**
* Initial common hooks
*/
public function init_hooks() {
// Add links setting|document|addon on plugins page.
add_filter( 'plugin_action_links_' . LP_PLUGIN_BASENAME, array( $this, 'plugin_links' ) );
register_activation_hook( LP_PLUGIN_FILE, array( $this, 'on_activate' ) );
register_deactivation_hook( LP_PLUGIN_FILE, array( $this, 'on_deactivate' ) );
// add_action( 'deactivate_' . LP_PLUGIN_BASENAME, array( $this, 'on_deactivate' ) );
if ( ! LP_Install::instance()->tables_install_done() ) {
return;
}
//add_action( 'wp_loaded', array( $this, 'wp_loaded' ), 20 );
//add_action( 'after_setup_theme', array( $this, 'setup_theme' ) );
add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ), - 10 );
add_action(
'plugin_loaded',
function ( $plugin ) {
// For check wp_remote call normally of WP
if ( ! empty( LP_Request::get_param( 'lp_test_wp_remote' ) ) ) {
echo '[TEST_REMOTE]';
die;
}
}
);
// Check require version thim-core on Backend.
if ( is_admin() ) {
add_action( 'before_thim_core_init', array( $this, 'check_thim_core_version_require' ) );
}
// Save key purchase addon when install via file download from Thimpress.
add_action(
'upgrader_process_complete',
function ( $plugin_upgrader ) {
if ( ! empty( $plugin_upgrader->result ) ) {
$res = $plugin_upgrader->result;
$path_source = $res['destination'] ?? '';
if ( empty( $path_source ) ) {
return;
}
$key_purchase_path = realpath( $path_source . '/purchase-code.txt' );
if ( file_exists( $key_purchase_path ) ) {
$purchase_code_content = file_get_contents( $key_purchase_path );
if ( empty( $purchase_code_content ) ) {
return;
}
$addon_slug = $res['destination_name'] ?? '';
if ( empty( $addon_slug ) ) {
return;
}
// Call active purchase code for site.
LP_Manager_Addons::instance()->active_site( $addon_slug, $purchase_code_content );
}
}
}
);
}
/**
* Add links to Documentation and Extensions in plugin's list of action links
*
* @param array $links Array of action links
*
* @return array
* @since 4.3.11
*
*/
public function plugin_links( array $links ): array {
$links[] = sprintf( '<a href="%s">%s</a>', admin_url( 'admin.php?page=learn-press-settings' ), __( 'Settings', 'learnpress' ) );
$links[] = sprintf( '<a href="%s" target="_blank">%s</a>', 'https://docspress.thimpress.com/learnpress-4-0/', __( 'Documentation', 'learnpress' ) );
$links[] = sprintf( '<a href="%s" target="_blank">%s</a>', get_admin_url() . '/admin.php?page=learn-press-addons', __( 'Add-ons', 'learnpress' ) );
return $links;
}
/**
* Trigger this function while activating Learnpress.
*
* @since 3.0.0
* @version 4.1.4.1
*/
public function on_activate() {
LP_Install::instance()->on_activate();
}
/**
* Trigger this function while deactivating Learnpress.
*
* $since 3.0.0
*
* @hook learn_press_deactivate
*/
public function on_deactivate() {
do_action( 'learn-press/deactivate', $this );
}
/**
* Trigger WP loaded actions.
*
* @since 3.0.0
* @deprecated 4.2.2
*/
public function wp_loaded() {
_deprecated_function( __METHOD__, '4.2.2' );
if ( $this->is_request( 'frontend' ) ) {
$this->gateways = LP_Gateways::instance()->get_available_payment_gateways();
}
}
/**
* Setup courses thumbnail.
*
* @since 3.0.0
*/
public function setup_theme() {
if ( ! current_theme_supports( 'post-thumbnails' ) ) {
add_theme_support( 'post-thumbnails' );
}
add_post_type_support( LP_COURSE_CPT, 'thumbnail', 'author' );
$size = LP_Settings::get_option(
'course_thumbnail_dimensions',
array(
500,
300,
)
);
$size = array_values( (array) $size );
add_image_size( 'course_thumbnail', $size[0], $size[1], true );
}
/**
* Trigger Learnpress loaded actions.
*
* @since 3.0.0
* @version 1.0.3
*/
public function plugins_loaded() {
try {
do_action( 'learnpress/hook/before-addons-call-hook-learnpress-ready' );
// Polylang
if ( defined( 'POLYLANG_VERSION' ) ) {
include_once 'inc/ExternalPlugin/Polylang/class-lp-polylang.php';
LP_Polylang::instance();
}
// For plugin Elementor
if ( defined( 'ELEMENTOR_VERSION' ) ) {
LPElementor::instance();
}
// For plugin Elementor
if ( defined( 'WPSEO_FILE' ) ) {
LPYoastSeo::instance();
}
$this->init();
include_once 'inc/lp-template-hooks.php';
/**
* Check version addons valid version require.
* If not valid will be to deactivate.
* Reload page, so not affect to hook "learn-press/ready"
*/
$addons_valid = true;
$plugins = get_option( 'active_plugins' );
$list_lp_addon_activated = preg_grep( '/^learnpress-.*/i', $plugins );
// Remove hook deactivate addon assignments v3.
add_action(
'deactivate_learnpress-assignments/learnpress-assignments.php',
array( $this, 'lp_assignment_install' ),
- 10
);
foreach ( $list_lp_addon_activated as $lp_addon ) {
$lp_addon_info = get_file_data(
WP_PLUGIN_DIR . '/' . $lp_addon,
array(
'Require_LP_Version' => 'Require_LP_Version',
'Version' => 'Version',
)
);
// $lp_addon_info = get_plugin_data( WP_PLUGIN_DIR . '/' . $lp_addon );
$lp_addon_version = $lp_addon_info['Version'];
$addon = new Lp_Addon();
$addon->version = $lp_addon_version;
$addon->plugin_base = $lp_addon;
$addon->require_version = $lp_addon_info['Require_LP_Version'];
$addon_valid = $addon->check_require_version_addon();
if ( $addons_valid ) {
$addon_valid = $addon->check_require_version_lp();
}
if ( ! $addon_valid ) {
$addons_valid = false;
}
}
// End check addons valid.
if ( ! $addons_valid ) {
return;
}
// let third parties know that we're ready .
do_action( 'learn-press/ready' );
} catch ( Throwable $e ) {
error_log( __METHOD__ . ': ' . $e->getMessage() );
}
}
/**
* Remove hook deactivate addon assignments v3.
*/
public function lp_assignment_install() {
remove_action( 'deactivate_learnpress-assignments/learnpress-assignments.php', 'lp_assignment_remove' );
}
/**
* Get instance of class LP_Template.
*
* @param string $type
*
* @return LP_Template_Course|LP_Template_Profile|LP_Template_General|LP_Abstract_Template|LP_Template
*
* @throws Exception
* @since 3.3.0
*/
public function template( $type = '' ) {
$this->template = LP_Template::instance();
$templates = (array) $this->template->get_templates();
return $templates[ $type ] ?? $this->template;
}
/**
* Init LearnPress when WP initialises
*/
public function init() {
$this->api = new LP_Core_API();
$this->admin_api = new LP_Admin_Core_API();
$this->get_session();
$this->settings = $this->settings();
if ( $this->is_request( 'frontend' ) ) {
$this->get_cart();
}
// Email hook notify
include_once 'inc/emails/class-lp-email-hooks.php';
// Init emails
LP_Emails::instance();
}
/**
* Get session object instance.
*
* @return mixed
*/
public function get_session() {
if ( ! $this->session ) {
$this->session = LP_Session_Handler::instance();
}
return $this->session;
}
/**
* Get settings object instance.
*
* @return bool|LP_Settings
*/
public function settings() {
return LP_Settings::instance();
}
/**
* Get cart object instance for online learning market.
*
* @return LP_Cart
*/
public function get_cart(): LP_Cart {
if ( ! $this->cart ) {
$this->cart = LP_Cart::instance();
}
return $this->cart;
}
/**
* Check type of request.
*
* @param string $type ajax, frontend or admin.
*
* @return bool
*/
public function is_request( $type ) {
switch ( $type ) {
case 'admin':
return is_admin();
case 'ajax':
return defined( 'LP_DOING_AJAX' );
case 'cron':
return defined( 'DOING_CRON' );
case 'frontend':
return ( ! is_admin() || defined( 'LP_DOING_AJAX' ) ) && ! defined( 'DOING_CRON' );
default:
return strtolower( $_SERVER['REQUEST_METHOD'] ) == $type;
}
}
/**
* Get the plugin url.
*
* @param string $sub_dir
*
* @return string
*/
public function plugin_url( $sub_dir = '' ) {
return LP_PLUGIN_URL . ( $sub_dir ? "{$sub_dir}" : '' );
}
/**
* Get the plugin path.
*
* @param string $sub_dir
*
* @return string
*/
public function plugin_path( $sub_dir = '' ) {
return LP_PLUGIN_PATH . ( $sub_dir ? "{$sub_dir}" : '' );
}
/**
* Get checkout object instance
*
* @return LP_Checkout
*/
public function checkout() {
return LP_Checkout::instance();
}
/**
* Short way to return image file is located in LearnPress directory.
*
* @param string
*
* @return string
*/
public function image( $file ) {
if ( ! preg_match( '/.(jpg|png)$/', $file ) ) {
$file .= '.jpg';
}
return $this->plugin_url( "assets/images/{$file}" );
}
/**
* Check require version thim-core
*/
public function check_thim_core_version_require() {
// Get thim-core info for LP check .
include_once ABSPATH . 'wp-admin/includes/plugin.php';
$thim_core_info = get_file_data(
WP_PLUGIN_DIR . '/thim-core/thim-core.php',
array(
'Name' => 'Plugin Name',
'Require_LP_Version' => 'Require_LP_Version',
'Version' => 'Version',
)
);
if ( version_compare( $this->thim_core_version_require, $thim_core_info['Version'], '>' ) ) {
deactivate_plugins( 'thim-core/thim-core.php' );
if ( isset( $_GET['activate'] ) ) {
unset( $_GET['activate'] );
}
$message = sprintf(
'%s %s You can download %s. Read guide on %s',
'LP4 require version Thim-core:',
$this->thim_core_version_require,
'<a href="https://thimpresswp.github.io/thim-core/thim-core.zip">latest version</a>',
'<a href="https://docspress.thimpress.com/upgrade-database-how-to-fix-some-issue/">here</a>'
);
?>
<div class="notice notice-error">
<p><?php echo wp_kses_post( $message ); ?></p>
</div>
<?php
die;
}
}
/**
* Main plugin instance.
*
* @return LearnPress
*/
public static function instance() {
if ( is_null( self::$_instance ) ) {
self::$_instance = new self();
}
return self::$_instance;
}
}
}
/**
* Short way to load main instance of plugin
*
* @return LearnPress
* @since 1.0
* @author thimpress
*/
function LP() {
return LearnPress::instance();
}
/**
* Done! entry point of the plugin
* Create new instance of LearnPress and put it to global
*/
$GLOBALS['LearnPress'] = LearnPress::instance();