LearnPress – WordPress LMS Plugin - Version 3.0.9

Version Description

  • GDPR compliance ~ Improved Start quiz button ~ Load js for comment-reply if it does not load by default ~ Fixed missing param when sending email for user who finished course
Download this release

Release Info

Developer tunnhn
Plugin Icon 128x128 LearnPress – WordPress LMS Plugin
Version 3.0.9
Comparing to
See all releases

Code changes from version 3.0.8 to 3.0.9

Files changed (48) hide show
  1. assets/css/admin/admin.css +11 -0
  2. assets/js/admin/course-editor.js +0 -1
  3. assets/js/global.js +65 -11
  4. assets/scss/admin/_admin-editor.scss +18 -0
  5. inc/admin/class-lp-plugin-install-list-table.php +1 -1
  6. inc/admin/lp-admin-actions.php +1 -1
  7. inc/class-lp-assets.php +10 -4
  8. inc/class-lp-gdpr.php +557 -0
  9. inc/class-lp-hard-cache.php +1 -1
  10. inc/class-lp-helper.php +35 -0
  11. inc/class-lp-install.php +1 -1
  12. inc/class-lp-session-handler.php +2 -2
  13. inc/class-lp-settings.php +6 -6
  14. inc/course/abstract-course.php +17 -0
  15. inc/course/class-lp-course-item.php +22 -2
  16. inc/course/lp-course-functions.php +1 -1
  17. inc/curds/class-lp-course-curd.php +20 -0
  18. inc/curds/class-lp-order-curd.php +1 -1
  19. inc/curds/class-lp-question-curd.php +2 -2
  20. inc/curds/class-lp-user-curd.php +5 -7
  21. inc/curds/class-lp-user-item-curd.php +5 -2
  22. inc/custom-post-types/course.php +19 -7
  23. inc/custom-post-types/lesson.php +0 -17
  24. inc/emails/_bk/class-lp-email-finished-course-admin.php +199 -0
  25. inc/emails/_bk/class-lp-email-finished-course-instructor.php +201 -0
  26. inc/emails/_bk/class-lp-email-finished-course-user.php +201 -0
  27. inc/emails/types/class-lp-email-type-finished-course.php +1 -0
  28. inc/gateways/paypal/class-lp-gateway-paypal.php +1 -1
  29. inc/libraries/meta-box/css/image-advanced.css +52 -0
  30. inc/libraries/meta-box/img/loader.gif +0 -0
  31. inc/libraries/meta-box/inc/fields/thickbox-image.php +80 -0
  32. inc/libraries/meta-box/js/thickbox-image.js +34 -0
  33. inc/libraries/wp-background-process.php +1 -1
  34. inc/lp-constants.php +1 -1
  35. inc/lp-core-functions.php +1 -1
  36. inc/lp-template-functions.php +68 -18
  37. inc/order/class-lp-order.php +1 -1
  38. inc/updates/_update-from-0.9.php +2 -2
  39. inc/user-item/class-lp-user-item-course.php +2 -2
  40. inc/user-item/class-lp-user-item.php +1 -25
  41. inc/user/abstract-lp-user.php +58 -141
  42. inc/user/class-lp-profile.php +3 -1
  43. learnpress.php +5 -3
  44. readme.txt +7 -1
  45. templates/content-lesson/block-content.php +17 -0
  46. templates/content-quiz/buttons/start.php +8 -8
  47. templates/profile/content.php +1 -0
  48. templates/single-course/content-item.php +7 -11
assets/css/admin/admin.css CHANGED
@@ -2226,6 +2226,17 @@
2226
display: block;
2227
border-color: #bdf4fe !important; }
2228
2229
.section-item-counts {
2230
position: absolute;
2231
top: 0;
2226
display: block;
2227
border-color: #bdf4fe !important; }
2228
2229
+ .wp-admin.post-type-lp_course #meta-box-tab-course_payment .learn-press-tip-floating {
2230
+ top: 40px;
2231
+ left: 100px;
2232
+ background: #a00;
2233
+ opacity: 0.8; }
2234
+ .wp-admin.post-type-lp_course #meta-box-tab-course_payment .learn-press-tip-floating::before {
2235
+ top: -7px;
2236
+ border: 7px solid transparent;
2237
+ border-bottom-color: #a00;
2238
+ border-top-width: 0; }
2239
+
2240
.section-item-counts {
2241
position: absolute;
2242
top: 0;
assets/js/admin/course-editor.js CHANGED
@@ -857,7 +857,6 @@ jQuery(function ($) {
857
*/
858
(function ($, Vue, $store) {
859
$(document).ready(function () {
860
- console.log($('#admin-editor-lp_course'))
861
window.LP_Course_Editor = new Vue({
862
el: '#admin-editor-lp_course',
863
template: '<lp-course-editor></lp-course-editor>'
857
*/
858
(function ($, Vue, $store) {
859
$(document).ready(function () {
860
window.LP_Course_Editor = new Vue({
861
el: '#admin-editor-lp_course',
862
template: '<lp-course-editor></lp-course-editor>'
assets/js/global.js CHANGED
@@ -296,7 +296,7 @@ if (typeof window.LP === 'undefined') {
296
quickConfirm: function (elem, args) {
297
var $e = $(elem);
298
$('[learn-press-quick-confirm]').each(function () {
299
- ( $ins = $(this).data('quick-confirm') ) && ( console.log($ins), $ins.destroy() );
300
});
301
!$e.attr('learn-press-quick-confirm') && $e.attr('learn-press-quick-confirm', 'true').data('quick-confirm',
302
new (function (elem, args) {
@@ -355,7 +355,7 @@ if (typeof window.LP === 'undefined') {
355
});
356
//$div.parent().css('position', 'relative');
357
$div.css({
358
- left: ( ( offset.left + $elem.outerWidth() ) - $div.outerWidth() ) + args.offset.left,
359
top: offset.top + $elem.outerHeight() + args.offset.top + 5
360
}).hide().fadeIn('fast');
361
start();
@@ -415,7 +415,7 @@ if (typeof window.LP === 'undefined') {
415
},
416
blockUI: function (message) {
417
418
- message = (message !== false ? ( message ? message : 'Wait a moment' ) : '') + '<div class="message-box-animation"></div>';
419
this.show(message);
420
},
421
hide: function (delay, instance) {
@@ -462,7 +462,7 @@ if (typeof window.LP === 'undefined') {
462
$content.css("height", "").css('overflow', '');
463
}
464
$wrap.css({
465
- marginTop: ( $(window).height() - height ) / 2
466
});
467
LP.Hook.doAction('learn_press_message_box_resize', height, that);
468
};
@@ -520,7 +520,7 @@ if (typeof window.LP === 'undefined') {
520
},
521
_createButton: function (title, type) {
522
var $button = $('<button type="button" class="button message-box-button message-box-button-' + type + '">' + title + '</button>'),
523
- callback = 'on' + ( type.substr(0, 1).toUpperCase() + type.substr(1) );
524
$button.data('callback', callback).click(function () {
525
var instance = $(this).data('instance'),
526
callback = instance.events[$(this).data('callback')];
@@ -684,7 +684,7 @@ if (typeof window.LP === 'undefined') {
684
dataType = args.dataType || 'json',
685
data = args.action ? $.extend(args.data, {'lp-ajax': args.action}) : args.data,
686
beforeSend = args.beforeSend || function () {
687
- },
688
url = args.url || window.location.href;
689
// console.debug( beforeSend );
690
$.ajax({
@@ -705,12 +705,12 @@ if (typeof window.LP === 'undefined') {
705
doAjax: function (args) {
706
var type = args.type || 'post',
707
dataType = args.dataType || 'json',
708
- action = ( ( args.prefix === undefined ) || 'learnpress_') + args.action,
709
data = args.action ? $.extend(args.data, {action: action}) : args.data;
710
711
$.ajax({
712
data: data,
713
- url: ( args.url || window.location.href ),
714
type: type,
715
dataType: 'html',
716
success: function (raw) {
@@ -815,7 +815,7 @@ if (typeof window.LP === 'undefined') {
815
}
816
if (reqWidth > seed.length) { // so short we pad
817
return new Array(1 + (reqWidth - seed.length))
818
- .join('0') + seed;
819
}
820
return seed;
821
};
@@ -832,7 +832,7 @@ if (typeof window.LP === 'undefined') {
832
833
retId = prefix; // start with prefix, add current milliseconds hex string
834
retId += formatSeed(parseInt(new Date()
835
- .getTime() / 1000, 10), 8);
836
retId += formatSeed(this.php_js.uniqidSeed, 5); // add seed hex string
837
if (more_entropy) {
838
// for more entropy we add a float lower to 10
@@ -1204,6 +1204,8 @@ if (typeof window.LP === 'undefined') {
1204
if (typeof $.alerts !== 'undefined') {
1205
$.alerts.overlayColor = '#000';
1206
$.alerts.overlayOpacity = 0.5;
1207
}
1208
1209
$('.learn-press-message.fixed').each(function () {
@@ -1218,12 +1220,64 @@ if (typeof window.LP === 'undefined') {
1218
if (options.delayOut) {
1219
setTimeout(function () {
1220
$el.fadeOut();
1221
- }, options.delayOut + ( options.delayIn || 0));
1222
}
1223
})($el, options);
1224
1225
});
1226
1227
$('body')
1228
.on('click', '.learn-press-nav-tabs li a', function (e) {
1229
e.preventDefault();
296
quickConfirm: function (elem, args) {
297
var $e = $(elem);
298
$('[learn-press-quick-confirm]').each(function () {
299
+ ($ins = $(this).data('quick-confirm')) && (console.log($ins), $ins.destroy());
300
});
301
!$e.attr('learn-press-quick-confirm') && $e.attr('learn-press-quick-confirm', 'true').data('quick-confirm',
302
new (function (elem, args) {
355
});
356
//$div.parent().css('position', 'relative');
357
$div.css({
358
+ left: ((offset.left + $elem.outerWidth()) - $div.outerWidth()) + args.offset.left,
359
top: offset.top + $elem.outerHeight() + args.offset.top + 5
360
}).hide().fadeIn('fast');
361
start();
415
},
416
blockUI: function (message) {
417
418
+ message = (message !== false ? (message ? message : 'Wait a moment') : '') + '<div class="message-box-animation"></div>';
419
this.show(message);
420
},
421
hide: function (delay, instance) {
462
$content.css("height", "").css('overflow', '');
463
}
464
$wrap.css({
465
+ marginTop: ($(window).height() - height) / 2
466
});
467
LP.Hook.doAction('learn_press_message_box_resize', height, that);
468
};
520
},
521
_createButton: function (title, type) {
522
var $button = $('<button type="button" class="button message-box-button message-box-button-' + type + '">' + title + '</button>'),
523
+ callback = 'on' + (type.substr(0, 1).toUpperCase() + type.substr(1));
524
$button.data('callback', callback).click(function () {
525
var instance = $(this).data('instance'),
526
callback = instance.events[$(this).data('callback')];
684
dataType = args.dataType || 'json',
685
data = args.action ? $.extend(args.data, {'lp-ajax': args.action}) : args.data,
686
beforeSend = args.beforeSend || function () {
687
+ },
688
url = args.url || window.location.href;
689
// console.debug( beforeSend );
690
$.ajax({
705
doAjax: function (args) {
706
var type = args.type || 'post',
707
dataType = args.dataType || 'json',
708
+ action = ((args.prefix === undefined) || 'learnpress_') + args.action,
709
data = args.action ? $.extend(args.data, {action: action}) : args.data;
710
711
$.ajax({
712
data: data,
713
+ url: (args.url || window.location.href),
714
type: type,
715
dataType: 'html',
716
success: function (raw) {
815
}
816
if (reqWidth > seed.length) { // so short we pad
817
return new Array(1 + (reqWidth - seed.length))
818
+ .join('0') + seed;
819
}
820
return seed;
821
};
832
833
retId = prefix; // start with prefix, add current milliseconds hex string
834
retId += formatSeed(parseInt(new Date()
835
+ .getTime() / 1000, 10), 8);
836
retId += formatSeed(this.php_js.uniqidSeed, 5); // add seed hex string
837
if (more_entropy) {
838
// for more entropy we add a float lower to 10
1204
if (typeof $.alerts !== 'undefined') {
1205
$.alerts.overlayColor = '#000';
1206
$.alerts.overlayOpacity = 0.5;
1207
+ $.alerts.okButton = lpGlobalSettings.localize.button_ok;
1208
+ $.alerts.cancelButton = lpGlobalSettings.localize.button_cancel;
1209
}
1210
1211
$('.learn-press-message.fixed').each(function () {
1220
if (options.delayOut) {
1221
setTimeout(function () {
1222
$el.fadeOut();
1223
+ }, options.delayOut + (options.delayIn || 0));
1224
}
1225
})($el, options);
1226
1227
});
1228
1229
+
1230
+ $(document).on('input', '#meta-box-tab-course_payment', function (e) {
1231
+ var _self = $(this),
1232
+ _price = $('#_lp_price'),
1233
+ _sale_price = $('#_lp_sale_price'),
1234
+ _target = $(e.target).attr('id');
1235
+ _self.find('#field-_lp_price div, #field-_lp_sale_price div').remove('.learn-press-tip-floating');
1236
+ if (parseInt(_sale_price.val()) >= parseInt(_price.val())) {
1237
+ if (_target === '_lp_price') {
1238
+ _price.parent('.rwmb-input').append('<div class="learn-press-tip-floating">' + lpAdminCourseEditorSettings.i18n.notice_price + '</div>');
1239
+ } else if (_target === '_lp_sale_price') {
1240
+ _sale_price.parent('.rwmb-input').append('<div class="learn-press-tip-floating">' + lpAdminCourseEditorSettings.i18n.notice_sale_price + '</div>');
1241
+ }
1242
+ }
1243
+ });
1244
+
1245
+ $(document).on('change', '#_lp_sale_start', function (e) {
1246
+ var _sale_start_date = $(this),
1247
+ _sale_end_date = $('#_lp_sale_end'),
1248
+ _start_date = Date.parse(_sale_start_date.val()),
1249
+ _end_date = Date.parse(_sale_end_date.val()),
1250
+ _parent_start = _sale_start_date.parent('.rwmb-input'),
1251
+ _parent_end = _sale_end_date.parent('.rwmb-input');
1252
+
1253
+ if (!_start_date) {
1254
+ _parent_start.append('<div class="learn-press-tip-floating">' + lpAdminCourseEditorSettings.i18n.notice_invalid_date + '</div>')
1255
+ }
1256
+
1257
+ $('#field-_lp_sale_start div, #field-_lp_sale_end div').remove('.learn-press-tip-floating');
1258
+ if (_start_date < _end_date) {
1259
+ _parent_start.append('<div class="learn-press-tip-floating">' + lpAdminCourseEditorSettings.i18n.notice_sale_start_date + '</div>')
1260
+ }
1261
+ });
1262
+
1263
+ $(document).on('change', '#_lp_sale_end', function (e) {
1264
+ var _sale_end_date = $(this),
1265
+ _sale_start_date = $('#_lp_sale_start'),
1266
+ _start_date = Date.parse(_sale_start_date.val()),
1267
+ _end_date = Date.parse(_sale_end_date.val()),
1268
+ _parent_start = _sale_start_date.parent('.rwmb-input'),
1269
+ _parent_end = _sale_end_date.parent('.rwmb-input');
1270
+
1271
+ if (!_end_date) {
1272
+ _parent_end.append('<div class="learn-press-tip-floating">' + lpAdminCourseEditorSettings.i18n.notice_invalid_date + '</div>')
1273
+ }
1274
+
1275
+ $('#field-_lp_sale_start div, #field-_lp_sale_end div').remove('.learn-press-tip-floating');
1276
+ if (_start_date < _end_date) {
1277
+ _parent_end.append('<div class="learn-press-tip-floating">' + lpAdminCourseEditorSettings.i18n.notice_sale_end_date + '</div>')
1278
+ }
1279
+ });
1280
+
1281
$('body')
1282
.on('click', '.learn-press-nav-tabs li a', function (e) {
1283
e.preventDefault();
assets/scss/admin/_admin-editor.scss CHANGED
@@ -625,6 +625,24 @@
625
}
626
}
627
628
.section-item-counts {
629
position: absolute;
630
top: 0;
625
}
626
}
627
628
+ .wp-admin.post-type-lp_course {
629
+ #meta-box-tab-course_payment {
630
+ .learn-press-tip-floating {
631
+ top: 40px;
632
+ left: 100px;
633
+ background: #a00;
634
+ opacity: 0.8;
635
+ &::before {
636
+ top: -7px;
637
+ border: 7px solid transparent;
638
+ border-bottom-color: #a00;;
639
+ border-top-width: 0;
640
+ }
641
+ }
642
+ }
643
+ }
644
+
645
+
646
.section-item-counts {
647
position: absolute;
648
top: 0;
inc/admin/class-lp-plugin-install-list-table.php CHANGED
@@ -77,7 +77,7 @@ class LP_Plugin_Install_List_Table extends WP_List_Table {
77
$cache = WP_CONTENT_DIR . '/upgrade/' . md5( serialize( $add_ons ) ) . '.cache';
78
$timeover = HOUR_IN_SECONDS * 24;
79
if( file_exists( $cache ) && ( time() - filemtime( $cache ) ) < $timeover ){
80
- $items = maybe_unserialize( file_get_contents( $cache ) );
81
}else {
82
$repo_url = 'http://thimpress.com/lprepo/';
83
77
$cache = WP_CONTENT_DIR . '/upgrade/' . md5( serialize( $add_ons ) ) . '.cache';
78
$timeover = HOUR_IN_SECONDS * 24;
79
if( file_exists( $cache ) && ( time() - filemtime( $cache ) ) < $timeover ){
80
+ $items = LP_Helper::maybe_unserialize( file_get_contents( $cache ) );
81
}else {
82
$repo_url = 'http://thimpress.com/lprepo/';
83
inc/admin/lp-admin-actions.php CHANGED
@@ -18,7 +18,7 @@ function _learn_press_set_user_items( $query ) {
18
if ( current_user_can( 'manage_options' ) || ! current_user_can( LP_TEACHER_ROLE ) || ! is_admin() || ( $pagenow != 'edit.php' ) ) {
19
return $query;
20
}
21
- if ( ! in_array( $post_type, apply_filters( 'lear-press/filter-user-access-types', array(
22
LP_COURSE_CPT,
23
LP_LESSON_CPT,
24
LP_QUIZ_CPT,
18
if ( current_user_can( 'manage_options' ) || ! current_user_can( LP_TEACHER_ROLE ) || ! is_admin() || ( $pagenow != 'edit.php' ) ) {
19
return $query;
20
}
21
+ if ( ! in_array( $post_type, apply_filters( 'learn-press/filter-user-access-types', array(
22
LP_COURSE_CPT,
23
LP_LESSON_CPT,
24
LP_QUIZ_CPT,
inc/class-lp-assets.php CHANGED
@@ -40,10 +40,16 @@ class LP_Assets extends LP_Abstract_Assets {
40
public function _get_script_data() {
41
return array(
42
'global' => array(
43
- 'url' => learn_press_get_current_url(),
44
- 'siteurl' => site_url(),
45
- 'ajax' => admin_url( 'admin-ajax.php' ),
46
- 'theme' => get_stylesheet()
47
),
48
'checkout' => array(
49
'ajaxurl' => site_url(),
40
public function _get_script_data() {
41
return array(
42
'global' => array(
43
+ 'url' => learn_press_get_current_url(),
44
+ 'siteurl' => site_url(),
45
+ 'ajax' => admin_url( 'admin-ajax.php' ),
46
+ 'theme' => get_stylesheet(),
47
+ 'localize' => array(
48
+ 'button_ok' => __( 'OK', 'learnpress' ),
49
+ 'button_cancel' => __( 'Cancel', 'learnpress' ),
50
+ 'button_yes' => __( 'Yes', 'learnpress' ),
51
+ 'button_no' => __( 'No', 'learnpress' )
52
+ )
53
),
54
'checkout' => array(
55
'ajaxurl' => site_url(),
inc/class-lp-gdpr.php ADDED
@@ -0,0 +1,557 @@
1
+ <?php
2
+
3
+ /**
4
+ * Class LP_GDPR
5
+ *
6
+ * Personal data export and removal for LearnPress
7
+ *
8
+ * @since 4.9.6
9
+ */
10
+ class LP_GDPR {
11
+
12
+ /**
13
+ * LP_GDPR constructor.
14
+ */
15
+ public function __construct() {
16
+ // Filter to wp privacy personal data exporter
17
+ add_filter(
18
+ 'wp_privacy_personal_data_exporters',
19
+ array( $this, 'register_exporter' ),
20
+ 10
21
+ );
22
+
23
+ add_filter(
24
+ 'wp_privacy_personal_data_erasers',
25
+ array( $this, 'register_data_eraser' )
26
+ );
27
+ }
28
+
29
+ public function register_data_eraser( $erasers ) {
30
+ $erasers['learnpress'] = array(
31
+ 'eraser_friendly_name' => __( 'LearnPress' ),
32
+ 'callback' => array( $this, 'personal_data_eraser' ),
33
+ );
34
+
35
+ return $erasers;
36
+ }
37
+
38
+ /**
39
+ * @param array $exporters
40
+ *
41
+ * @return mixed
42
+ */
43
+ public function register_exporter( $exporters ) {
44
+
45
+ /**
46
+ * Owned courses
47
+ */
48
+ $exporters['learnpress-owned-courses'] = array(
49
+ 'exporter_friendly_name' => __( 'LearnPress Owned Courses', 'learnpress' ),
50
+ 'callback' => array( $this, 'user_owned_courses' ),
51
+ );
52
+
53
+ /**
54
+ * Orders
55
+ */
56
+ $exporters['learnpress-orders'] = array(
57
+ 'exporter_friendly_name' => __( 'LearnPress Orders', 'learnpress' ),
58
+ 'callback' => array( $this, 'user_orders' ),
59
+ );
60
+
61
+ /**
62
+ * Purchased courses
63
+ */
64
+ $exporters['learnpress-purchased-courses'] = array(
65
+ 'exporter_friendly_name' => __( 'LearnPress Purchased Courses', 'learnpress' ),
66
+ 'callback' => array( $this, 'user_purchased_courses' ),
67
+ );
68
+
69
+ /**
70
+ * Profile
71
+ */
72
+ $exporters['learnpress-profile'] = array(
73
+ 'exporter_friendly_name' => __( 'LearnPress User Profile', 'learnpress' ),
74
+ 'callback' => array( $this, 'user_profile' ),
75
+ );
76
+
77
+ return $exporters;
78
+ }
79
+
80
+ public function user_profile( $email_address, $page ) {
81
+ $export_data = array(
82
+ 'data' => array(),
83
+ 'done' => true
84
+ );
85
+
86
+ if ( ! $wp_user = get_user_by( 'email', $email_address ) ) {
87
+ return $export_data;
88
+ }
89
+
90
+ $user = learn_press_get_user( $wp_user->ID );
91
+ $profile = LP_Profile::instance( $wp_user->ID );
92
+ $export_items = array();
93
+
94
+ if ( $user = $profile->get_user() ) {
95
+ if ( $publicity = $user->get_data( 'profile_publicity' ) ) {
96
+ $export_item = array(
97
+ 'group_id' => 'lp-profile',
98
+ 'group_label' => __( 'Profile Settings', 'learnpress' ),
99
+ 'item_id' => "profile-" . $wp_user->ID,
100
+ 'data' => array()
101
+ );
102
+ foreach ( $publicity as $key => $item ) {
103
+ $export_item['data'][] = array(
104
+ 'name' => $key,
105
+ 'value' => $item
106
+ );
107
+ }
108
+ $export_items[] = $export_item;
109
+ }
110
+ }
111
+
112
+ $export_data['data'] = $export_items;
113
+
114
+ return $export_data;
115
+ }
116
+
117
+ public function user_orders( $email_address, $page ) {
118
+ $number = 10; // Limit us to avoid timing out
119
+ $page = (int) $page;
120
+ $export_data = array(
121
+ 'data' => array(),
122
+ 'done' => true
123
+ );
124
+
125
+ if ( ! $wp_user = get_user_by( 'email', $email_address ) ) {
126
+ return $export_data;
127
+ }
128
+
129
+ $profile = LP_Profile::instance( $wp_user->ID );
130
+
131
+ if ( ! $query_orders = $profile->query_orders( array( 'paged' => $page, 'limit' => $number ) ) ) {
132
+ return $export_data;
133
+ }
134
+
135
+ if ( ! $orders = $query_orders->get_items() ) {
136
+ return $export_data;
137
+ }
138
+
139
+ $export_items = array();
140
+ foreach ( $orders as $order ) {
141
+ if ( ! $order instanceof LP_Order ) {
142
+ $order = learn_press_get_order( $order );
143
+ }
144
+
145
+ $data = array(
146
+ array(
147
+ 'name' => __( 'Order ID', 'learnpress' ),
148
+ 'value' => $order->get_order_number()
149
+ ),
150
+ array(
151
+ 'name' => __( 'Order Date', 'learnpress' ),
152
+ 'value' => $order->get_order_date()
153
+ ),
154
+ array(
155
+ 'name' => __( 'Order status', 'learnpress' ),
156
+ 'value' => $order->get_order_status()
157
+ ),
158
+ array(
159
+ 'name' => __( 'Order Total', 'learnpress' ),
160
+ 'value' => $order->get_formatted_order_total()
161
+ )
162
+ );
163
+ $export_items[] = array(
164
+ 'group_id' => 'lp-order',
165
+ 'group_label' => __( 'Orders', 'learnpress' ),
166
+ 'item_id' => "order-{$order->get_id()}",
167
+ 'data' => $data
168
+ );
169
+ }
170
+
171
+ $done = count( $orders ) < $number;
172
+ $export_data['done'] = $done;
173
+ $export_data['data'] = $export_items;
174
+
175
+ return $export_data;
176
+ }
177
+
178
+ /**
179
+ * Course list
180
+ *
181
+ * @param string $email_address
182
+ * @param int $page
183
+ *
184
+ * @return array
185
+ */
186
+ public function user_owned_courses( $email_address, $page ) {
187
+
188
+ $number = 10; // Limit us to avoid timing out
189
+ $page = (int) $page;
190
+ $export_items = array();
191
+
192
+ $query = $this->get_courses_by_email( 'own', $email_address, array(
193
+ 'paged' => $page,
194
+ 'limit' => $number,
195
+ 'status' => '*'
196
+ ) );
197
+
198
+ if ( ! $query ) {
199
+ return array(
200
+ 'data' => array(),
201
+ 'done' => true
202
+ );
203
+ }
204
+
205
+ if ( $courses = (array) $query->get_items() ) {
206
+ foreach ( $courses as $course_id ) {
207
+ if ( ! $course = learn_press_get_course( $course_id ) ) {
208
+ continue;
209
+ }
210
+
211
+ $data = array(
212
+ array(
213
+ 'name' => __( 'Course Author', 'learnpress' ),
214
+ 'value' => $course->get_author_display_name()
215
+ ),
216
+ array(
217
+ 'name' => __( 'Course Name', 'learnpress' ),
218
+ 'value' => $course->get_title()
219
+ ),
220
+ array(
221
+ 'name' => __( 'Course Date', 'learnpress' ),
222
+ 'value' => get_post_field( 'post_date', $course_id )
223
+ ),
224
+ array(
225
+ 'name' => __( 'Course URL', 'learnpress' ),
226
+ 'value' => $course->get_permalink()
227
+ )
228
+ );
229
+ $export_items[] = array(
230
+ 'group_id' => 'lp-owned-course',
231
+ 'group_label' => __( 'Owned Course', 'learnpress' ),
232
+ 'item_id' => "course-{$course->get_id()}",
233
+ 'data' => $data
234
+ );
235
+
236
+ $this->_export_course_items( $export_items, $course_id );
237
+ }
238
+ }
239
+ $done = count( $courses ) < $number;
240
+
241
+ return array(
242
+ 'data' => $export_items,
243
+ 'done' => $done
244
+ );
245
+ }
246
+
247
+ /**
248
+ * @param array $export_items
249
+ */
250
+ protected function _export_course_items( &$export_items, $course_id ) {
251
+ global $post;
252
+ $post = get_post( $course_id );
253
+ setup_postdata( $post );
254
+ $course = learn_press_get_course( $course_id );
255
+
256
+ if ( ! $items = $course->get_items() ) {
257
+ return;
258
+ }
259
+
260
+ foreach ( $items as $item_id ) {
261
+ $item = $course->get_item( $item_id );
262
+ $export_item_data = array(
263
+ array(
264
+ 'name' => __( 'Item Name', 'learnpress' ),
265
+ 'value' => $item->get_title()
266
+ ),
267
+ array(
268
+ 'name' => __( 'Item Type', 'learnpress' ),
269
+ 'value' => $item->get_item_type( 'display' )
270
+ ),
271
+ array(
272
+ 'name' => __( 'Item URL', 'learnpress' ),
273
+ 'value' => $item->get_permalink()
274
+ )
275
+ );
276
+
277
+ $export_items[] = array(
278
+ 'group_id' => 'lp-owned-course-items-' . $course_id,
279
+ 'group_label' => __( 'Course Items', 'learnpress' ),
280
+ 'item_id' => "course-items-{$course_id}-{$item_id}",
281
+ 'data' => $export_item_data
282
+ );
283
+ }
284
+
285
+ wp_reset_postdata();
286
+ }
287
+
288
+ /**
289
+ * @param string $email_address
290
+ * @param string $page
291
+ *
292
+ * @return array
293
+ */
294
+ public function user_purchased_courses( $email_address, $page ) {
295
+
296
+ $number = 10; // Limit us to avoid timing out
297
+ $page = (int) $page;
298
+ $export_data = array(
299
+ 'data' => array(),
300
+ 'done' => true
301
+ );
302
+ if ( ! $wp_user = get_user_by( 'email', $email_address ) ) {
303
+ return $export_data;
304
+ }
305
+
306
+ $user = learn_press_get_user( $wp_user->ID );
307
+ $query = $this->get_courses_by_email( 'purchased', $email_address, array(
308
+ 'paged' => $page,
309
+ 'limit' => $number
310
+ ) );
311
+
312
+
313
+ if ( ! $query ) {
314
+ return $export_data;
315
+ }
316
+
317
+ $export_items = array();
318
+ if ( $courses = (array) $query->get_items() ) {
319
+
320
+ foreach ( $courses as $course_data ) {
321
+
322
+ $course = learn_press_get_course( $course_data->get_id() );
323
+ //if ( $course_data = $user->get_course_data( $course_id ) ) {
324
+ $enrolled_date = $course_data->get_start_time();
325
+ $finished_date = $course_data->get_end_time();
326
+ $status = $course_data->get_status();
327
+ $grade = $course_data->get_grade();
328
+ //}
329
+
330
+ $data = array(
331
+ array(
332
+ 'name' => __( 'Course Author', 'learnpress' ),
333
+ 'value' => $course->get_author_display_name()
334
+ ),
335
+ array(
336
+ 'name' => __( 'Course Name', 'learnpress' ),
337
+ 'value' => $course->get_title()
338
+ ),
339
+ array(
340
+ 'name' => __( 'Course Date', 'learnpress' ),
341
+ 'value' => get_post_field( 'post_date', $course_data->get_id() )
342
+ ),
343
+ array(
344
+ 'name' => __( 'Course URL', 'learnpress' ),
345
+ 'value' => $course->get_permalink()
346
+ ),
347
+ array(
348
+ 'name' => __( 'Enrolled Date', 'learnpress' ),
349
+ 'value' => $enrolled_date
350
+ ),
351
+ array(
352
+ 'name' => __( 'Finished Date', 'learnpress' ),
353
+ 'value' => $finished_date ? $finished_date : '-'
354
+ ),
355
+ array(
356
+ 'name' => __( 'Course Status', 'learnpress' ),
357
+ 'value' => $status
358
+ ),
359
+ array(
360
+ 'name' => __( 'Course Grade', 'learnpress' ),
361
+ 'value' => $status == 'finished' ? $grade : __( 'Ungraded', 'learnpress' )
362
+ )
363
+ );
364
+ $export_items[] = array(
365
+ 'group_id' => 'lp-purchased-course-' . $course_data->get_id(),
366
+ 'group_label' => __( 'Purchased Course', 'learnpress' ),
367
+ 'item_id' => "course-{$course_data->get_id()}",
368
+ 'data' => $data
369
+ );
370
+
371
+ $this->_export_purchased_course_items( $export_items, $course_data );
372
+ }
373
+ }
374
+
375
+ $done = count( $courses ) < $number;
376
+ $export_data['data'] = $export_items;
377
+ $export_data['done'] = $done;
378
+
379
+ return $export_data;
380
+ }
381
+
382
+ /**
383
+ * @param array $export_items
384
+ * @param LP_User_Item_Course $course_data
385
+ */
386
+ protected function _export_purchased_course_items( &$export_items, $course_data ) {
387
+ global $post;
388
+ $post = get_post( $course_data->get_id() );
389
+ setup_postdata( $post );
390
+ $course = learn_press_get_course( $course_data->get_id() );
391
+
392
+ if ( ! $items = $course_data->get_items() ) {
393
+ return;
394
+ }
395
+
396
+ foreach ( $items as $user_course_item ) {
397
+ $item = $course->get_item( $user_course_item->get_id() );
398
+ $export_item_data = array(
399
+ array(
400
+ 'name' => __( 'Item Name', 'learnpress' ),
401
+ 'value' => $item->get_title()
402
+ ),
403
+ array(
404
+ 'name' => __( 'Item Type', 'learnpress' ),
405
+ 'value' => $item->get_item_type( 'display' )
406
+ ),
407
+ array(
408
+ 'name' => __( 'Item URL', 'learnpress' ),
409
+ 'value' => $item->get_permalink()
410
+ )
411
+ );
412
+
413
+ if ( $item->get_item_type() == LP_QUIZ_CPT ) {
414
+ $export_item_data[] = array(
415
+ 'name' => __( 'Status', 'learnpress' ),
416
+ 'value' => $user_course_item->get_result() . '%'
417
+ );
418
+
419
+ $export_item_data[] = array(
420
+ 'name' => __( 'Grade', 'learnpress' ),
421
+ 'value' => $user_course_item->get_result( 'grade' )
422
+ );
423
+ } elseif ( $item->get_item_type() == LP_LESSON_CPT ) {
424
+ $export_item_data[] = array(
425
+ 'name' => __( 'Completed', 'learnpress' ),
426
+ 'value' => $user_course_item->get_status() === 'completed' ? __( 'Yes', 'learnpress' ) : __( 'No', 'learnpress' )
427
+ );
428
+ }
429
+
430
+ $export_items[] = array(
431
+ 'group_id' => 'lp-purchased-course-items-' . $course_data->get_id(),
432
+ 'group_label' => __( 'Course Items', 'learnpress' ),
433
+ 'item_id' => "course-{$course_data->get_id()}-{$user_course_item->get_id()}",
434
+ 'data' => $export_item_data
435
+ );
436
+ }
437
+
438
+ wp_reset_postdata();
439
+ }
440
+
441
+ /**
442
+ * Query all courses by user email
443
+ *
444
+ * @param string $type
445
+ * @param string $email
446
+ * @param array $args
447
+ *
448
+ * @return array|bool|LP_Query_List_Table
449
+ */
450
+ protected function get_courses_by_email( $type = 'own', $email, $args = array() ) {
451
+ if ( ! $user = get_user_by( 'email', $email ) ) {
452
+ return false;
453
+ }
454
+
455
+ $profile = LP_Profile::instance( $user->ID );
456
+
457
+ return $profile->query_courses(
458
+ $type,
459
+ $args
460
+ );
461
+ }
462
+
463
+ /**
464
+ * Eraser personal data
465
+ *
466
+ * @param string $email
467
+ * @param int $page
468
+ *
469
+ * @return array
470
+ */
471
+ public function personal_data_eraser( $email, $page ) {
472
+ $number = 500;
473
+ $page = (int) $page;
474
+
475
+ $eraser_data = array(
476
+ 'items_removed' => false,
477
+ 'items_retained' => false,
478
+ 'messages' => array(),
479
+ 'done' => 1,
480
+ );
481
+
482
+ if ( ! $wp_user = get_user_by( 'email', $email ) ) {
483
+ return $eraser_data;
484
+ }
485
+
486
+ $this->_eraser_orders( $wp_user->ID, $page );
487
+ $this->_eraser_user_items( $wp_user->ID, $page );
488
+ $this->_eraser_courses( $wp_user->ID, $page );
489
+
490
+ delete_user_meta( $wp_user->ID, '_lp_profile_publicity' );
491
+ $eraser_data['items_removed'] = true;
492
+
493
+ return $eraser_data;
494
+ }
495
+
496
+ /**
497
+ * Eraser orders
498
+ *
499
+ * @param int $user_id
500
+ * @param int $page
501
+ */
502
+ protected function _eraser_orders( $user_id, $page ) {
503
+
504
+ $curd = new LP_User_CURD();
505
+ $order_curd = new LP_Order_CURD();
506
+
507
+ if ( ! $orders = $curd->get_orders( $user_id, array( 'group_by_order' => true ) ) ) {
508
+ return;
509
+ }
510
+
511
+ foreach ( $orders as $order_id => $course_ids ) {
512
+ $order = learn_press_get_order( $order_id );
513
+ //$order_curd->delete_order_data( $order );
514
+ wp_delete_post( $order_id );
515
+ }
516
+
517
+ }
518
+
519
+ /**
520
+ * Eraser user items
521
+ *
522
+ * @param int $user_id
523
+ * @param int $page
524
+ */
525
+ protected function _eraser_user_items( $user_id, $page ) {
526
+ $curd = new LP_User_CURD();
527
+ $curd->delete_user_item( array( 'user_id' => $user_id ) );
528
+ }
529
+
530
+ /**
531
+ * Eraser courses
532
+ *
533
+ * @param int $user_id
534
+ * @param int $page
535
+ */
536
+ protected function _eraser_courses( $user_id, $page ) {
537
+
538
+ global $wpdb;
539
+ $query = $wpdb->prepare( "
540
+ SELECT *
541
+ FROM {$wpdb->posts}
542
+ WHERE post_author = %d
543
+ AND post_type = %s
544
+ ", $user_id, LP_COURSE_CPT );
545
+ if ( ! $post_ids = $wpdb->get_col( $query ) ) {
546
+ return;
547
+ }
548
+
549
+ $api = new LP_Course_CURD();
550
+ foreach ( $post_ids as $post_id ) {
551
+ $api->delete_course( $post_id, true );
552
+ }
553
+ }
554
+
555
+ }
556
+
557
+ return new LP_GDPR();
inc/class-lp-hard-cache.php CHANGED
@@ -132,7 +132,7 @@ class LP_Hard_Cache {
132
return false;
133
}
134
135
- return maybe_unserialize( $content );
136
}
137
138
return false;
132
return false;
133
}
134
135
+ return LP_Helper::maybe_unserialize( $content );
136
}
137
138
return false;
inc/class-lp-helper.php CHANGED
@@ -6,6 +6,41 @@
6
defined( 'ABSPATH' ) || exit;
7
8
class LP_Helper {
9
/**
10
* Shuffle array and keep the keys
11
*
6
defined( 'ABSPATH' ) || exit;
7
8
class LP_Helper {
9
+
10
+ /**
11
+ * Wrap function unserialize to fix issues with UTF-8 chars when encoding/decoding
12
+ * of serialize function.
13
+ *
14
+ * @param string $string
15
+ *
16
+ * @return mixed
17
+ */
18
+ public static function maybe_unserialize( $string ) {
19
+ if ( is_string( $string ) ) {
20
+
21
+ $unserialized = maybe_unserialize( $string );
22
+ if ( ! $unserialized && strlen( $string ) ) {
23
+ $string = preg_replace_callback(
24
+ '!s:(\d+):"(.*?)";!s',
25
+ array( __CLASS__, '_unserialize_replace_callback' ),
26
+ $string );
27
+
28
+ $unserialized = maybe_unserialize( $string );
29
+ }
30
+
31
+ $string = $unserialized;
32
+ }
33
+
34
+ return $string;
35
+ }
36
+
37
+ public static function _unserialize_replace_callback( $m ) {
38
+ $len = strlen( $m[2] );
39
+ $result = "s:$len:\"{$m[2]}\";";
40
+
41
+ return $result;
42
+ }
43
+
44
/**
45
* Shuffle array and keep the keys
46
*
inc/class-lp-install.php CHANGED
@@ -246,7 +246,7 @@ if ( ! function_exists( 'LP_Install' ) ) {
246
parse_str( $str, $options );
247
if ( $options ) {
248
foreach ( $options as $name => $value ) {
249
- $value = maybe_unserialize( $value );
250
update_option( $name, $value, 'yes' );
251
}
252
}
246
parse_str( $str, $options );
247
if ( $options ) {
248
foreach ( $options as $name => $value ) {
249
+ $value = LP_Helper::maybe_unserialize( $value );
250
update_option( $name, $value, 'yes' );
251
}
252
}
inc/class-lp-session-handler.php CHANGED
@@ -284,7 +284,7 @@ class LP_Session_Handler implements ArrayAccess {
284
wp_cache_add( $this->get_cache_prefix() . $customer_id, $value, LP_SESSION_CACHE_GROUP, $this->_session_expiration - time() );
285
}
286
287
- return maybe_unserialize( $value );
288
}
289
290
public function delete_session( $customer_id ) {
@@ -344,7 +344,7 @@ class LP_Session_Handler implements ArrayAccess {
344
public function get( $key, $default = null ) {
345
$key = sanitize_key( $key );
346
347
- return isset( $this->_data[ $key ] ) ? maybe_unserialize( $this->_data[ $key ] ) : $default;
348
}
349
350
/**
284
wp_cache_add( $this->get_cache_prefix() . $customer_id, $value, LP_SESSION_CACHE_GROUP, $this->_session_expiration - time() );
285
}
286
287
+ return LP_Helper::maybe_unserialize( $value );
288
}
289
290
public function delete_session( $customer_id ) {
344
public function get( $key, $default = null ) {
345
$key = sanitize_key( $key );
346
347
+ return isset( $this->_data[ $key ] ) ? LP_Helper::maybe_unserialize( $this->_data[ $key ] ) : $default;
348
}
349
350
/**
inc/class-lp-settings.php CHANGED
@@ -91,7 +91,7 @@ class LP_Settings {
91
92
if ( $options = $wpdb->get_results( $query ) ) {
93
foreach ( $options as $option ) {
94
- $this->_options[ $option->option_name ] = maybe_unserialize( $option->option_value );
95
}
96
}
97
}
@@ -114,7 +114,7 @@ class LP_Settings {
114
$current_var = array_shift( $var );
115
if ( is_object( $obj ) ) {
116
if ( isset( $obj->{$current_var} ) ) {
117
- $obj->{$current_var} = maybe_unserialize( $obj->{$current_var} );
118
if ( count( $var ) ) {
119
$this->_set_option( $obj->{$current_var}, join( '.', $var ), $value );
120
} else {
@@ -125,7 +125,7 @@ class LP_Settings {
125
}
126
} else {
127
if ( isset( $obj[ $current_var ] ) ) {
128
- $obj[ $current_var ] = maybe_unserialize( $obj[ $current_var ] );
129
if ( count( $var ) ) {
130
$this->_set_option( $obj[ $current_var ], join( '.', $var ), $value );
131
} else {
@@ -174,7 +174,7 @@ class LP_Settings {
174
$current_var = array_shift( $var );
175
if ( is_object( $obj ) ) {
176
if ( isset( $obj->{$current_var} ) ) {
177
- $obj->{$current_var} = maybe_unserialize( $obj->{$current_var} );
178
if ( count( $var ) ) {
179
return $this->_get_option( $obj->{$current_var}, join( '.', $var ), $default );
180
} else {
@@ -185,7 +185,7 @@ class LP_Settings {
185
}
186
} else {
187
if ( isset( $obj[ $current_var ] ) ) {
188
- $obj[ $current_var ] = maybe_unserialize( $obj[ $current_var ] );
189
if ( count( $var ) ) {
190
return $this->_get_option( $obj[ $current_var ], join( '.', $var ), $default );
191
} else {
@@ -318,7 +318,7 @@ class LP_Settings {
318
319
foreach ( $options as $o_name ) {
320
if ( ! empty( $alloptions_db[ $o_name ] ) ) {
321
- $o_value = maybe_unserialize( $alloptions_db[ $o_name ]->option_value );
322
wp_cache_set( $o_name, $o_value, 'options' );
323
} else {
324
if ( ! is_array( $notoptions ) ) {
91
92
if ( $options = $wpdb->get_results( $query ) ) {
93
foreach ( $options as $option ) {
94
+ $this->_options[ $option->option_name ] = LP_Helper::maybe_unserialize( $option->option_value );
95
}
96
}
97
}
114
$current_var = array_shift( $var );
115
if ( is_object( $obj ) ) {
116
if ( isset( $obj->{$current_var} ) ) {
117
+ $obj->{$current_var} = LP_Helper::maybe_unserialize( $obj->{$current_var} );
118
if ( count( $var ) ) {
119
$this->_set_option( $obj->{$current_var}, join( '.', $var ), $value );
120
} else {
125
}
126
} else {
127
if ( isset( $obj[ $current_var ] ) ) {
128
+ $obj[ $current_var ] = LP_Helper::maybe_unserialize( $obj[ $current_var ] );
129
if ( count( $var ) ) {
130
$this->_set_option( $obj[ $current_var ], join( '.', $var ), $value );
131
} else {
174
$current_var = array_shift( $var );
175
if ( is_object( $obj ) ) {
176
if ( isset( $obj->{$current_var} ) ) {
177
+ $obj->{$current_var} = LP_Helper::maybe_unserialize( $obj->{$current_var} );
178
if ( count( $var ) ) {
179
return $this->_get_option( $obj->{$current_var}, join( '.', $var ), $default );
180
} else {
185
}
186
} else {
187
if ( isset( $obj[ $current_var ] ) ) {
188
+ $obj[ $current_var ] = LP_Helper::maybe_unserialize( $obj[ $current_var ] );
189
if ( count( $var ) ) {
190
return $this->_get_option( $obj[ $current_var ], join( '.', $var ), $default );
191
} else {
318
319
foreach ( $options as $o_name ) {
320
if ( ! empty( $alloptions_db[ $o_name ] ) ) {
321
+ $o_value = LP_Helper::maybe_unserialize( $alloptions_db[ $o_name ]->option_value );
322
wp_cache_set( $o_name, $o_value, 'options' );
323
} else {
324
if ( ! is_array( $notoptions ) ) {
inc/course/abstract-course.php CHANGED
@@ -1819,6 +1819,23 @@ if ( ! function_exists( 'LP_Abstract_Course' ) ) {
1819
return learn_press_get_user( get_post_field( 'post_author', $this->get_id() ) );
1820
}
1821
1822
/**
1823
* @return mixed
1824
*/
1819
return learn_press_get_user( get_post_field( 'post_author', $this->get_id() ) );
1820
}
1821
1822
+ /**
1823
+ * Get author's display name
1824
+ *
1825
+ * @since 3.0.9
1826
+ *
1827
+ * @return string
1828
+ */
1829
+ public function get_author_display_name() {
1830
+ $display_name = '';
1831
+
1832
+ if ( $user = $this->get_author() ) {
1833
+ $display_name = $user->get_display_name();
1834
+ }
1835
+
1836
+ return $display_name;
1837
+ }
1838
+
1839
/**
1840
* @return mixed
1841
*/
inc/course/class-lp-course-item.php CHANGED
@@ -64,10 +64,22 @@ if ( ! class_exists( 'LP_Course_Item' ) ) {
64
}
65
66
/**
67
* @return string
68
*/
69
- public function get_item_type() {
70
- return $this->_item_type;
71
}
72
73
/**
@@ -514,6 +526,14 @@ if ( ! class_exists( 'LP_Course_Item' ) ) {
514
$course_id = get_the_ID();
515
}
516
517
$key = 'course-item-' . $user_id . '-' . $course_id;
518
519
if ( false === ( $blocked_items = wp_cache_get( $key, 'blocked-items' ) ) ) {
64
}
65
66
/**
67
+ * Get type of item.
68
+ *
69
+ * @param string $context
70
+ *
71
* @return string
72
*/
73
+ public function get_item_type( $context = '' ) {
74
+ $post_type = $this->_item_type;
75
+
76
+ if ( $context === 'display' ) {
77
+ if ( $post_type_object = get_post_type_object( $post_type ) ) {
78
+ $post_type = $post_type_object->labels->singular_name;
79
+ }
80
+ }
81
+
82
+ return $post_type;
83
}
84
85
/**
526
$course_id = get_the_ID();
527
}
528
529
+ $course_author = learn_press_get_course_user( $course_id );
530
+ if ( $course_author ) {
531
+ $author_id = $course_author->get_id();
532
+ if ( $author_id == $user_id ) {
533
+ return false;
534
+ }
535
+ }
536
+
537
$key = 'course-item-' . $user_id . '-' . $course_id;
538
539
if ( false === ( $blocked_items = wp_cache_get( $key, 'blocked-items' ) ) ) {
inc/course/lp-course-functions.php CHANGED
@@ -710,7 +710,7 @@ if ( ! function_exists( 'learn_press_get_nav_course_item_url' ) ) {
710
function learn_press_get_nav_course_item_url( $course_id = null, $item_id = null, $content_only = false ) {
711
712
$course = learn_press_get_course( $course_id );
713
- $curriculum_items = $course->get_items();// maybe_unserialize( $course->post->curriculum_items );
714
$index = array_search( $item_id, $curriculum_items );
715
$return = array( 'back' => '', 'next' => '' );
716
if ( is_array( $curriculum_items ) ) {
710
function learn_press_get_nav_course_item_url( $course_id = null, $item_id = null, $content_only = false ) {
711
712
$course = learn_press_get_course( $course_id );
713
+ $curriculum_items = $course->get_items();// LP_Helper::maybe_unserialize( $course->post->curriculum_items );
714
$index = array_search( $item_id, $curriculum_items );
715
$return = array( 'back' => '', 'next' => '' );
716
if ( is_array( $curriculum_items ) ) {
inc/curds/class-lp-course-curd.php CHANGED
@@ -89,6 +89,26 @@ if ( ! class_exists( 'LP_Course_CURD' ) ) {
89
$curd->clear();
90
}
91
92
/**
93
* Duplicate course.
94
*
89
$curd->clear();
90
}
91
92
+ /**
93
+ * Delete course itself and sections.
94
+ *
95
+ * @param int|object $course_id
96
+ * @param bool $delete_item - Optional. TRUE will delete all items assigned to course
97
+ */
98
+ public function delete_course( $course_id, $delete_item = false ) {
99
+ if ( $delete_item ) {
100
+ if($course = learn_press_get_course( $course_id )) {
101
+ if ( $items = $course->get_items() ) {
102
+ foreach ( $items as $item ) {
103
+ wp_delete_post( $item );
104
+ }
105
+ }
106
+ }
107
+ }
108
+
109
+ wp_delete_post( $course_id );
110
+ }
111
+
112
/**
113
* Duplicate course.
114
*
inc/curds/class-lp-order-curd.php CHANGED
@@ -131,7 +131,7 @@ class LP_Order_CURD extends LP_Object_Data_CURD implements LP_Interface_CURD {
131
public function get_item_meta( &$item ) {
132
if ( $metas = get_metadata( 'learnpress_order_item', $item['id'] ) ) {
133
foreach ( $metas as $k => $v ) {
134
- $item[ preg_replace( '!^_!', '', $k ) ] = maybe_unserialize( $v[0] );
135
}
136
};
137
//$item = wp_parse_args()
131
public function get_item_meta( &$item ) {
132
if ( $metas = get_metadata( 'learnpress_order_item', $item['id'] ) ) {
133
foreach ( $metas as $k => $v ) {
134
+ $item[ preg_replace( '!^_!', '', $k ) ] = LP_Helper::maybe_unserialize( $v[0] );
135
}
136
};
137
//$item = wp_parse_args()
inc/curds/class-lp-question-curd.php CHANGED
@@ -870,7 +870,7 @@ if ( ! class_exists( 'LP_Question_CURD' ) ) {
870
if ( $answer_options = $wpdb->get_results( $query, OBJECT_K ) ) {
871
foreach ( $answer_options as $k => $v ) {
872
$answer_options[ $k ] = (array) $answer_options[ $k ];
873
- if ( $answer_data = maybe_unserialize( $v->answer_data ) ) {
874
foreach ( $answer_data as $data_key => $data_value ) {
875
$answer_options[ $k ][ $data_key ] = $data_value;
876
}
@@ -932,7 +932,7 @@ if ( ! class_exists( 'LP_Question_CURD' ) ) {
932
$question_answers[ $qid ] = array();
933
}
934
935
- if ( $answer_data = maybe_unserialize( $v->answer_data ) ) {
936
foreach ( $answer_data as $data_key => $data_value ) {
937
$v->{$data_key} = $data_value;
938
}
870
if ( $answer_options = $wpdb->get_results( $query, OBJECT_K ) ) {
871
foreach ( $answer_options as $k => $v ) {
872
$answer_options[ $k ] = (array) $answer_options[ $k ];
873
+ if ( $answer_data = LP_Helper::maybe_unserialize( $v->answer_data ) ) {
874
foreach ( $answer_data as $data_key => $data_value ) {
875
$answer_options[ $k ][ $data_key ] = $data_value;
876
}
932
$question_answers[ $qid ] = array();
933
}
934
935
+ if ( $answer_data = LP_Helper::maybe_unserialize( $v->answer_data ) ) {
936
foreach ( $answer_data as $data_key => $data_value ) {
937
$v->{$data_key} = $data_value;
938
}
inc/curds/class-lp-user-curd.php CHANGED
@@ -120,7 +120,6 @@ class LP_User_CURD extends LP_Object_Data_CURD implements LP_Interface_CURD {
120
* )
121
*
122
* @param int $user_id
123
- * @param bool $group_by_order - Optional. Group by order id instead of by course id
124
* @param array $args
125
*
126
* @return array|mixed
@@ -529,7 +528,7 @@ class LP_User_CURD extends LP_Object_Data_CURD implements LP_Interface_CURD {
529
if ( $meta = $wpdb->get_results( $query, ARRAY_A ) ) {
530
$item['meta'] = array();
531
foreach ( $meta as $k => $v ) {
532
- $v['meta_value'] = maybe_unserialize( $v['meta_value'] );
533
$item['meta'][ $v['meta_id'] ] = $v;
534
}
535
}
@@ -939,10 +938,7 @@ class LP_User_CURD extends LP_Object_Data_CURD implements LP_Interface_CURD {
939
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->learnpress_user_itemmeta} WHERE learnpress_user_item_id = %d", $user_item_id ) );
940
do_action( 'learn-press/deleted-user-item', $user_item_id );
941
}
942
- // if($user_item_ids) {
943
- // // Flush all cache to apply new changes
944
- // wp_cache_flush();
945
- // }
946
947
return true;
948
}
@@ -1046,7 +1042,7 @@ class LP_User_CURD extends LP_Object_Data_CURD implements LP_Interface_CURD {
1046
} else {
1047
if ( 'pending' === $args['status'] ) {
1048
$where .= $wpdb->prepare( " AND post_status IN( %s, %s )", array( 'draft', 'pending' ) );
1049
- } else {
1050
$where .= $wpdb->prepare( " AND post_status = %s", $args['status'] );
1051
}
1052
}
@@ -1564,4 +1560,6 @@ class LP_User_CURD extends LP_Object_Data_CURD implements LP_Interface_CURD {
1564
1565
return $new_user;
1566
}
1567
}
120
* )
121
*
122
* @param int $user_id
123
* @param array $args
124
*
125
* @return array|mixed
528
if ( $meta = $wpdb->get_results( $query, ARRAY_A ) ) {
529
$item['meta'] = array();
530
foreach ( $meta as $k => $v ) {
531
+ $v['meta_value'] = LP_Helper::maybe_unserialize( $v['meta_value'] );
532
$item['meta'][ $v['meta_id'] ] = $v;
533
}
534
}
938
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->learnpress_user_itemmeta} WHERE learnpress_user_item_id = %d", $user_item_id ) );
939
do_action( 'learn-press/deleted-user-item', $user_item_id );
940
}
941
+
942
943
return true;
944
}
1042
} else {
1043
if ( 'pending' === $args['status'] ) {
1044
$where .= $wpdb->prepare( " AND post_status IN( %s, %s )", array( 'draft', 'pending' ) );
1045
+ } elseif ( $args['status'] !== '*' ) {
1046
$where .= $wpdb->prepare( " AND post_status = %s", $args['status'] );
1047
}
1048
}
1560
1561
return $new_user;
1562
}
1563
+
1564
+
1565
}
inc/curds/class-lp-user-item-curd.php CHANGED
@@ -143,7 +143,7 @@ class LP_User_Item_CURD implements LP_Interface_CURD {
143
$answer_options[ $v->question_id ] = array();
144
}
145
$v = (array) $v;
146
- if ( $answer_data = maybe_unserialize( $v['answer_data'] ) ) {
147
foreach ( $answer_data as $kk => $vv ) {
148
$v[ $kk ] = $vv;
149
}
@@ -154,7 +154,7 @@ class LP_User_Item_CURD implements LP_Interface_CURD {
154
$answer_options[ $v['question_id'] ][] = $v;
155
/*$kk = sizeof( $answer_options[ $v->question_id ] );
156
157
- if ( $answer_data = maybe_unserialize( $v->answer_data ) ) {
158
foreach ( $answer_data as $data_key => $data_value ) {
159
$answer_options[ $v->question_id ][ $kk ][ $data_key ] = $data_value;
160
}
@@ -414,6 +414,9 @@ class LP_User_Item_CURD implements LP_Interface_CURD {
414
return learn_press_update_user_item_meta( $object->get_user_item_id(), $meta->meta_key, $meta->meta_value );
415
}
416
417
/**
418
* Get WP_Object.
419
*
143
$answer_options[ $v->question_id ] = array();
144
}
145
$v = (array) $v;
146
+ if ( $answer_data = LP_Helper::maybe_unserialize( $v['answer_data'] ) ) {
147
foreach ( $answer_data as $kk => $vv ) {
148
$v[ $kk ] = $vv;
149
}
154
$answer_options[ $v['question_id'] ][] = $v;
155
/*$kk = sizeof( $answer_options[ $v->question_id ] );
156
157
+ if ( $answer_data = LP_Helper::maybe_unserialize( $v->answer_data ) ) {
158
foreach ( $answer_data as $data_key => $data_value ) {
159
$answer_options[ $v->question_id ][ $kk ][ $data_key ] = $data_value;
160
}
414
return learn_press_update_user_item_meta( $object->get_user_item_id(), $meta->meta_key, $meta->meta_value );
415
}
416
417
+ /**
418
+
419
+
420
/**
421
* Get WP_Object.
422
*
inc/custom-post-types/course.php CHANGED
@@ -92,15 +92,20 @@ if ( ! class_exists( 'LP_Course_Post_Type' ) ) {
92
'items' => array(),
93
),
94
'i18n' => array(
95
- 'item' => __( 'item', 'learnpress' ),
96
- 'new_section_item' => __( 'Create a new', 'learnpress' ),
97
- 'back' => __( 'Back', 'learnpress' ),
98
- 'selected_items' => __( 'Selected items', 'learnpress' ),
99
- 'confirm_trash_item' => __( 'Do you want to remove item "{{ITEM_NAME}}" to trash?', 'learnpress' ),
100
- 'item_labels' => array(
101
'singular' => __( 'Item', 'learnpress' ),
102
'plural' => __( 'Items', 'learnpress' ),
103
- )
104
),
105
'sections' => array(
106
'sections' => $course->get_curriculum_raw(),
@@ -628,6 +633,13 @@ if ( ! class_exists( 'LP_Course_Post_Type' ) ) {
628
'type' => 'url',
629
'desc' => __( 'Redirect to this url when you press button buy this course.', 'learnpress' ),
630
'std' => '',
631
)
632
)
633
);
92
'items' => array(),
93
),
94
'i18n' => array(
95
+ 'item' => __( 'item', 'learnpress' ),
96
+ 'new_section_item' => __( 'Create a new', 'learnpress' ),
97
+ 'back' => __( 'Back', 'learnpress' ),
98
+ 'selected_items' => __( 'Selected items', 'learnpress' ),
99
+ 'confirm_trash_item' => __( 'Do you want to remove item "{{ITEM_NAME}}" to trash?', 'learnpress' ),
100
+ 'item_labels' => array(
101
'singular' => __( 'Item', 'learnpress' ),
102
'plural' => __( 'Items', 'learnpress' ),
103
+ ),
104
+ 'notice_sale_price' => __( 'Course sale price must less than the regular price', 'learnpress' ),
105
+ 'notice_price' => __( 'Course price must greater than the sale price', 'learnpress' ),
106
+ 'notice_sale_start_date' => __( 'Sale start date must before sale end date', 'learnpress' ),
107
+ 'notice_sale_end_date' => __( 'Sale end date must before sale start date', 'learnpress' ),
108
+ 'notice_invalid_date' => __( 'Invalid date', 'learnpress' ),
109
),
110
'sections' => array(
111
'sections' => $course->get_curriculum_raw(),
633
'type' => 'url',
634
'desc' => __( 'Redirect to this url when you press button buy this course.', 'learnpress' ),
635
'std' => '',
636
+ ),
637
+ array(
638
+ 'name' => __( 'Submission Form', 'learnpress' ),
639
+ 'id' => '_lp_submission',
640
+ 'type' => 'yes-no',
641
+ 'desc' => __( 'If this option is ON, then guess can click on the link of items but only see the submission form.', 'learnpress' ),
642
+ 'std' => 'yes'
643
)
644
)
645
);
inc/custom-post-types/lesson.php CHANGED
@@ -261,23 +261,6 @@ if ( ! class_exists( 'LP_Lesson_Post_Type' ) ) {
261
'type' => 'yes-no',
262
'desc' => __( 'If this is a preview lesson, then student can view this lesson content without taking the course.', 'learnpress' ),
263
'std' => 'no'
264
- ),
265
- array(
266
- 'name' => __( 'Submission Form', 'learnpress' ),
267
- 'id' => '_lp_submission',
268
- 'type' => 'yes-no',
269
- 'desc' => __( 'If this option is ON, then guess can click on the link of this lesson but only see the submission form.', 'learnpress' ),
270
- 'std' => 'no',
271
- 'visibility' => array(
272
- 'state' => 'show',
273
- 'conditional' => array(
274
- array(
275
- 'field' => '_lp_preview',
276
- 'compare' => '!=',
277
- 'value' => 'yes'
278
- )
279
- )
280
- )
281
)
282
)
283
)
261
'type' => 'yes-no',
262
'desc' => __( 'If this is a preview lesson, then student can view this lesson content without taking the course.', 'learnpress' ),
263
'std' => 'no'
264
)
265
)
266
)
inc/emails/_bk/class-lp-email-finished-course-admin.php ADDED
@@ -0,0 +1,199 @@
1
+ <?php
2
+ /**
3
+ * Class LP_Email_Finished_Course_Admin
4
+ *
5
+ * @author ThimPress
6
+ * @package LearnPress/Classes
7
+ * @version 3.0.0
8
+ */
9
+
10
+ /**
11
+ * Prevent loading this file directly
12
+ */
13
+ defined( 'ABSPATH' ) || exit();
14
+
15
+ if ( ! class_exists( 'LP_Email_Finished_Course_Admin' ) ) {
16
+
17
+ /**
18
+ * Class LP_Email_Finished_Course_Admin
19
+ */
20
+ class LP_Email_Finished_Course_Admin extends LP_Email_Type_Finished_Course {
21
+ /**
22
+ * LP_Email_Finished_Course constructor.
23
+ */
24
+ public function __construct() {
25
+ $this->id = 'finished-course-admin';
26
+ $this->title = __( 'Admin', 'learnpress' );
27
+ $this->description = __( 'Send this email to user when a user finished a course.', 'learnpress' );
28
+
29
+
30
+ $this->default_subject = __( '[{{site_title}}] You have finished this course ({{course_name}})', 'learnpress' );
31
+ $this->default_heading = __( 'Finished course', 'learnpress' );
32
+
33
+ $this->support_variables = array_merge( $this->general_variables, array(
34
+ '{{course_id}}',
35
+ '{{course_name}}',
36
+ '{{course_url}}',
37
+ '{{user_id}}',
38
+ '{{user_name}}',
39
+ '{{user_email}}',
40
+ '{{user_profile_url}}'
41
+ ) );
42
+
43
+ //$this->email_text_message_description = sprintf( '%s {{course_id}}, {{course_title}}, {{course_url}}, {{user_email}}, {{user_name}}, {{user_profile_url}}', __( 'Shortcodes', 'learnpress' ) );
44
+
45
+ parent::__construct();
46
+ }
47
+
48
+ /**
49
+ * Trigger email.
50
+ *
51
+ * @param $course_id
52
+ * @param $user_id
53
+ * @param $result
54
+ *
55
+ * @return bool
56
+ */
57
+ public function trigger( $course_id, $user_id, $result ) {
58
+
59
+ if ( ! $this->enable || ! ( $user = learn_press_get_user( $user_id ) ) ) {
60
+ return false;
61
+ }
62
+
63
+ $course = learn_press_get_course( $course_id );
64
+ remove_filter( 'the_title', 'wptexturize' );
65
+ $course_name = $course->get_title();
66
+ add_filter( 'the_title', 'wptexturize' );
67
+
68
+ $this->object = $this->get_common_template_data(
69
+ $this->email_format,
70
+ array(
71
+ 'course_id' => $course_id,
72
+ 'course_name' => $course_name,
73
+ 'course_url' => get_the_permalink( $course_id ),
74
+ 'user_id' => $user_id,
75
+ 'user_name' => learn_press_get_profile_display_name( $user ),
76
+ 'user_email' => $user->user_email,
77
+ 'user_profile_url' => learn_press_user_profile_link( $user->get_id() )
78
+ )
79
+ );
80
+
81
+ $this->variables = $this->data_to_variables( $this->object );
82
+
83
+ $this->object['course'] = $course;
84
+ $this->object['user'] = $user;
85
+
86
+ $this->recipient = $user->user_email;
87
+
88
+ $return = $this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
89
+
90
+ return $return;
91
+ }
92
+
93
+
94
+ /**
95
+ * Get recipient.
96
+ *
97
+ * @return mixed|void
98
+ */
99
+ public function get_recipient() {
100
+ if ( ! empty( $this->object['user'] ) ) {
101
+ $this->recipient = $this->object['user']->user_email;
102
+ }
103
+
104
+ parent::get_recipient();
105
+ }
106
+
107
+ /**
108
+ * Get email template.
109
+ *
110
+ * @param string $content_type
111
+ *
112
+ * @return array|object
113
+ */
114
+ public function get_template_data( $content_type = 'plain' ) {
115
+ return $this->object;
116
+ }
117
+
118
+ /**
119
+ * Admin settings.
120
+ */
121
+ public function get_settings() {
122
+ return apply_filters(
123
+ 'learn-press/email-settings/finished-course/settings',
124
+ array(
125
+ array(
126
+ 'type' => 'heading',
127
+ 'title' => $this->title,
128
+ 'desc' => $this->description
129
+ ),
130
+ array(
131
+ 'title' => __( 'Enable', 'learnpress' ),
132
+ 'type' => 'yes-no',
133
+ 'default' => 'no',
134
+ 'id' => $this->get_field_name( 'enable' )
135
+ ),
136
+ array(
137
+ 'title' => __( 'Subject', 'learnpress' ),
138
+ 'type' => 'text',
139
+ 'default' => $this->default_subject,
140
+ 'id' => $this->get_field_name( 'subject' ),
141
+ 'desc' => sprintf( __( 'Email subject, default: <code>%s</code>.', 'learnpress' ), $this->default_subject ),
142
+ 'visibility' => array(
143
+ 'state' => 'show',
144
+ 'conditional' => array(
145
+ array(
146
+ 'field' => $this->get_field_name( 'enable' ),
147
+ 'compare' => '=',
148
+ 'value' => 'yes'
149
+ )
150
+ )
151
+ )
152
+ ),
153
+ array(
154
+ 'title' => __( 'Heading', 'learnpress' ),
155
+ 'type' => 'text',
156
+ 'default' => $this->default_heading,
157
+ 'id' => $this->get_field_name( 'heading' ),
158
+ 'desc' => sprintf( __( 'Email heading, default: <code>%s</code>.', 'learnpress' ), $this->default_heading ),
159
+ 'visibility' => array(
160
+ 'state' => 'show',
161
+ 'conditional' => array(
162
+ array(
163
+ 'field' => $this->get_field_name( 'enable' ),
164
+ 'compare' => '=',
165
+ 'value' => 'yes'
166
+ )
167
+ )
168
+ )
169
+ ),
170
+ array(
171
+ 'title' => __( 'Email content', 'learnpress' ),
172
+ 'type' => 'email-content',
173
+ 'default' => '',
174
+ 'id' => $this->get_field_name( 'email_content' ),
175
+ 'template_base' => $this->template_base,
176
+ 'template_path' => $this->template_path,//default learnpress
177
+ 'template_html' => $this->template_html,
178
+ 'template_plain' => $this->template_plain,
179
+ 'template_html_local' => $this->get_theme_template_file( 'html', $this->template_path ),
180
+ 'template_plain_local' => $this->get_theme_template_file( 'plain', $this->template_path ),
181
+ 'support_variables' => $this->get_variables_support(),
182
+ 'visibility' => array(
183
+ 'state' => 'show',
184
+ 'conditional' => array(
185
+ array(
186
+ 'field' => $this->get_field_name( 'enable' ),
187
+ 'compare' => '=',
188
+ 'value' => 'yes'
189
+ )
190
+ )
191
+ )
192
+ ),
193
+ )
194
+ );
195
+ }
196
+ }
197
+ }
198
+
199
+ return new LP_Email_Finished_Course_Admin();
inc/emails/_bk/class-lp-email-finished-course-instructor.php ADDED
@@ -0,0 +1,201 @@
1
+ <?php
2
+ /**
3
+ * Class LP_Email_Finished_Course_Instructor
4
+ *
5
+ * @author ThimPress
6
+ * @package LearnPress/Classes
7
+ * @version 3.0.0
8
+ */
9
+
10
+ /**
11
+ * Prevent loading this file directly
12
+ */
13
+ defined( 'ABSPATH' ) || exit();
14
+
15
+ if ( ! class_exists( 'LP_Email_Finished_Course_Instructor' ) ) {
16
+
17
+ /**
18
+ * Class LP_Email_Finished_Course_Instructor
19
+ */
20
+ class LP_Email_Finished_Course_Instructor extends LP_Email {
21
+ /**
22
+ * LP_Email_Finished_Course constructor.
23
+ */
24
+ public function __construct() {
25
+ $this->id = 'finished-course-instructor';
26
+ $this->title = __( 'Instructor', 'learnpress' );
27
+ $this->description = __( 'Send this email to user when a user finished a course.', 'learnpress' );
28
+
29
+ $this->template_html = 'emails/finished-course.php';
30
+ $this->template_plain = 'emails/plain/finished-course.php';
31
+
32
+ $this->default_subject = __( '[{{site_title}}] You have finished this course ({{course_name}})', 'learnpress' );
33
+ $this->default_heading = __( 'Finished course', 'learnpress' );
34
+
35
+ $this->support_variables = array_merge( $this->general_variables, array(
36
+ '{{course_id}}',
37
+ '{{course_name}}',
38
+ '{{course_url}}',
39
+ '{{user_id}}',
40
+ '{{user_name}}',
41
+ '{{user_email}}',
42
+ '{{user_profile_url}}'
43
+ ) );
44
+
45
+ //$this->email_text_message_description = sprintf( '%s {{course_id}}, {{course_title}}, {{course_url}}, {{user_email}}, {{user_name}}, {{user_profile_url}}', __( 'Shortcodes', 'learnpress' ) );
46
+
47
+ parent::__construct();
48
+ }
49
+
50
+ /**
51
+ * Trigger email.
52
+ *
53
+ * @param $course_id
54
+ * @param $user_id
55
+ * @param $result
56
+ *
57
+ * @return bool
58
+ */
59
+ public function trigger( $course_id, $user_id, $result ) {
60
+
61
+ if ( ! $this->enable || ! ( $user = learn_press_get_user( $user_id ) ) ) {
62
+ return false;
63
+ }
64
+
65
+ $course = learn_press_get_course( $course_id );
66
+ remove_filter( 'the_title', 'wptexturize' );
67
+ $course_name = $course->get_title();
68
+ add_filter( 'the_title', 'wptexturize' );
69
+
70
+ $this->object = $this->get_common_template_data(
71
+ $this->email_format,
72
+ array(
73
+ 'course_id' => $course_id,
74
+ 'course_name' => $course_name,
75
+ 'course_url' => get_the_permalink( $course_id ),
76
+ 'user_id' => $user_id,
77
+ 'user_name' => learn_press_get_profile_display_name( $user ),
78
+ 'user_email' => $user->user_email,
79
+ 'user_profile_url' => learn_press_user_profile_link( $user->get_id() )
80
+ )
81
+ );
82
+
83
+ $this->variables = $this->data_to_variables( $this->object );
84
+
85
+ $this->object['course'] = $course;
86
+ $this->object['user'] = $user;
87
+
88
+ $this->recipient = $user->user_email;
89
+
90
+ $return = $this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
91
+
92
+ return $return;
93
+ }
94
+
95
+
96
+ /**
97
+ * Get recipient.
98
+ *
99
+ * @return mixed|void
100
+ */
101
+ public function get_recipient() {
102
+ if ( ! empty( $this->object['user'] ) ) {
103
+ $this->recipient = $this->object['user']->user_email;
104
+ }
105
+
106
+ parent::get_recipient();
107
+ }
108
+
109
+ /**
110
+ * Get email template.
111
+ *
112
+ * @param string $content_type
113
+ *
114
+ * @return array|object
115
+ */
116
+ public function get_template_data( $content_type = 'plain' ) {
117
+ return $this->object;
118
+ }
119
+
120
+ /**
121
+ * Admin settings.
122
+ */
123
+ public function get_settings() {
124
+ return apply_filters(
125
+ 'learn-press/email-settings/finished-course/settings',
126
+ array(
127
+ array(
128
+ 'type' => 'heading',
129
+ 'title' => $this->title,
130
+ 'desc' => $this->description
131
+ ),
132
+ array(
133
+ 'title' => __( 'Enable', 'learnpress' ),
134
+ 'type' => 'yes-no',
135
+ 'default' => 'no',
136
+ 'id' => $this->get_field_name( 'enable' )
137
+ ),
138
+ array(
139
+ 'title' => __( 'Subject', 'learnpress' ),
140
+ 'type' => 'text',
141
+ 'default' => $this->default_subject,
142
+ 'id' => $this->get_field_name( 'subject' ),
143
+ 'desc' => sprintf( __( 'Email subject, default: <code>%s</code>.', 'learnpress' ), $this->default_subject ),
144
+ 'visibility' => array(
145
+ 'state' => 'show',
146
+ 'conditional' => array(
147
+ array(
148
+ 'field' => $this->get_field_name( 'enable' ),
149
+ 'compare' => '=',
150
+ 'value' => 'yes'
151
+ )
152
+ )
153
+ )
154
+ ),
155
+ array(
156
+ 'title' => __( 'Heading', 'learnpress' ),
157
+ 'type' => 'text',
158
+ 'default' => $this->default_heading,
159
+ 'id' => $this->get_field_name( 'heading' ),
160
+ 'desc' => sprintf( __( 'Email heading, default: <code>%s</code>.', 'learnpress' ), $this->default_heading ),
161
+ 'visibility' => array(
162
+ 'state' => 'show',
163
+ 'conditional' => array(
164
+ array(
165
+ 'field' => $this->get_field_name( 'enable' ),
166
+ 'compare' => '=',
167
+ 'value' => 'yes'
168
+ )
169
+ )
170
+ )
171
+ ),
172
+ array(
173
+ 'title' => __( 'Email content', 'learnpress' ),
174
+ 'type' => 'email-content',
175
+ 'default' => '',
176
+ 'id' => $this->get_field_name( 'email_content' ),
177
+ 'template_base' => $this->template_base,
178
+ 'template_path' => $this->template_path,//default learnpress
179
+ 'template_html' => $this->template_html,
180
+ 'template_plain' => $this->template_plain,
181
+ 'template_html_local' => $this->get_theme_template_file( 'html', $this->template_path ),
182
+ 'template_plain_local' => $this->get_theme_template_file( 'plain', $this->template_path ),
183
+ 'support_variables' => $this->get_variables_support(),
184
+ 'visibility' => array(
185
+ 'state' => 'show',
186
+ 'conditional' => array(
187
+ array(
188
+ 'field' => $this->get_field_name( 'enable' ),
189
+ 'compare' => '=',
190
+ 'value' => 'yes'
191
+ )
192
+ )
193
+ )
194
+ ),
195
+ )
196
+ );
197
+ }
198
+ }
199
+ }
200
+
201
+ return new LP_Email_Finished_Course_Instructor();
inc/emails/_bk/class-lp-email-finished-course-user.php ADDED
@@ -0,0 +1,201 @@
1
+ <?php
2
+ /**
3
+ * Class LP_Email_Finished_Course_User
4
+ *
5
+ * @author ThimPress
6
+ * @package LearnPress/Classes
7
+ * @version 3.0.0
8
+ */
9
+
10
+ /**
11
+ * Prevent loading this file directly
12
+ */
13
+ defined( 'ABSPATH' ) || exit();
14
+
15
+ if ( ! class_exists( 'LP_Email_Finished_Course_User' ) ) {
16
+
17
+ /**
18
+ * Class LP_Email_Finished_Course_User
19
+ */
20
+ class LP_Email_Finished_Course_User extends LP_Email {
21
+ /**
22
+ * LP_Email_Finished_Course constructor.
23
+ */
24
+ public function __construct() {
25
+ $this->id = 'finished-course-user';
26
+ $this->title = __( 'User', 'learnpress' );
27
+ $this->description = __( 'Send this email to user when a user finished a course.', 'learnpress' );
28
+
29
+ $this->template_html = 'emails/finished-course.php';
30
+ $this->template_plain = 'emails/plain/finished-course.php';
31
+
32
+ $this->default_subject = __( '[{{site_title}}] You have finished this course ({{course_name}})', 'learnpress' );
33
+ $this->default_heading = __( 'Finished course', 'learnpress' );
34
+
35
+ $this->support_variables = array_merge( $this->general_variables, array(
36
+ '{{course_id}}',
37
+ '{{course_name}}',
38
+ '{{course_url}}',
39
+ '{{user_id}}',
40
+ '{{user_name}}',
41
+ '{{user_email}}',
42
+ '{{user_profile_url}}'
43
+ ) );
44
+
45
+ //$this->email_text_message_description = sprintf( '%s {{course_id}}, {{course_title}}, {{course_url}}, {{user_email}}, {{user_name}}, {{user_profile_url}}', __( 'Shortcodes', 'learnpress' ) );
46
+
47
+ parent::__construct();
48
+ }
49
+
50
+ /**
51
+ * Trigger email.
52
+ *
53
+ * @param $course_id
54
+ * @param $user_id
55
+ * @param $result
56
+ *
57
+ * @return bool
58
+ */
59
+ public function trigger( $course_id, $user_id, $result ) {
60
+
61
+ if ( ! $this->enable || ! ( $user = learn_press_get_user( $user_id ) ) ) {
62
+ return false;
63
+ }
64
+
65
+ $course = learn_press_get_course( $course_id );
66
+ remove_filter( 'the_title', 'wptexturize' );
67
+ $course_name = $course->get_title();
68
+ add_filter( 'the_title', 'wptexturize' );
69
+
70
+ $this->object = $this->get_common_template_data(
71
+ $this->email_format,
72
+ array(
73
+ 'course_id' => $course_id,
74
+ 'course_name' => $course_name,
75
+ 'course_url' => get_the_permalink( $course_id ),
76
+ 'user_id' => $user_id,
77
+ 'user_name' => learn_press_get_profile_display_name( $user ),
78
+ 'user_email' => $user->user_email,
79
+ 'user_profile_url' => learn_press_user_profile_link( $user->get_id() )
80
+ )
81
+ );
82
+
83
+ $this->variables = $this->data_to_variables( $this->object );
84
+
85
+ $this->object['course'] = $course;
86
+ $this->object['user'] = $user;
87
+
88
+ $this->recipient = $user->user_email;
89
+
90
+ $return = $this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
91
+
92
+ return $return;
93
+ }
94
+
95
+
96
+ /**
97
+ * Get recipient.
98
+ *
99
+ * @return mixed|void
100
+ */
101
+ public function get_recipient() {
102
+ if ( ! empty( $this->object['user'] ) ) {
103
+ $this->recipient = $this->object['user']->user_email;
104
+ }
105
+
106
+ parent::get_recipient();
107
+ }
108
+
109
+ /**
110
+ * Get email template.
111
+ *
112
+ * @param string $content_type
113
+ *
114
+ * @return array|object
115
+ */
116
+ public function get_template_data( $content_type = 'plain' ) {
117
+ return $this->object;
118
+ }
119
+
120
+ /**
121
+ * Admin settings.
122
+ */
123
+ public function get_settings() {
124
+ return apply_filters(
125
+ 'learn-press/email-settings/finished-course/settings',
126
+ array(
127
+ array(
128
+ 'type' => 'heading',
129
+ 'title' => $this->title,
130
+ 'desc' => $this->description
131
+ ),
132
+ array(
133
+ 'title' => __( 'Enable', 'learnpress' ),
134
+ 'type' => 'yes-no',
135
+ 'default' => 'no',
136
+ 'id' => $this->get_field_name( 'enable' )
137
+ ),
138
+ array(
139
+ 'title' => __( 'Subject', 'learnpress' ),
140
+ 'type' => 'text',
141
+ 'default' => $this->default_subject,
142
+ 'id' => $this->get_field_name( 'subject' ),
143
+ 'desc' => sprintf( __( 'Email subject, default: <code>%s</code>.', 'learnpress' ), $this->default_subject ),
144
+ 'visibility' => array(
145
+ 'state' => 'show',
146
+ 'conditional' => array(
147
+ array(
148
+ 'field' => $this->get_field_name( 'enable' ),
149
+ 'compare' => '=',
150
+ 'value' => 'yes'
151
+ )
152
+ )
153
+ )
154
+ ),
155
+ array(
156
+ 'title' => __( 'Heading', 'learnpress' ),
157
+ 'type' => 'text',
158
+ 'default' => $this->default_heading,
159
+ 'id' => $this->get_field_name( 'heading' ),
160
+ 'desc' => sprintf( __( 'Email heading, default: <code>%s</code>.', 'learnpress' ), $this->default_heading ),
161
+ 'visibility' => array(
162
+ 'state' => 'show',
163
+ 'conditional' => array(
164
+ array(
165
+ 'field' => $this->get_field_name( 'enable' ),
166
+ 'compare' => '=',
167
+ 'value' => 'yes'
168
+ )
169
+ )
170
+ )
171
+ ),
172
+ array(
173
+ 'title' => __( 'Email content', 'learnpress' ),
174
+ 'type' => 'email-content',
175
+ 'default' => '',
176
+ 'id' => $this->get_field_name( 'email_content' ),
177
+ 'template_base' => $this->template_base,
178
+ 'template_path' => $this->template_path,//default learnpress
179
+ 'template_html' => $this->template_html,
180
+ 'template_plain' => $this->template_plain,
181
+ 'template_html_local' => $this->get_theme_template_file( 'html', $this->template_path ),
182
+ 'template_plain_local' => $this->get_theme_template_file( 'plain', $this->template_path ),
183
+ 'support_variables' => $this->get_variables_support(),
184
+ 'visibility' => array(
185
+ 'state' => 'show',
186
+ 'conditional' => array(
187
+ array(
188
+ 'field' => $this->get_field_name( 'enable' ),
189
+ 'compare' => '=',
190
+ 'value' => 'yes'
191
+ )
192
+ )
193
+ )
194
+ ),
195
+ )
196
+ );
197
+ }
198
+ }
199
+ }
200
+
201
+ return new LP_Email_Finished_Course_User();
inc/emails/types/class-lp-email-type-finished-course.php CHANGED
@@ -56,6 +56,7 @@ class LP_Email_Type_Finished_Course extends LP_Email {
56
print_r( $this );
57
die();
58
}
59
$course = learn_press_get_course( $this->course_id );
60
$course_data = $user->get_course_data( $this->course_id );
61
$object = array();
56
print_r( $this );
57
die();
58
}
59
+ wp_cache_delete( 'course-' . $user->get_id() . '-' . $this->course_id, 'lp-user-course-data' );
60
$course = learn_press_get_course( $this->course_id );
61
$course_data = $user->get_course_data( $this->course_id );
62
$object = array();
inc/gateways/paypal/class-lp-gateway-paypal.php CHANGED
@@ -233,7 +233,7 @@ if ( ! class_exists( 'LP_Gateway_Paypal' ) ) {
233
$order_key = $custom->order_key;
234
235
// Fallback to serialized data if safe. This is @deprecated in 2.3.11
236
- } elseif ( preg_match( '/^a:2:{/', $raw_custom ) && ! preg_match( '/[CO]:\+?[0-9]+:"/', $raw_custom ) && ( $custom = maybe_unserialize( $raw_custom ) ) ) {
237
$order_id = $custom[0];
238
$order_key = $custom[1];
239
233
$order_key = $custom->order_key;