LearnPress – WordPress LMS Plugin - Version 3.0.5

Version Description

  • Added: missing single course permalink options ~ Fixed: error notice when saving user profile ~ Fixed: date translation ~ Fixed: notice when viewing courses with Yoast SEO ~ Fixed: can't change author of the course ~ Fixed: preview lesson will redirect back to course ~ Fixed: some other bugs...
Download this release

Release Info

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

Code changes from version 3.0.4 to 3.0.5

assets/js/admin/admin.js CHANGED
@@ -333,6 +333,27 @@
333
  });
334
  }
335
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
336
  var $doc = $(document);
337
 
338
  function _ready() {
@@ -345,6 +366,7 @@
345
  initTooltips();
346
  initSelect2();
347
  makePaymentsSortable();
 
348
 
349
  $doc.on('click', '.change-email-status', updateEmailStatus)
350
  .on('click', '#learn-press-enable-emails, #learn-press-disable-emails', toggleEmails)
333
  });
334
  }
335
 
336
+ function initSingleCoursePermalink() {
337
+ $doc.on('change', '.learn-press-single-course-permalink input[type="radio"]', function () {
338
+ var $check = $(this),
339
+ $row = $check.closest('.learn-press-single-course-permalink');
340
+ if ($row.hasClass('custom-base')) {
341
+ $row.find('input[type="text"]').prop('readonly', false);
342
+ } else {
343
+ $row.siblings('.custom-base').find('input[type="text"]').prop('readonly', true);
344
+ }
345
+ })
346
+ .on('change', 'input.learn-press-course-base', function () {
347
+ $('#course_permalink_structure').val($(this).val());
348
+ })
349
+ .on('focus', '#course_permalink_structure', function () {
350
+ $('#learn_press_custom_permalink').click();
351
+ })
352
+ .on('change', '#learn_press_courses_page_id', function () {
353
+ $('tr.learn-press-courses-page-id').toggleClass('hide-if-js', !parseInt(this.value))
354
+ });
355
+ }
356
+
357
  var $doc = $(document);
358
 
359
  function _ready() {
366
  initTooltips();
367
  initSelect2();
368
  makePaymentsSortable();
369
+ initSingleCoursePermalink();
370
 
371
  $doc.on('click', '.change-email-status', updateEmailStatus)
372
  .on('click', '#learn-press-enable-emails, #learn-press-disable-emails', toggleEmails)
assets/js/admin/update.js CHANGED
@@ -33,7 +33,7 @@
33
  context: context
34
  },
35
  success: function (res) {
36
- var $msg = $('<div class="notice notice-success"><p>' + $(res).text() + '</p></div>');
37
  if (context == 'message') {
38
  $btn.closest('.notice').replaceWith($msg);
39
  } else {
33
  context: context
34
  },
35
  success: function (res) {
36
+ var $msg = $('<div class="notice notice-success"><p>' + $(res).find('#message-success').text() + '</p></div>');
37
  if (context == 'message') {
38
  $btn.closest('.notice').replaceWith($msg);
39
  } else {
inc/abstracts/abstract-assets.php CHANGED
@@ -302,7 +302,7 @@ abstract class LP_Abstract_Assets {
302
  if ( isset( $wp_scripts->registered[ $handle ] ) ) {
303
  if ( isset( $wp_scripts->registered[ $handle ]->extra['data'] ) ) {
304
  if ( $data = $wp_scripts->registered[ $handle ]->extra['data'] ) {
305
- $data = preg_replace_callback( '~:"([0-9.,]+|true|false)"~', array(
306
  $this,
307
  '_valid_json_number'
308
  ), $data );
302
  if ( isset( $wp_scripts->registered[ $handle ] ) ) {
303
  if ( isset( $wp_scripts->registered[ $handle ]->extra['data'] ) ) {
304
  if ( $data = $wp_scripts->registered[ $handle ]->extra['data'] ) {
305
+ $data = preg_replace_callback( '~:"(([0-9]+)([.,]?)([0-9]?)|true|false)"~', array(
306
  $this,
307
  '_valid_json_number'
308
  ), $data );
inc/admin/class-lp-install-sample-data.php CHANGED
@@ -55,6 +55,11 @@ class LP_Install_Sample_Data {
55
  }
56
 
57
  public function i18n( $data, $handle ) {
 
 
 
 
 
58
  $i18n = array(
59
  'confirm_install_sample_data' => __( 'Are you sure you want to install sample course data?', 'learnpress' ),
60
  'confirm_uninstall_sample_data' => __( 'Are you sure you want to delete sample course data?', 'learnpress' )
@@ -110,7 +115,9 @@ class LP_Install_Sample_Data {
110
  unset( $wp_filter[ $key ] );
111
  }
112
 
113
- if ( ! $course_id = $this->create_course() ) {
 
 
114
  throw new Exception( 'Create course failed' );
115
  }
116
 
@@ -128,7 +135,8 @@ class LP_Install_Sample_Data {
128
 
129
  LP_Debug::commitTransaction();
130
 
131
- } catch ( Exception $ex ) {
 
132
  LP_Debug::rollbackTransaction();
133
 
134
  echo $ex->getMessage();
@@ -169,7 +177,8 @@ class LP_Install_Sample_Data {
169
 
170
  $this->_delete_post( $post->ID );
171
  }
172
- } catch ( Exception $ex ) {
 
173
  LP_Debug::rollbackTransaction();
174
  echo "Error: " . $ex->getMessage();
175
  }
@@ -283,12 +292,14 @@ class LP_Install_Sample_Data {
283
  /**
284
  * Create course.
285
  *
 
 
286
  * @return int|WP_Error
287
  */
288
- protected function create_course() {
289
 
290
  $data = array(
291
- 'post_title' => 'Sample course',
292
  'post_type' => LP_COURSE_CPT,
293
  'post_status' => 'publish',
294
  'post_content' => $this->generate_content()
@@ -341,7 +352,7 @@ class LP_Install_Sample_Data {
341
  * Create section.
342
  *
343
  * @param string $name
344
- * @param int $course_id
345
  *
346
  * @return int
347
  */
@@ -402,8 +413,8 @@ class LP_Install_Sample_Data {
402
  * Create lesson.
403
  *
404
  * @param string $name
405
- * @param int $section_id
406
- * @param int $course_id
407
  *
408
  * @return int|WP_Error
409
  */
@@ -443,8 +454,8 @@ class LP_Install_Sample_Data {
443
  * Create quiz.
444
  *
445
  * @param string $name
446
- * @param int $section_id
447
- * @param int $course_id
448
  *
449
  * @return int|WP_Error
450
  */
@@ -546,7 +557,7 @@ class LP_Install_Sample_Data {
546
  /**
547
  * Create answers for a question.
548
  *
549
- * @param int $question_id
550
  * @param string $type
551
  */
552
  protected function create_question_answers( $question_id, $type ) {
55
  }
56
 
57
  public function i18n( $data, $handle ) {
58
+
59
+ if ( 'learn-press-global' !== $handle ) {
60
+ return $data;
61
+ }
62
+
63
  $i18n = array(
64
  'confirm_install_sample_data' => __( 'Are you sure you want to install sample course data?', 'learnpress' ),
65
  'confirm_uninstall_sample_data' => __( 'Are you sure you want to delete sample course data?', 'learnpress' )
115
  unset( $wp_filter[ $key ] );
116
  }
117
 
118
+ $name = LP_Request::get_string( 'custom-name' );
119
+
120
+ if ( ! $course_id = $this->create_course( $name ) ) {
121
  throw new Exception( 'Create course failed' );
122
  }
123
 
135
 
136
  LP_Debug::commitTransaction();
137
 
138
+ }
139
+ catch ( Exception $ex ) {
140
  LP_Debug::rollbackTransaction();
141
 
142
  echo $ex->getMessage();
177
 
178
  $this->_delete_post( $post->ID );
179
  }
180
+ }
181
+ catch ( Exception $ex ) {
182
  LP_Debug::rollbackTransaction();
183
  echo "Error: " . $ex->getMessage();
184
  }
292
  /**
293
  * Create course.
294
  *
295
+ * @param string $name
296
+ *
297
  * @return int|WP_Error
298
  */
299
+ protected function create_course( $name = '' ) {
300
 
301
  $data = array(
302
+ 'post_title' => strlen( $name ) ? $name : __( 'Sample course', 'learnpress' ),
303
  'post_type' => LP_COURSE_CPT,
304
  'post_status' => 'publish',
305
  'post_content' => $this->generate_content()
352
  * Create section.
353
  *
354
  * @param string $name
355
+ * @param int $course_id
356
  *
357
  * @return int
358
  */
413
  * Create lesson.
414
  *
415
  * @param string $name
416
+ * @param int $section_id
417
+ * @param int $course_id
418
  *
419
  * @return int|WP_Error
420
  */
454
  * Create quiz.
455
  *
456
  * @param string $name
457
+ * @param int $section_id
458
+ * @param int $course_id
459
  *
460
  * @return int|WP_Error
461
  */
557
  /**
558
  * Create answers for a question.
559
  *
560
+ * @param int $question_id
561
  * @param string $type
562
  */
563
  protected function create_question_answers( $question_id, $type ) {
inc/admin/class-lp-modal-search-items.php CHANGED
@@ -215,6 +215,7 @@ if ( ! class_exists( 'LP_Modal_Search_Items' ) ) {
215
  $pagination = paginate_links( $pagination );
216
  }
217
  }
 
218
  }
219
 
220
  return $pagination;
215
  $pagination = paginate_links( $pagination );
216
  }
217
  }
218
+ $this->_changed = false;
219
  }
220
 
221
  return $pagination;
inc/admin/class-lp-updater.php CHANGED
@@ -39,6 +39,8 @@ class LP_Updater {
39
  $file = LP_PLUGIN_PATH . '/inc/updates/' . $file;
40
 
41
  include_once $file;
 
 
42
  }
43
 
44
  LP_Install::update_version();
@@ -54,8 +56,9 @@ class LP_Updater {
54
 
55
  if ( ! learn_press_message_count() ) {
56
  LP_Debug::commitTransaction();
57
-
58
  learn_press_display_message( __( 'Successfully updated your database.', 'learnpress' ) );
 
59
  } else {
60
  LP_Debug::rollbackTransaction();
61
 
@@ -93,7 +96,7 @@ class LP_Updater {
93
  require_once ABSPATH . 'wp-admin/includes/file.php';
94
  if ( WP_Filesystem() ) {
95
  global $wp_filesystem;
96
- if ( $files = $wp_filesystem->dirlist( LP_PLUGIN_PATH . '/inc/updates' ) ) {
97
  foreach ( $files as $file ) {
98
  if ( preg_match( '!learnpress-update-([0-9.]+).php!', $file['name'], $matches ) ) {
99
  $this->_update_files [ $matches[1] ] = $file['name'];
39
  $file = LP_PLUGIN_PATH . '/inc/updates/' . $file;
40
 
41
  include_once $file;
42
+
43
+ echo sprintf( __( "<p>Updated version %s</p>", 'learnpress' ), $version ) . "\n";
44
  }
45
 
46
  LP_Install::update_version();
56
 
57
  if ( ! learn_press_message_count() ) {
58
  LP_Debug::commitTransaction();
59
+ echo '<div id="message-success">';
60
  learn_press_display_message( __( 'Successfully updated your database.', 'learnpress' ) );
61
+ echo '</div>';
62
  } else {
63
  LP_Debug::rollbackTransaction();
64
 
96
  require_once ABSPATH . 'wp-admin/includes/file.php';
97
  if ( WP_Filesystem() ) {
98
  global $wp_filesystem;
99
+ if ( $files = $wp_filesystem->dirlist( LP_PLUGIN_PATH . 'inc/updates' ) ) {
100
  foreach ( $files as $file ) {
101
  if ( preg_match( '!learnpress-update-([0-9.]+).php!', $file['name'], $matches ) ) {
102
  $this->_update_files [ $matches[1] ] = $file['name'];
inc/admin/lp-admin-functions.php CHANGED
@@ -2200,4 +2200,26 @@ function learn_press_modal_search_items_context( $context_id, $context ) {
2200
  return $context_id;
2201
  }
2202
 
2203
- add_filter( 'learn-press/modal-search-items/context-id', 'learn_press_modal_search_items_context', 10, 2 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2200
  return $context_id;
2201
  }
2202
 
2203
+ add_filter( 'learn-press/modal-search-items/context-id', 'learn_press_modal_search_items_context', 10, 2 );
2204
+
2205
+ /**
2206
+ * Filter to post link to change the link if it is an item inside course.
2207
+ *
2208
+ * @since 3.0.0
2209
+ *
2210
+ * @param string $link
2211
+ * @param WP_Post $post
2212
+ *
2213
+ * @return string
2214
+ */
2215
+ function learn_press_preview_post_link( $link, $post ) {
2216
+ $items = learn_press_course_get_support_item_types( true );
2217
+
2218
+ if ( in_array( $post->post_type, $items ) ) {
2219
+ $link = learn_press_course_item_type_link($link, $post);
2220
+ }
2221
+
2222
+ return $link;
2223
+ }
2224
+
2225
+ add_filter( 'preview_post_link', 'learn_press_preview_post_link', 10, 2 );
inc/admin/meta-box/fields/course-permalink.php ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class RWMB_Course_Permalink_Field extends RWMB_Field {
4
+ public static function html( $meta, $field ) {
5
+ $meta = self::sanitize_meta( $meta );
6
+ // default value
7
+
8
+ flush_rewrite_rules();
9
+ ob_start();
10
+
11
+ $settings = LP()->settings;
12
+ global $wp_post_types;
13
+ if ( ! empty( $wp_post_types[ LP_COURSE_CPT ] ) ) {
14
+ $course_type = $wp_post_types[ LP_COURSE_CPT ];
15
+ $default_courses_slug = $course_type->rewrite['slug'];
16
+ } else {
17
+ $default_courses_slug = '';
18
+ }
19
+
20
+ $course_permalink = $settings->get( 'course_base' );
21
+ $courses_page_id = learn_press_get_page_id( 'courses' );
22
+ $base_slug = urldecode( ( $courses_page_id > 0 && get_post( $courses_page_id ) ) ? get_page_uri( $courses_page_id ) : _x( 'courses', 'default-slug', 'learnpress' ) );
23
+ $course_base = _x( 'course', 'default-slug', 'learnpress' );
24
+
25
+ /*if ( !$course_permalink ) {
26
+ global $wpdb;
27
+ if ( $wpdb->get_results( $wpdb->prepare( "SELECT count(option_id) FROM {$wpdb->options} WHERE option_name = %s", 'learn_press_course_base' ) ) == 0 ) {
28
+ //$course_permalink = '/courses';
29
+ }
30
+ }*/
31
+ $structures = array(
32
+ 0 => array(
33
+ 'value' => '',
34
+ 'text' => __( 'Default', 'learnpress' ),
35
+ 'code' => esc_html( home_url() ) . '/?lp_course=sample-course'
36
+ ),
37
+ 1 => array(
38
+ 'value' => '/' . trailingslashit( $course_base ),
39
+ 'text' => __( 'Course', 'learnpress' ),
40
+ 'code' => esc_html( sprintf( '%s/%s/sample-course/', home_url(), $course_base ) )
41
+ ),
42
+ 2 => array(
43
+ 'value' => '/' . trailingslashit( $base_slug ),
44
+ 'text' => __( 'Courses base', 'learnpress' ),
45
+ 'code' => esc_html( sprintf( '%s/%s/sample-course/', home_url(), $base_slug ) )
46
+ ),
47
+ 3 => array(
48
+ 'value' => '/' . trailingslashit( $base_slug ) . trailingslashit( '%course_category%' ),
49
+ 'text' => __( 'Courses base with category', 'learnpress' ),
50
+ 'code' => esc_html( sprintf( '%s/%s/course-category/sample-course/', home_url(), $base_slug ) )
51
+ )
52
+ );
53
+
54
+ $base_type = get_option( 'learn_press_course_base_type' );
55
+ $is_custom = ( $base_type == 'custom' && $course_permalink != '' );
56
+ ?>
57
+ <ul>
58
+ <?php foreach ( $structures as $k => $structure ): ?>
59
+ <li class="learn-press-single-course-permalink<?php if ( $k == 2 || $k == 3 ) {
60
+ echo ' learn-press-courses-page-id';
61
+ echo ! $courses_page_id ? ' hide-if-js' : '';
62
+ }; ?>">
63
+ <?php
64
+ $is_checked = ( $course_permalink == '' && $structure['value'] == '' ) || ( $structure['value'] == trailingslashit( $course_permalink ) );
65
+ $is_checked = checked( $is_checked, true, false );
66
+ if ( $is_custom && $is_checked ) {
67
+ $is_custom = false;
68
+ }
69
+ ?>
70
+ <label>
71
+ <input name="<?php echo $field['id']; ?>" type="radio"
72
+ value="<?php echo esc_attr( $structure['value'] ); ?>"
73
+ class="learn-press-course-base" <?php echo $is_checked; ?> />
74
+ <?php echo $structure['text']; ?>
75
+ <p><code><?php echo $structure['code']; ?></code></p>
76
+ </label>
77
+ </li>
78
+ <?php endforeach; ?>
79
+ <li class="learn-press-single-course-permalink custom-base">
80
+ <label>
81
+ <input name="<?php echo $field['id']; ?>"
82
+ id="learn_press_custom_permalink" type="radio"
83
+ value="custom" <?php checked( $is_custom, true ); ?> />
84
+ <?php _e( 'Custom Base', 'learnpress' ); ?>
85
+ <input name="course_permalink_structure" id="course_permalink_structure" <?php if ( ! $is_custom ) {
86
+ echo 'readonly="readonly"';
87
+ } ?> type="text" value="<?php if ( $course_permalink ) {
88
+ echo esc_attr( trailingslashit( $course_permalink ) );
89
+ } ?>" class="regular-text code"/>
90
+ </label>
91
+
92
+ <p class="description"><?php _e( 'Enter a custom base to use. A base <strong>must</strong> be set or WordPress will use default values instead.', 'learnpress' ); ?></p>
93
+ </li>
94
+ </ul>
95
+ <?php
96
+ return ob_get_clean();
97
+ }
98
+
99
+ public static function sanitize_meta( $meta ) {
100
+ return $meta;
101
+ }
102
+ }
inc/admin/settings/class-lp-settings-courses.php CHANGED
@@ -127,11 +127,7 @@ class LP_Settings_Courses extends LP_Abstract_Settings_Page {
127
  'type' => 'heading',
128
  'desc' => __( 'Those settings are applied to single course page.', 'learnpress' )
129
  ),
130
- array(
131
- 'title' => __( 'Single course permalink', 'learnpress' ),
132
- 'type' => 'course-permalink',
133
- 'default' => ''
134
- ),
135
  array(
136
  'title' => __( 'Course category base', 'learnpress' ),
137
  'id' => 'course_category_base',
@@ -144,6 +140,12 @@ class LP_Settings_Courses extends LP_Abstract_Settings_Page {
144
  'default' => 'course-tag',
145
  'type' => 'text'
146
  ),
 
 
 
 
 
 
147
  array(
148
  'title' => __( 'Lesson', 'learnpress' ),
149
  'type' => 'text',
127
  'type' => 'heading',
128
  'desc' => __( 'Those settings are applied to single course page.', 'learnpress' )
129
  ),
130
+
 
 
 
 
131
  array(
132
  'title' => __( 'Course category base', 'learnpress' ),
133
  'id' => 'course_category_base',
140
  'default' => 'course-tag',
141
  'type' => 'text'
142
  ),
143
+ array(
144
+ 'title' => __( 'Single course permalink', 'learnpress' ),
145
+ 'type' => 'course-permalink',
146
+ 'default' => '',
147
+ 'id' => 'course_base'
148
+ ),
149
  array(
150
  'title' => __( 'Lesson', 'learnpress' ),
151
  'type' => 'text',
inc/admin/views/meta-boxes/order/actions.php CHANGED
@@ -9,33 +9,7 @@
9
  defined( 'ABSPATH' ) || exit();
10
  ?>
11
 
12
- <?php
13
- global $post, $action;
14
- $post_type = $post->post_type;
15
- $post_type_object = get_post_type_object( $post_type );
16
- $can_publish = current_user_can( $post_type_object->cap->publish_posts );
17
- $datef = __( 'M j, Y @ H:i' );
18
- ?>
19
-
20
- <?php
21
- if ( 0 != $post->ID ) {
22
- if ( 'future' == $post->post_status ) { // scheduled for publishing at a future date
23
- $stamp = __( 'Scheduled for: <b>%1$s</b>' );
24
- } elseif ( 'publish' == $post->post_status || 'private' == $post->post_status ) { // already published
25
- $stamp = __( 'Order date: <b>%1$s</b>' );
26
- } elseif ( '0000-00-00 00:00:00' == $post->post_date_gmt ) { // draft, 1 or more saves, no date specified
27
- $stamp = __( 'Publish <b>immediately</b>' );
28
- } elseif ( time() < strtotime( $post->post_date_gmt . ' +0000' ) ) { // draft, 1 or more saves, future date specified
29
- $stamp = __( 'Schedule for: <b>%1$s</b>' );
30
- } else { // draft, 1 or more saves, date specified
31
- $stamp = __( 'Publish on: <b>%1$s</b>' );
32
- }
33
- $date = date_i18n( $datef, strtotime( $post->post_date ) );
34
- } else { // draft (no saves, and thus no date specified)
35
- $stamp = __( 'Publish <b>immediately</b>' );
36
- $date = date_i18n( $datef, strtotime( current_time( 'mysql' ) ) );
37
- }
38
- ?>
39
 
40
  <div class="submitbox" id="submitpost">
41
  <div id="minor-publishing">
@@ -46,81 +20,6 @@ if ( 0 != $post->ID ) {
46
  <option value="current-status"><?php _e( 'Trigger action of current order status', 'learnpress' ); ?></option>
47
  </select>
48
  </div>
49
- <?php if ( $can_publish ) : // Contributors don't get to choose the date of publish ?>
50
- <?php if ( 0 == 1 ) { ?>
51
-
52
- <div class="misc-pub-section">
53
- <label>
54
- <?php _e( 'Order status', 'learnpress' ); ?>
55
- </label>
56
- <select name="order-status" data-status="<?php echo 'lp-' . $order->get_status(); ?>">
57
- <?php
58
- $statuses = learn_press_get_order_statuses();
59
- foreach ( $statuses as $status => $status_name ) {
60
- echo '<option data-desc="' . esc_attr( _learn_press_get_order_status_description( $status ) ) . '" value="' . esc_attr( $status ) . '" ' . selected( $status, 'lp-' . $order->get_status(), false ) . '>' . esc_html( $status_name ) . '</option>';
61
- }
62
- ?>
63
- </select>
64
-
65
- <div class="description order-status-description">
66
- <?php if ( $order->get_status() == 'auto-draft' ) {
67
- echo _learn_press_get_order_status_description( 'lp-pending' );
68
- } ?>
69
- <?php echo _learn_press_get_order_status_description( 'lp-' . $order->get_status() ); ?>
70
- </div>
71
- </div>
72
- <div class="misc-pub-section hide-if-js order-action-section">
73
- <label for="trigger-order-action">
74
- <input type="checkbox" name="trigger-order-action" id="trigger-order-action" value="yes"/>
75
- <?php _e( 'Trigger order status action', 'learnpress' ); ?>
76
- </label>
77
- <p class="description"><?php esc_attr_e( 'Check this option to force an action to be triggered. Normally, an action is triggered only after the order status was changed.', 'learnpress' ); ?></p>
78
- </div>
79
- <div class="misc-pub-section">
80
- <label>
81
- <?php _e( 'Customer', 'learnpress' ); ?>
82
- </label>
83
- <?php
84
- if ( $order->is_multi_users() ) {
85
- $order->dropdown_users();
86
- ?>
87
- <input type="hidden" name="multi-users" value="yes"/>
88
- <?php
89
- wp_enqueue_style( 'select2', RWMB_CSS_URL . 'select2/select2.css' );
90
- wp_enqueue_script( 'select2', RWMB_JS_URL . 'select2/select2.min.js' );
91
- } else {
92
- wp_dropdown_users(
93
- array(
94
- 'show_option_none' => __( '[Guest]', 'learnpress' ),
95
- 'name' => 'order-customer',
96
- 'id' => null,
97
- 'selected' => $order->get_user( 'id' )
98
- )
99
- );
100
- }
101
- if ( $order->get_status() == 'auto-draft' && ! $order->is_multi_users() ) {
102
- ?>
103
- --
104
- <a href="<?php echo add_query_arg( 'multi-users', 'yes' ); ?>"><?php _e( 'Multiple users', 'learnpress' ); ?></a>
105
- <?php
106
- }
107
- // }else{
108
- // echo $order->get_customer_name();
109
- // }
110
- ?>
111
- </div>
112
-
113
- <div class="misc-pub-section curtime misc-pub-curtime">
114
- <span id="timestamp"><?php printf( $stamp, $date ); ?></span>
115
- <a href="#edit_timestamp" class="edit-timestamp hide-if-no-js"><span
116
- aria-hidden="true"><?php _e( 'Edit' ); ?></span>
117
- <span class="screen-reader-text"><?php _e( 'Edit date and time' ); ?></span></a>
118
- <fieldset id="timestampdiv" class="hide-if-js">
119
- <legend class="screen-reader-text"><?php _e( 'Date and time' ); ?></legend>
120
- <?php touch_time( ( $action === 'edit' ), 1 ); ?>
121
- </fieldset>
122
- </div><?php // /misc-pub-section ?><?php } ?>
123
- <?php endif; ?>
124
  </div>
125
  <div id="major-publishing-actions">
126
  <div id="delete-action">
@@ -130,8 +29,7 @@ if ( 0 != $post->ID ) {
130
  $delete_text = __( 'Delete Permanently' );
131
  } else {
132
  $delete_text = __( 'Move to Trash' );
133
- }
134
- ?>
135
  <a class="submitdelete deletion" href="<?php echo get_delete_post_link( $post->ID ); ?>">
136
  <?php echo $delete_text; ?>
137
  </a>
9
  defined( 'ABSPATH' ) || exit();
10
  ?>
11
 
12
+ <?php global $post; ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
  <div class="submitbox" id="submitpost">
15
  <div id="minor-publishing">
20
  <option value="current-status"><?php _e( 'Trigger action of current order status', 'learnpress' ); ?></option>
21
  </select>
22
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  </div>
24
  <div id="major-publishing-actions">
25
  <div id="delete-action">
29
  $delete_text = __( 'Delete Permanently' );
30
  } else {
31
  $delete_text = __( 'Move to Trash' );
32
+ } ?>
 
33
  <a class="submitdelete deletion" href="<?php echo get_delete_post_link( $post->ID ); ?>">
34
  <?php echo $delete_text; ?>
35
  </a>
inc/admin/views/tools/database/html-install-sample-data.php CHANGED
@@ -17,7 +17,13 @@ $answer_range = LP_Install_Sample_Data::$answer_range;
17
  <p><?php _e( 'Create a <strong>Sample course</strong> with lessons and quizzes. The content will be filled with <strong>Lorem</strong> text.', 'learnpress' ); ?></p>
18
  <fieldset class="lp-install-sample-data-options hide-if-js">
19
  <legend><?php esc_html_e( 'Options', 'learnpress' ); ?></legend>
 
20
  <ul>
 
 
 
 
 
21
  <li>
22
  <p><?php esc_html_e( 'Random number of sections in range', 'learnpress' ); ?></p>
23
  <input type="number" size="3" value="<?php echo $section_range[0]; ?>" min="1" max="20"
17
  <p><?php _e( 'Create a <strong>Sample course</strong> with lessons and quizzes. The content will be filled with <strong>Lorem</strong> text.', 'learnpress' ); ?></p>
18
  <fieldset class="lp-install-sample-data-options hide-if-js">
19
  <legend><?php esc_html_e( 'Options', 'learnpress' ); ?></legend>
20
+
21
  <ul>
22
+ <li>
23
+ <p><?php esc_html_e( 'Course name', 'learnpress' ); ?></p>
24
+ <input type="text" class="widefat" name="custom-name" value=""
25
+ placeholder="<?php esc_attr_e( 'Sample course', 'learnpress' ); ?>">
26
+ </li>
27
  <li>
28
  <p><?php esc_html_e( 'Random number of sections in range', 'learnpress' ); ?></p>
29
  <input type="number" size="3" value="<?php echo $section_range[0]; ?>" min="1" max="20"
inc/class-lp-helper.php CHANGED
@@ -208,7 +208,7 @@ class LP_Helper {
208
  */
209
  public static function json_encode( $data ) {
210
  $data = wp_json_encode( $data );
211
- $data = preg_replace_callback( '~:"([0-9.,]+|true|false)"~', array(
212
  __CLASS__,
213
  '_valid_json_value'
214
  ), $data );
208
  */
209
  public static function json_encode( $data ) {
210
  $data = wp_json_encode( $data );
211
+ $data = preg_replace_callback( '~:"(([0-9]+)([.,]?)([0-9]?)|true|false)"~', array(
212
  __CLASS__,
213
  '_valid_json_value'
214
  ), $data );
inc/class-lp-install.php CHANGED
@@ -51,7 +51,6 @@ if ( ! function_exists( 'LP_Install' ) ) {
51
 
52
  //add_action( 'learn_press_activate', array( __CLASS__, 'install' ) );
53
 
54
-
55
  return;
56
  add_action( 'admin_init', array( __CLASS__, 'include_update' ), - 10 );
57
  add_action( 'admin_init', array( __CLASS__, 'update_from_09' ), 5 );
51
 
52
  //add_action( 'learn_press_activate', array( __CLASS__, 'install' ) );
53
 
 
54
  return;
55
  add_action( 'admin_init', array( __CLASS__, 'include_update' ), - 10 );
56
  add_action( 'admin_init', array( __CLASS__, 'update_from_09' ), 5 );
inc/class-lp-page-controller.php CHANGED
@@ -367,7 +367,7 @@ class LP_Page_Controller {
367
  if ( empty( $wp->query_vars['user'] ) ) {
368
  $viewing_user = $current_user;
369
  } else {
370
- if ( $wp_user = get_user_by( 'login', $wp->query_vars['user'] ) ) {
371
  $viewing_user = learn_press_get_user( $wp_user->ID );
372
  if ( $viewing_user->is_guest() ) {
373
  $viewing_user = false;
@@ -500,7 +500,8 @@ class LP_Page_Controller {
500
  if ( is_post_type_archive( LP_COURSE_CPT ) || LEARNPRESS_IS_CATEGORY ) {
501
  $wp_query->is_page = false;
502
  $wp_query->is_archive = true;
503
- $wp_query->is_category = true;
 
504
  $wp_query->is_single = false;
505
  } else {
506
  $wp_query->found_posts = 1;
@@ -598,7 +599,7 @@ class LP_Page_Controller {
598
  // Example: http://example.com/lesson/sample-lesson
599
  $course_support_items = learn_press_get_course_item_types();
600
 
601
- if ( isset($q->query_vars['post_type']) && in_array( $q->query_vars['post_type'], $course_support_items ) ) {
602
  learn_press_404_page();
603
  $q->set( 'post_type', '__unknown' );
604
 
367
  if ( empty( $wp->query_vars['user'] ) ) {
368
  $viewing_user = $current_user;
369
  } else {
370
+ if ( $wp_user = get_user_by( 'login', urldecode( $wp->query_vars['user'] ) ) ) {
371
  $viewing_user = learn_press_get_user( $wp_user->ID );
372
  if ( $viewing_user->is_guest() ) {
373
  $viewing_user = false;
500
  if ( is_post_type_archive( LP_COURSE_CPT ) || LEARNPRESS_IS_CATEGORY ) {
501
  $wp_query->is_page = false;
502
  $wp_query->is_archive = true;
503
+ // Fixed issue with Yoast Seo plugin
504
+ //$wp_query->is_category = true;
505
  $wp_query->is_single = false;
506
  } else {
507
  $wp_query->found_posts = 1;
599
  // Example: http://example.com/lesson/sample-lesson
600
  $course_support_items = learn_press_get_course_item_types();
601
 
602
+ if ( isset( $q->query_vars['post_type'] ) && in_array( $q->query_vars['post_type'], $course_support_items ) ) {
603
  learn_press_404_page();
604
  $q->set( 'post_type', '__unknown' );
605
 
inc/class-lp-query.php CHANGED
@@ -115,7 +115,7 @@ class LP_Query {
115
 
116
  $rewrite_prefix = get_option( 'learn_press_permalink_structure' );
117
  // lesson
118
- $course_type = 'lp_course';
119
  $post_types = get_post_types( '', 'objects' );
120
  $slug = preg_replace( '!^/!', '', $post_types[ $course_type ]->rewrite['slug'] );
121
  $has_category = false;
@@ -154,18 +154,18 @@ class LP_Query {
154
  );
155
 
156
  /* Test */
157
- if ( $popup_slug ) {
158
- add_rewrite_rule(
159
- '^' . $slug . '/(' . $popup_slug . ')(?:/' . $post_types['lp_lesson']->rewrite['slug'] . '/([^/]+))/?$',
160
- 'index.php?content-item-only=yes&' . $course_type . '=$matches[3]&course_category=$matches[2]&course-item=$matches[4]&item-type=lp_lesson',
161
- 'top'
162
- );
163
- add_rewrite_rule(
164
- '^' . $slug . '/(' . $popup_slug . ')(?:/' . $post_types['lp_quiz']->rewrite['slug'] . '/([^/]+)/?([^/]+)?)/?$',
165
- 'index.php?content-item-only=yes&' . $course_type . '=$matches[3]&course_category=$matches[2]&course-item=$matches[4]&question=$matches[5]&item-type=lp_quiz',
166
- 'top'
167
- );
168
- }
169
  } else {
170
 
171
  add_rewrite_rule(
@@ -180,18 +180,18 @@ class LP_Query {
180
  );
181
 
182
  /* Test */
183
- if ( $popup_slug ) {
184
- add_rewrite_rule(
185
- '^' . $slug . '/(' . $popup_slug . ')/([^/]+)(?:/' . $post_types['lp_lesson']->rewrite['slug'] . '/([^/]+))/?$',
186
- 'index.php?content-item-only=yes&' . $course_type . '=$matches[2]&course-item=$matches[3]&item-type=lp_lesson',
187
- 'top'
188
- );
189
- add_rewrite_rule(
190
- '^' . $slug . '/(' . $popup_slug . ')/([^/]+)(?:/' . $post_types['lp_quiz']->rewrite['slug'] . '/([^/]+)/?([^/]+)?)/?$',
191
- 'index.php?content-item-only=yes&' . $course_type . '=$matches[2]&course-item=$matches[3]&question=$matches[4]&item-type=lp_quiz',
192
- 'top'
193
- );
194
- }
195
  }
196
 
197
  // Profile
115
 
116
  $rewrite_prefix = get_option( 'learn_press_permalink_structure' );
117
  // lesson
118
+ $course_type = LP_COURSE_CPT;
119
  $post_types = get_post_types( '', 'objects' );
120
  $slug = preg_replace( '!^/!', '', $post_types[ $course_type ]->rewrite['slug'] );
121
  $has_category = false;
154
  );
155
 
156
  /* Test */
157
+ // if ( $popup_slug ) {
158
+ // add_rewrite_rule(
159
+ // '^' . $slug . '/(' . $popup_slug . ')(?:/' . $post_types['lp_lesson']->rewrite['slug'] . '/([^/]+))/?$',
160
+ // 'index.php?content-item-only=yes&' . $course_type . '=$matches[3]&course_category=$matches[2]&course-item=$matches[4]&item-type=lp_lesson',
161
+ // 'top'
162
+ // );
163
+ // add_rewrite_rule(
164
+ // '^' . $slug . '/(' . $popup_slug . ')(?:/' . $post_types['lp_quiz']->rewrite['slug'] . '/([^/]+)/?([^/]+)?)/?$',
165
+ // 'index.php?content-item-only=yes&' . $course_type . '=$matches[3]&course_category=$matches[2]&course-item=$matches[4]&question=$matches[5]&item-type=lp_quiz',
166
+ // 'top'
167
+ // );
168
+ // }
169
  } else {
170
 
171
  add_rewrite_rule(
180
  );
181
 
182
  /* Test */
183
+ // if ( $popup_slug ) {
184
+ // add_rewrite_rule(
185
+ // '^' . $slug . '/(' . $popup_slug . ')/([^/]+)(?:/' . $post_types['lp_lesson']->rewrite['slug'] . '/([^/]+))/?$',
186
+ // 'index.php?content-item-only=yes&' . $course_type . '=$matches[2]&course-item=$matches[3]&item-type=lp_lesson',
187
+ // 'top'
188
+ // );
189
+ // add_rewrite_rule(
190
+ // '^' . $slug . '/(' . $popup_slug . ')/([^/]+)(?:/' . $post_types['lp_quiz']->rewrite['slug'] . '/([^/]+)/?([^/]+)?)/?$',
191
+ // 'index.php?content-item-only=yes&' . $course_type . '=$matches[2]&course-item=$matches[3]&question=$matches[4]&item-type=lp_quiz',
192
+ // 'top'
193
+ // );
194
+ // }
195
  }
196
 
197
  // Profile
inc/class-lp-settings.php CHANGED
@@ -51,7 +51,14 @@ class LP_Settings {
51
  settype( $data, 'array' );
52
  $this->_options = $data;
53
  }
 
 
 
 
 
54
 
 
 
55
  }
56
 
57
  /**
@@ -117,7 +124,7 @@ class LP_Settings {
117
  $current_var = array_shift( $var );
118
  if ( is_object( $obj ) ) {
119
  if ( isset( $obj->{$current_var} ) ) {
120
- $obj->{$current_var} = maybe_unserialize($obj->{$current_var});
121
  if ( count( $var ) ) {
122
  $this->_set_option( $obj->{$current_var}, join( '.', $var ), $value );
123
  } else {
@@ -128,7 +135,7 @@ class LP_Settings {
128
  }
129
  } else {
130
  if ( isset( $obj[ $current_var ] ) ) {
131
- $obj[ $current_var ] = maybe_unserialize($obj[ $current_var ]);
132
  if ( count( $var ) ) {
133
  $this->_set_option( $obj[ $current_var ], join( '.', $var ), $value );
134
  } else {
@@ -177,7 +184,7 @@ class LP_Settings {
177
  $current_var = array_shift( $var );
178
  if ( is_object( $obj ) ) {
179
  if ( isset( $obj->{$current_var} ) ) {
180
- $obj->{$current_var} = maybe_unserialize($obj->{$current_var});
181
  if ( count( $var ) ) {
182
  return $this->_get_option( $obj->{$current_var}, join( '.', $var ), $default );
183
  } else {
@@ -188,7 +195,7 @@ class LP_Settings {
188
  }
189
  } else {
190
  if ( isset( $obj[ $current_var ] ) ) {
191
- $obj[ $current_var ] = maybe_unserialize($obj[ $current_var ]);
192
  if ( count( $var ) ) {
193
  return $this->_get_option( $obj[ $current_var ], join( '.', $var ), $default );
194
  } else {
@@ -262,6 +269,12 @@ class LP_Settings {
262
  * @since 3.0.0
263
  */
264
  public static function load_site_options() {
 
 
 
 
 
 
265
  $options = array(
266
  'pmpro_updates',
267
  'pmpro_stripe_billingaddress',
@@ -326,6 +339,7 @@ class LP_Settings {
326
  }
327
 
328
  wp_cache_set( 'notoptions', $notoptions, 'options' );
 
329
  }
330
 
331
  /**
@@ -393,6 +407,5 @@ class LP_Settings {
393
  }
394
  }
395
 
396
- LP_Settings::load_site_options();
397
 
398
  return LP_Settings::instance();
51
  settype( $data, 'array' );
52
  $this->_options = $data;
53
  }
54
+ self::load_site_options();
55
+ //add_action( 'init', array( $this, 'init' ) );
56
+ }
57
+
58
+ public function init() {
59
 
60
+ LP_Background_Global::add( 'load-site-options', '', array( __CLASS__, 'load_site_options' ) );
61
+ //LP_Settings::load_site_options();
62
  }
63
 
64
  /**
124
  $current_var = array_shift( $var );
125
  if ( is_object( $obj ) ) {
126
  if ( isset( $obj->{$current_var} ) ) {
127
+ $obj->{$current_var} = maybe_unserialize( $obj->{$current_var} );
128
  if ( count( $var ) ) {
129
  $this->_set_option( $obj->{$current_var}, join( '.', $var ), $value );
130
  } else {
135
  }
136
  } else {
137
  if ( isset( $obj[ $current_var ] ) ) {
138
+ $obj[ $current_var ] = maybe_unserialize( $obj[ $current_var ] );
139
  if ( count( $var ) ) {
140
  $this->_set_option( $obj[ $current_var ], join( '.', $var ), $value );
141
  } else {
184
  $current_var = array_shift( $var );
185
  if ( is_object( $obj ) ) {
186
  if ( isset( $obj->{$current_var} ) ) {
187
+ $obj->{$current_var} = maybe_unserialize( $obj->{$current_var} );
188
  if ( count( $var ) ) {
189
  return $this->_get_option( $obj->{$current_var}, join( '.', $var ), $default );
190
  } else {
195
  }
196
  } else {
197
  if ( isset( $obj[ $current_var ] ) ) {
198
+ $obj[ $current_var ] = maybe_unserialize( $obj[ $current_var ] );
199
  if ( count( $var ) ) {
200
  return $this->_get_option( $obj[ $current_var ], join( '.', $var ), $default );
201
  } else {
269
  * @since 3.0.0
270
  */
271
  public static function load_site_options() {
272
+ static $loaded = false;
273
+
274
+ if ( $loaded ) {
275
+ return;
276
+ }
277
+
278
  $options = array(
279
  'pmpro_updates',
280
  'pmpro_stripe_billingaddress',
339
  }
340
 
341
  wp_cache_set( 'notoptions', $notoptions, 'options' );
342
+ $loaded = true;
343
  }
344
 
345
  /**
407
  }
408
  }
409
 
 
410
 
411
  return LP_Settings::instance();
inc/course/abstract-course.php CHANGED
@@ -81,6 +81,8 @@ if ( ! function_exists( 'LP_Abstract_Course' ) ) {
81
  'payment' => ''
82
  );
83
 
 
 
84
  /**
85
  * Constructor gets the post object and sets the ID for the loaded course.
86
  *
@@ -109,6 +111,11 @@ if ( ! function_exists( 'LP_Abstract_Course' ) ) {
109
  * - Curriculum: sections, items, etc...
110
  */
111
  public function load() {
 
 
 
 
 
112
  $this->_curd->load( $this );
113
  $id = $this->get_id();
114
  $post_object = get_post( $id );
@@ -135,6 +142,8 @@ if ( ! function_exists( 'LP_Abstract_Course' ) ) {
135
  'external_link_text' => get_post_meta( $id, '_lp_external_link_text', true ),
136
  )
137
  );
 
 
138
  }
139
 
140
  /**
@@ -356,6 +365,9 @@ if ( ! function_exists( 'LP_Abstract_Course' ) ) {
356
  if ( ! $this->get_id() ) {
357
  return false;
358
  }
 
 
 
359
  $curriculum = $this->_curd->get_curriculum( $this->get_id() );
360
 
361
  $return = false;
@@ -383,6 +395,8 @@ if ( ! function_exists( 'LP_Abstract_Course' ) ) {
383
  */
384
  public function get_items( $type = '', $preview = true ) {
385
 
 
 
386
  // get course items from cache
387
 
388
  if ( ! $type && $preview ) {
81
  'payment' => ''
82
  );
83
 
84
+ protected $_loaded = false;
85
+
86
  /**
87
  * Constructor gets the post object and sets the ID for the loaded course.
88
  *
111
  * - Curriculum: sections, items, etc...
112
  */
113
  public function load() {
114
+
115
+ if ( $this->_loaded ) {
116
+ return;
117
+ }
118
+
119
  $this->_curd->load( $this );
120
  $id = $this->get_id();
121
  $post_object = get_post( $id );
142
  'external_link_text' => get_post_meta( $id, '_lp_external_link_text', true ),
143
  )
144
  );
145
+
146
+ $this->_loaded = true;
147
  }
148
 
149
  /**
365
  if ( ! $this->get_id() ) {
366
  return false;
367
  }
368
+
369
+ $this->load();
370
+
371
  $curriculum = $this->_curd->get_curriculum( $this->get_id() );
372
 
373
  $return = false;
395
  */
396
  public function get_items( $type = '', $preview = true ) {
397
 
398
+ $this->load();
399
+
400
  // get course items from cache
401
 
402
  if ( ! $type && $preview ) {
inc/course/class-lp-course-item.php CHANGED
@@ -104,7 +104,13 @@ if ( ! class_exists( 'LP_Course_Item' ) ) {
104
  * @return bool|false|mixed|string
105
  */
106
  public function get_format() {
107
- return ( false !== ( $format = wp_cache_get( 'item-format-' . $this->get_id(), 'lp-item-formats' ) ) ) ? $format : get_post_format( $this->get_id() );
 
 
 
 
 
 
108
  }
109
 
110
  /**
104
  * @return bool|false|mixed|string
105
  */
106
  public function get_format() {
107
+ $format = ( false !== ( $format = wp_cache_get( 'item-format-' . $this->get_id(), 'lp-item-formats' ) ) ) ? $format : get_post_format( $this->get_id() );
108
+
109
+ if(!$format){
110
+ $format = 'standard';
111
+ }
112
+
113
+ return $format;
114
  }
115
 
116
  /**
inc/course/class-lp-course.php CHANGED
@@ -18,10 +18,6 @@ if ( ! class_exists( 'LP_Course' ) ) {
18
  * Class LP_Course
19
  */
20
  class LP_Course extends LP_Abstract_Course {
21
- /**
22
- * @var int
23
- */
24
- protected static $_loaded = 0;
25
 
26
  /**
27
  * LP_Course constructor.
@@ -30,11 +26,6 @@ if ( ! class_exists( 'LP_Course' ) ) {
30
  */
31
  public function __construct( $course ) {
32
  parent::__construct( $course );
33
-
34
- self::$_loaded ++;
35
- if ( self::$_loaded == 1 ) {
36
- add_filter( 'debug_data', array( __CLASS__, 'log' ) );
37
- }
38
  }
39
 
40
  /**
@@ -45,8 +36,6 @@ if ( ! class_exists( 'LP_Course' ) ) {
45
  * @return array
46
  */
47
  public static function log( $data ) {
48
- $data[] = __CLASS__ . '( ' . self::$_loaded . ' )';
49
-
50
  return $data;
51
  }
52
 
18
  * Class LP_Course
19
  */
20
  class LP_Course extends LP_Abstract_Course {
 
 
 
 
21
 
22
  /**
23
  * LP_Course constructor.
26
  */
27
  public function __construct( $course ) {
28
  parent::__construct( $course );
 
 
 
 
 
29
  }
30
 
31
  /**
36
  * @return array
37
  */
38
  public static function log( $data ) {
 
 
39
  return $data;
40
  }
41
 
inc/curds/class-lp-course-curd.php CHANGED
@@ -221,6 +221,8 @@ if ( ! class_exists( 'LP_Course_CURD' ) ) {
221
  return false;
222
  }
223
 
 
 
224
  /**
225
  * Get course's data from cache and if it is already existed
226
  * then ignore that course.
@@ -236,6 +238,7 @@ if ( ! class_exists( 'LP_Course_CURD' ) ) {
236
  $meta_cache_ids = array( $course_id );
237
  $quiz_ids = array();
238
  $lesson_ids = array();
 
239
  $preview_ids = array();
240
 
241
  $section_ids = array();
@@ -293,20 +296,32 @@ if ( ! class_exists( 'LP_Course_CURD' ) ) {
293
 
294
  $meta_cache_ids[] = $row->item_id;
295
 
296
- if ( $row->item_type === LP_QUIZ_CPT ) {
297
- $quiz_ids[] = $row->item_id;
298
- } elseif ( $row->item_type === LP_LESSON_CPT ) {
299
- $lesson_ids[] = $row->item_id;
 
 
 
 
300
  }
 
301
 
302
  if ( $row->preview === 'yes' ) {
303
  $preview_ids[] = $row->item_id;
304
  }
305
  }
306
 
 
 
 
 
 
 
 
 
 
307
  wp_cache_set( 'course-' . $cur_id, $curriculum, 'lp-course-curriculum' );
308
- wp_cache_set( 'course-' . $cur_id, $quiz_ids, 'lp-course-' . LP_QUIZ_CPT );
309
- wp_cache_set( 'course-' . $cur_id, $lesson_ids, 'lp-course-' . LP_LESSON_CPT );
310
  wp_cache_set( 'course-' . $cur_id, $preview_ids, 'lp-course-preview-items' );
311
 
312
  // Cache items ids for using in some cases
221
  return false;
222
  }
223
 
224
+ //return false;
225
+
226
  /**
227
  * Get course's data from cache and if it is already existed
228
  * then ignore that course.
238
  $meta_cache_ids = array( $course_id );
239
  $quiz_ids = array();
240
  $lesson_ids = array();
241
+ $group_items = array();
242
  $preview_ids = array();
243
 
244
  $section_ids = array();
296
 
297
  $meta_cache_ids[] = $row->item_id;
298
 
299
+ // if ( $row->item_type === LP_QUIZ_CPT ) {
300
+ // $quiz_ids[] = $row->item_id;
301
+ // } elseif ( $row->item_type === LP_LESSON_CPT ) {
302
+ // $lesson_ids[] = $row->item_id;
303
+ // }
304
+
305
+ if ( empty( $group_items[ $row->item_type ] ) ) {
306
+ $group_items[ $row->item_type ] = array();
307
  }
308
+ $group_items[ $row->item_type ][] = $row->item_id;
309
 
310
  if ( $row->preview === 'yes' ) {
311
  $preview_ids[] = $row->item_id;
312
  }
313
  }
314
 
315
+ //wp_cache_set( 'course-' . $cur_id, $quiz_ids, 'lp-course-' . LP_QUIZ_CPT );
316
+ //wp_cache_set( 'course-' . $cur_id, $lesson_ids, 'lp-course-' . LP_LESSON_CPT );
317
+
318
+ if ( $group_items ) {
319
+ foreach ( $group_items as $type => $group_item_ids ) {
320
+ wp_cache_set( 'course-' . $cur_id, $group_item_ids, 'lp-course-' . $type );
321
+ }
322
+ }
323
+
324
  wp_cache_set( 'course-' . $cur_id, $curriculum, 'lp-course-curriculum' );
 
 
325
  wp_cache_set( 'course-' . $cur_id, $preview_ids, 'lp-course-preview-items' );
326
 
327
  // Cache items ids for using in some cases
inc/curds/class-lp-order-curd.php CHANGED
@@ -152,6 +152,7 @@ class LP_Order_CURD extends LP_Object_Data_CURD implements LP_Interface_CURD {
152
  $status = 'pending';
153
  }
154
 
 
155
  $post_data = array(
156
  'post_date' => $order->get_order_date( 'edit' )->toSql(),
157
  'post_date_gmt' => $order->get_order_date( 'edit' )->toSql( false ),
@@ -430,139 +431,139 @@ class LP_Order_CURD extends LP_Object_Data_CURD implements LP_Interface_CURD {
430
  }
431
  }
432
  if ( $post = get_post( $the_id ) ) {
433
- $_users = get_post_meta( $order->get_id(), '_user_id' );
434
- settype( $_users, 'array' );
 
 
 
435
  if ( sizeof( $_users ) > 1 ) {
436
- $users = array();
437
-
438
- foreach ( $_users as $user ) {
439
- $users[] = $user[0];
440
- }
441
  } elseif ( sizeof( $_users ) == 1 ) {
442
  $users = $_users[0];
443
  } else {
444
  $users = 0;
445
  }
446
- $order->set_data_via_methods(
447
- array(
448
- 'user_id' => $users,//get_post_meta( $order->get_id(), '_user_id', true ),
449
- 'order_date' => new LP_Datetime( $post->post_date ),
450
- 'date_modified' => new LP_Datetime( $post->post_modified ),
451
- 'status' => str_replace( 'lp-', '', $post->post_status ),
452
- 'parent_id' => $post->post_parent,
453
- 'created_via' => get_post_meta( $post->ID, '_created_via', true ),
454
- 'total' => get_post_meta( $post->ID, '_order_total', true ),
455
- 'subtotal' => get_post_meta( $post->ID, '_order_subtotal', true ),
456
- 'order_key' => get_post_meta( $post->ID, '_order_key', true ),
457
- 'user_ip_address' => get_post_meta( $post->ID, '_user_ip_address', true ),
458
- 'user_agent' => get_post_meta( $post->ID, '_user_agent', true ),
459
- 'checkout_email' => get_post_meta( $post->ID, '_checkout_email', true ),
460
- 'currency' => get_post_meta( $post->ID, '_order_currency', true )
461
- )
462
- );
463
- $this->read_items( $order );
464
- $order->read_meta();
465
- }
466
 
467
- return true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
468
  }
469
 
470
- /**
471
- * Recover an order checked out by Guest for an user.
472
- *
473
- * @param string $order_key
474
- * @param int $user_id
475
- *
476
- * @return bool|LP_Order|WP_Error
477
- */
478
- public function recover( $order_key, $user_id ) {
479
- try {
480
- $order = $this->get_order_by_key( $order_key );
481
 
482
- // Validations
483
- if ( ! $order ) {
484
- throw new Exception( __( 'Invalid order.', 'learnpress' ), 1000 );
485
- }
 
 
 
 
 
 
 
486
 
487
- if ( ! $order->is_guest() ) {
488
- throw new Exception( __( 'Order is already assigned.', 'learnpress' ), 1010 );
489
- }
 
490
 
491
- $user = learn_press_get_user( $user_id );
 
 
492
 
493
- if ( ! $user ) {
494
- throw new Exception( __( 'User does not exist.', 'learnpress' ), 1020 );
495
- }
496
 
497
- global $wpdb;
 
 
498
 
499
- // Set user to order and update
500
- $order->set_user_id( $user_id );
501
- $order->save();
502
 
503
- // Trigger action
504
- do_action( 'learn-press/order/recovered-successful', $order->get_id(), $user_id );
505
- } catch ( Exception $ex ) {
506
- return new WP_Error( $ex->getCode(), $ex->getMessage() );
507
- }
508
 
509
- return $order;
 
 
 
510
  }
511
 
512
- /**
513
- * Retrieve an order by order key.
514
- *
515
- * @param string $order_key
516
- *
517
- * @return bool|LP_Order
518
- */
519
- public function get_order_by_key( $order_key ) {
520
- global $wpdb;
521
- $query = $wpdb->prepare( "
 
 
 
522
  SELECT ID
523
  FROM {$wpdb->posts} p
524
  INNER JOIN {$wpdb->postmeta} pm ON pm.post_id = p.ID AND pm.meta_key = %s AND pm.meta_value = %s
525
  ", '_order_key', $order_key );
526
 
527
- $order = false;
528
- if ( $order_id = $wpdb->get_var( $query ) ) {
529
- $order = learn_press_get_order( $order_id );
530
- }
531
-
532
- return $order;
533
  }
534
 
535
- /**
536
- * Get all child orders of an order by id
537
- *
538
- * @param int $order_id
539
- *
540
- * @return array|bool|mixed
541
- */
542
- public function get_child_orders( $order_id ) {
543
- global $wpdb;
544
 
545
- if ( false === ( $orders = wp_cache_get( 'order-' . $order_id, 'lp-child-orders' ) ) ) {
546
- $query = $wpdb->prepare( "
 
 
 
 
 
 
 
 
 
 
547
  SELECT *
548
  FROM {$wpdb->posts}
549
  WHERE post_parent = %d
550
  ", $order_id );
551
- if ( $posts = $wpdb->get_results( $query ) ) {
552
- foreach ( $posts as $order ) {
553
- new WP_Post( $order );
554
- $orders[] = $order->ID;
555
- }
556
- } else {
557
- $orders = array();
558
  }
559
- wp_cache_set( 'order-' . $order_id, $orders, 'lp-child-orders' );
 
560
  }
561
-
562
- return $orders;
563
  }
564
 
565
- public function duplicate( &$order, $args = array() ) {
566
- // TODO: Implement duplicate() method.
567
- }
 
 
 
568
  }
152
  $status = 'pending';
153
  }
154
 
155
+
156
  $post_data = array(
157
  'post_date' => $order->get_order_date( 'edit' )->toSql(),
158
  'post_date_gmt' => $order->get_order_date( 'edit' )->toSql( false ),
431
  }
432
  }
433
  if ( $post = get_post( $the_id ) ) {
434
+ if ( $_users = get_post_meta( $order->get_id(), '_user_id' ) ) {
435
+ settype( $_users, 'array' );
436
+ } else {
437
+ $_users = array();
438
+ }
439
  if ( sizeof( $_users ) > 1 ) {
440
+ $users = $_users;
 
 
 
 
441
  } elseif ( sizeof( $_users ) == 1 ) {
442
  $users = $_users[0];
443
  } else {
444
  $users = 0;
445
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
446
 
447
+ $order->set_data_via_methods(
448
+ array(
449
+ 'user_id' => $users,//get_post_meta( $order->get_id(), '_user_id', true ),
450
+ 'order_date' => new LP_Datetime( $post->post_date ),
451
+ 'date_modified' => new LP_Datetime( $post->post_modified ),
452
+ 'status' => str_replace( 'lp-', '', $post->post_status ),
453
+ 'parent_id' => $post->post_parent,
454
+ 'created_via' => get_post_meta( $post->ID, '_created_via', true ),
455
+ 'total' => get_post_meta( $post->ID, '_order_total', true ),
456
+ 'subtotal' => get_post_meta( $post->ID, '_order_subtotal', true ),
457
+ 'order_key' => get_post_meta( $post->ID, '_order_key', true ),
458
+ 'user_ip_address' => get_post_meta( $post->ID, '_user_ip_address', true ),
459
+ 'user_agent' => get_post_meta( $post->ID, '_user_agent', true ),
460
+ 'checkout_email' => get_post_meta( $post->ID, '_checkout_email', true ),
461
+ 'currency' => get_post_meta( $post->ID, '_order_currency', true )
462
+ )
463
+ );
464
+ $this->read_items( $order );
465
+ $order->read_meta();
466
  }
467
 
468
+ return true;
469
+ }
 
 
 
 
 
 
 
 
 
470
 
471
+ /**
472
+ * Recover an order checked out by Guest for an user.
473
+ *
474
+ * @param string $order_key
475
+ * @param int $user_id
476
+ *
477
+ * @return bool|LP_Order|WP_Error
478
+ */
479
+ public function recover( $order_key, $user_id ) {
480
+ try {
481
+ $order = $this->get_order_by_key( $order_key );
482
 
483
+ // Validations
484
+ if ( ! $order ) {
485
+ throw new Exception( __( 'Invalid order.', 'learnpress' ), 1000 );
486
+ }
487
 
488
+ if ( ! $order->is_guest() ) {
489
+ throw new Exception( __( 'Order is already assigned.', 'learnpress' ), 1010 );
490
+ }
491
 
492
+ $user = learn_press_get_user( $user_id );
 
 
493
 
494
+ if ( ! $user ) {
495
+ throw new Exception( __( 'User does not exist.', 'learnpress' ), 1020 );
496
+ }
497
 
498
+ global $wpdb;
 
 
499
 
500
+ // Set user to order and update
501
+ $order->set_user_id( $user_id );
502
+ $order->save();
 
 
503
 
504
+ // Trigger action
505
+ do_action( 'learn-press/order/recovered-successful', $order->get_id(), $user_id );
506
+ } catch ( Exception $ex ) {
507
+ return new WP_Error( $ex->getCode(), $ex->getMessage() );
508
  }
509
 
510
+ return $order;
511
+ }
512
+
513
+ /**
514
+ * Retrieve an order by order key.
515
+ *
516
+ * @param string $order_key
517
+ *
518
+ * @return bool|LP_Order
519
+ */
520
+ public function get_order_by_key( $order_key ) {
521
+ global $wpdb;
522
+ $query = $wpdb->prepare( "
523
  SELECT ID
524
  FROM {$wpdb->posts} p
525
  INNER JOIN {$wpdb->postmeta} pm ON pm.post_id = p.ID AND pm.meta_key = %s AND pm.meta_value = %s
526
  ", '_order_key', $order_key );
527
 
528
+ $order = false;
529
+ if ( $order_id = $wpdb->get_var( $query ) ) {
530
+ $order = learn_press_get_order( $order_id );
 
 
 
531
  }
532
 
533
+ return $order;
534
+ }
 
 
 
 
 
 
 
535
 
536
+ /**
537
+ * Get all child orders of an order by id
538
+ *
539
+ * @param int $order_id
540
+ *
541
+ * @return array|bool|mixed
542
+ */
543
+ public function get_child_orders( $order_id ) {
544
+ global $wpdb;
545
+
546
+ if ( false === ( $orders = wp_cache_get( 'order-' . $order_id, 'lp-child-orders' ) ) ) {
547
+ $query = $wpdb->prepare( "
548
  SELECT *
549
  FROM {$wpdb->posts}
550
  WHERE post_parent = %d
551
  ", $order_id );
552
+ if ( $posts = $wpdb->get_results( $query ) ) {
553
+ foreach ( $posts as $order ) {
554
+ new WP_Post( $order );
555
+ $orders[] = $order->ID;
 
 
 
556
  }
557
+ } else {
558
+ $orders = array();
559
  }
560
+ wp_cache_set( 'order-' . $order_id, $orders, 'lp-child-orders' );
 
561
  }
562
 
563
+ return $orders;
564
+ }
565
+
566
+ public function duplicate( &$order, $args = array() ) {
567
+ // TODO: Implement duplicate() method.
568
+ }
569
  }
inc/custom-post-types/course.php CHANGED
@@ -255,13 +255,24 @@ if ( ! class_exists( 'LP_Course_Post_Type' ) ) {
255
  * @param $course_id
256
  */
257
  public function update_course( $course_id ) {
 
258
  global $wpdb;
259
 
260
  /**
261
  * Update all course items if set Course Author option
262
  */
263
- $course = learn_press_get_course( $course_id );
 
 
264
  if ( ! $curriculum = $course->get_items() ) {
 
 
 
 
 
 
 
 
265
  return;
266
  }
267
  // course curriculum items / quiz items / questions of quiz
@@ -284,11 +295,11 @@ if ( ! class_exists( 'LP_Course_Post_Type' ) ) {
284
  $ids = array_merge( (array) $course_id, $item_ids, $question_ids );
285
 
286
  // update post author
287
- if ( ! empty( $_POST['_lp_course_author'] ) ) {
288
  foreach ( $ids as $id ) {
289
  $wpdb->update(
290
  $wpdb->posts,
291
- array( 'post_author' => $_POST['_lp_course_author'] ),
292
  array( 'ID' => $id )
293
  );
294
  }
@@ -617,9 +628,9 @@ if ( ! class_exists( 'LP_Course_Post_Type' ) ) {
617
  $passing_grade = '';
618
 
619
  if ( $final_quiz = $course->get_final_quiz() ) {
620
- $quiz = learn_press_get_quiz( $final_quiz );
621
-
622
- $passing_grade = $quiz->get_passing_grade();
623
  }
624
 
625
  $quiz_passing_condition_html = '
@@ -716,7 +727,13 @@ if ( ! class_exists( 'LP_Course_Post_Type' ) ) {
716
 
717
  $payment = get_post_meta( $course_id, '_lp_payment', true );
718
 
719
- if ( current_user_can( 'manage_options' ) ) {
 
 
 
 
 
 
720
  $message = '';
721
  $price = get_post_meta( $course_id, '_lp_price', true );
722
  $sale_price = '';
255
  * @param $course_id
256
  */
257
  public function update_course( $course_id ) {
258
+
259
  global $wpdb;
260
 
261
  /**
262
  * Update all course items if set Course Author option
263
  */
264
+ $course = learn_press_get_course( $course_id );
265
+ $post_author = $_POST['_lp_course_author'];
266
+
267
  if ( ! $curriculum = $course->get_items() ) {
268
+ if ( ! empty( $post_author ) ) {
269
+ $wpdb->update(
270
+ $wpdb->posts,
271
+ array( 'post_author' => $post_author ),
272
+ array( 'ID' => $course_id )
273
+ );
274
+ }
275
+
276
  return;
277
  }
278
  // course curriculum items / quiz items / questions of quiz
295
  $ids = array_merge( (array) $course_id, $item_ids, $question_ids );
296
 
297
  // update post author
298
+ if ( ! empty( $post_author ) ) {
299
  foreach ( $ids as $id ) {
300
  $wpdb->update(
301
  $wpdb->posts,
302
+ array( 'post_author' => $post_author ),
303
  array( 'ID' => $id )
304
  );
305
  }
628
  $passing_grade = '';
629
 
630
  if ( $final_quiz = $course->get_final_quiz() ) {
631
+ if ( $quiz = learn_press_get_quiz( $final_quiz ) ) {
632
+ $passing_grade = $quiz->get_passing_grade();
633
+ }
634
  }
635
 
636
  $quiz_passing_condition_html = '
727
 
728
  $payment = get_post_meta( $course_id, '_lp_payment', true );
729
 
730
+ $current_user = learn_press_get_current_user();
731
+ $role = $current_user->get_role();
732
+
733
+ if ( in_array( $role, apply_filters( 'learn-press/user-set-course-price-roles', array(
734
+ 'admin',
735
+ 'instructor'
736
+ ) ) ) ) {
737
  $message = '';
738
  $price = get_post_meta( $course_id, '_lp_price', true );
739
  $sale_price = '';
inc/libraries/meta-box/meta-box.zip DELETED
File without changes
inc/lp-constants.php CHANGED
@@ -4,7 +4,7 @@
4
  */
5
  $upload_dir = wp_upload_dir();
6
  // version
7
- define( 'LEARNPRESS_VERSION', '3.0.4' );
8
 
9
  define( 'LP_WP_CONTENT', basename( WP_CONTENT_DIR ) );
10
 
4
  */
5
  $upload_dir = wp_upload_dir();
6
  // version
7
+ define( 'LEARNPRESS_VERSION', '3.0.5' );
8
 
9
  define( 'LP_WP_CONTENT', basename( WP_CONTENT_DIR ) );
10
 
inc/lp-template-functions.php CHANGED
@@ -2852,6 +2852,7 @@ if ( ! function_exists( 'learn_press_content_item_lesson_content' ) ) {
2852
 
2853
  return;
2854
  }
 
2855
  learn_press_get_template( 'content-lesson/content.php' );
2856
  }
2857
  }
2852
 
2853
  return;
2854
  }
2855
+
2856
  learn_press_get_template( 'content-lesson/content.php' );
2857
  }
2858
  }
inc/order/class-lp-order.php CHANGED
@@ -162,6 +162,8 @@ if ( ! class_exists( 'LP_Order' ) ) {
162
  default:
163
  $date = learn_press_date_i18n( $strtime );
164
  }
 
 
165
  }
166
 
167
  return $date;
@@ -337,10 +339,14 @@ if ( ! class_exists( 'LP_Order' ) ) {
337
  public function get_status() {
338
 
339
  $status = $this->get_data( 'status' );
340
-
 
341
  $status = apply_filters( 'learn_press_order_status', $status, $this );
 
 
342
 
343
- return apply_filters( 'learn-press/order/status', $status, $this->get_id() );
 
344
  }
345
 
346
  /**
@@ -377,6 +383,8 @@ if ( ! class_exists( 'LP_Order' ) ) {
377
 
378
  if ( ! empty( $statuses[ $order_status ] ) ) {
379
  $status = $statuses[ $order_status ];
 
 
380
  } elseif ( $order_status == 'trash' ) {
381
  $status = __( 'Removed', 'learnpress' );
382
  } else {
@@ -775,7 +783,7 @@ if ( ! class_exists( 'LP_Order' ) ) {
775
  public function get_user( $field = '' ) {
776
 
777
  $users = $this->get_users();
778
- $uid = reset($users);
779
 
780
  if ( false === ( $user = learn_press_get_user( $uid ) ) ) {
781
  return false;
@@ -1034,19 +1042,21 @@ if ( ! class_exists( 'LP_Order' ) ) {
1034
  if ( $user_ids = $this->get_data( 'user_id' ) ) {
1035
  if ( is_array( $user_ids ) ) {
1036
  foreach ( $user_ids as $user_id ) {
1037
- $user = learn_press_get_user( $user_id );
1038
- $data[ $user_id ] = $user->get_data(
1039
- array(
1040
- 'id',
1041
- 'email',
1042
- 'user_login',
1043
- 'description',
1044
- 'first_name',
1045
- 'last_name',
1046
- 'nickname',
1047
- 'display_name'
1048
- )
1049
- );
 
 
1050
  }
1051
  }
1052
  // global $wpdb;
162
  default:
163
  $date = learn_press_date_i18n( $strtime );
164
  }
165
+ } elseif ( ! $date instanceof LP_Datetime ) {
166
+ $date = new LP_Datetime( $date );
167
  }
168
 
169
  return $date;
339
  public function get_status() {
340
 
341
  $status = $this->get_data( 'status' );
342
+ // echo $status;
343
+ // var_dump($status);
344
  $status = apply_filters( 'learn_press_order_status', $status, $this );
345
+ // var_dump($status);
346
+ apply_filters( 'learn-press/order/status', $status, $this->get_id() );
347
 
348
+ // var_dump($this);
349
+ return $status;
350
  }
351
 
352
  /**
383
 
384
  if ( ! empty( $statuses[ $order_status ] ) ) {
385
  $status = $statuses[ $order_status ];
386
+ } elseif ( ! empty( $statuses[ 'lp-' . $order_status ] ) ) {
387
+ $status = $statuses[ 'lp-' . $order_status ];
388
  } elseif ( $order_status == 'trash' ) {
389
  $status = __( 'Removed', 'learnpress' );
390
  } else {
783
  public function get_user( $field = '' ) {
784
 
785
  $users = $this->get_users();
786
+ $uid = reset( $users );
787
 
788
  if ( false === ( $user = learn_press_get_user( $uid ) ) ) {
789
  return false;
1042
  if ( $user_ids = $this->get_data( 'user_id' ) ) {
1043
  if ( is_array( $user_ids ) ) {
1044
  foreach ( $user_ids as $user_id ) {
1045
+ $user = learn_press_get_user( $user_id );
1046
+ if ( $user->is_exists() ) {
1047
+ $data[ $user_id ] = $user->get_data(
1048
+ array(
1049
+ 'id',
1050
+ 'email',
1051
+ 'user_login',
1052
+ 'description',
1053
+ 'first_name',
1054
+ 'last_name',
1055
+ 'nickname',
1056
+ 'display_name'
1057
+ )
1058
+ );
1059
+ }
1060
  }
1061
  }
1062
  // global $wpdb;
inc/order/lp-order-functions.php CHANGED
@@ -748,10 +748,10 @@ function learn_press_get_register_order_statuses() {
748
  function _learn_press_get_order_status_description( $status ) {
749
  static $descriptions = null;
750
  $descriptions = array(
751
- 'lp-pending' => __( 'Order received in case user buy a course but doesn\'t finalise the order.', 'learnpress' ),
752
- 'lp-processing' => __( 'Payment received and the order is awaiting fulfillment.', 'learnpress' ),
753
- 'lp-completed' => __( 'Order fulfilled and complete.', 'learnpress' ),
754
- 'lp-cancelled' => __( 'The order is cancelled by an admin or the customer.', 'learnpress' )
755
  );
756
 
757
  return apply_filters( 'learn_press_order_status_description', ! empty( $descriptions[ $status ] ) ? $descriptions[ $status ] : '' );
748
  function _learn_press_get_order_status_description( $status ) {
749
  static $descriptions = null;
750
  $descriptions = array(
751
+ 'pending' => __( 'Order received in case user buy a course but doesn\'t finalise the order.', 'learnpress' ),
752
+ 'processing' => __( 'Payment received and the order is awaiting fulfillment.', 'learnpress' ),
753
+ 'completed' => __( 'Order fulfilled and complete.', 'learnpress' ),
754
+ 'cancelled' => __( 'The order is cancelled by an admin or the customer.', 'learnpress' )
755
  );
756
 
757
  return apply_filters( 'learn_press_order_status_description', ! empty( $descriptions[ $status ] ) ? $descriptions[ $status ] : '' );
inc/user-item/class-lp-user-item-course.php CHANGED
@@ -25,10 +25,10 @@ class LP_User_Item_Course extends LP_User_Item implements ArrayAccess {
25
 
26
  protected $_item = null;
27
 
28
- protected static $_loaded = 0;
29
-
30
  protected $_items_by_item_ids = array();
31
 
 
 
32
  /**
33
  * LP_User_Item_Course constructor.
34
  *
@@ -37,19 +37,14 @@ class LP_User_Item_Course extends LP_User_Item implements ArrayAccess {
37
  public function __construct( $item ) {
38
  parent::__construct( $item );
39
  $this->_item = $item;
40
- $this->read_items();
41
- $this->read_items_meta();
42
-
43
- self::$_loaded ++;
44
- if ( self::$_loaded == 1 ) {
45
- add_filter( 'debug_data', array( __CLASS__, 'log' ) );
46
- }
47
  }
48
 
49
- public static function log( $data ) {
50
- $data[] = __CLASS__ . '( ' . self::$_loaded . ' )';
51
-
52
- return $data;
 
53
  }
54
 
55
  /**
@@ -109,7 +104,6 @@ class LP_User_Item_Course extends LP_User_Item implements ArrayAccess {
109
  return $exceeded;
110
  }
111
 
112
-
113
  return parent::is_exceeded();
114
  }
115
 
@@ -214,6 +208,7 @@ class LP_User_Item_Course extends LP_User_Item implements ArrayAccess {
214
  return false;
215
  }
216
 
 
217
  $course_result = $course->get_data( 'course_result' );
218
  $results = false;
219
 
@@ -238,6 +233,9 @@ class LP_User_Item_Course extends LP_User_Item implements ArrayAccess {
238
  case 'evaluate_quiz':
239
  $results = $this->_evaluate_course_by_completed_quizzes();
240
  break;
 
 
 
241
  }
242
 
243
  if ( is_array( $results ) ) {
@@ -469,9 +467,9 @@ class LP_User_Item_Course extends LP_User_Item implements ArrayAccess {
469
  /**
470
  * Get completed items.
471
  *
472
- * @param string $type - Optional. Filter by type (such lp_quiz, lp_lesson) if passed
473
- * @param bool $with_total - Optional. Include total if TRUE
474
- * @param int $section_id - Optional. Get in specific section
475
  *
476
  * @return array|bool|mixed
477
  */
@@ -525,8 +523,8 @@ class LP_User_Item_Course extends LP_User_Item implements ArrayAccess {
525
  /**
526
  * Get items completed by percentage.
527
  *
528
- * @param string $type - Optional. Filter by type or not
529
- * @param int $section_id - Optional. Get in specific section
530
  *
531
  * @return float|int
532
  */
25
 
26
  protected $_item = null;
27
 
 
 
28
  protected $_items_by_item_ids = array();
29
 
30
+ protected $_loaded = false;
31
+
32
  /**
33
  * LP_User_Item_Course constructor.
34
  *
37
  public function __construct( $item ) {
38
  parent::__construct( $item );
39
  $this->_item = $item;
40
+ $this->load();
 
 
 
 
 
 
41
  }
42
 
43
+ public function load() {
44
+ if ( ! $this->_loaded ) {
45
+ $this->read_items();
46
+ $this->read_items_meta();
47
+ }
48
  }
49
 
50
  /**
104
  return $exceeded;
105
  }
106
 
 
107
  return parent::is_exceeded();
108
  }
109
 
208
  return false;
209
  }
210
 
211
+ $this->load();
212
  $course_result = $course->get_data( 'course_result' );
213
  $results = false;
214
 
233
  case 'evaluate_quiz':
234
  $results = $this->_evaluate_course_by_completed_quizzes();
235
  break;
236
+ default:
237
+ $results = apply_filters( 'learn-press/evaluate_passed_conditions', $course_result, $this );
238
+ break;
239
  }
240
 
241
  if ( is_array( $results ) ) {
467
  /**
468
  * Get completed items.
469
  *
470
+ * @param string $type - Optional. Filter by type (such lp_quiz, lp_lesson) if passed
471
+ * @param bool $with_total - Optional. Include total if TRUE
472
+ * @param int $section_id - Optional. Get in specific section
473
  *
474
  * @return array|bool|mixed
475
  */
523
  /**
524
  * Get items completed by percentage.
525
  *
526
+ * @param string $type - Optional. Filter by type or not
527
+ * @param int $section_id - Optional. Get in specific section
528
  *
529
  * @return float|int
530
  */
inc/user-item/class-lp-user-item.php CHANGED
@@ -5,11 +5,6 @@
5
  * @since 3.0.0
6
  */
7
  class LP_User_Item extends LP_Abstract_Object_Data {
8
- /**
9
- * @var int
10
- */
11
- protected static $_loaded = 0;
12
-
13
  /**
14
  * @var bool
15
  */
@@ -34,16 +29,6 @@ class LP_User_Item extends LP_Abstract_Object_Data {
34
  if ( ! empty( $item['end_time'] ) ) {
35
  $this->set_end_time( $item['end_time'] );
36
  }
37
- self::$_loaded ++;
38
- if ( self::$_loaded == 1 ) {
39
- add_filter( 'debug_data', array( __CLASS__, 'log' ) );
40
- }
41
- }
42
-
43
- public static function log( $data ) {
44
- $data[] = __CLASS__ . '( ' . self::$_loaded . ' )';
45
-
46
- return $data;
47
  }
48
 
49
  /**
5
  * @since 3.0.0
6
  */
7
  class LP_User_Item extends LP_Abstract_Object_Data {
 
 
 
 
 
8
  /**
9
  * @var bool
10
  */
29
  if ( ! empty( $item['end_time'] ) ) {
30
  $this->set_end_time( $item['end_time'] );
31
  }
 
 
 
 
 
 
 
 
 
 
32
  }
33
 
34
  /**
inc/user/abstract-lp-user.php CHANGED
@@ -337,7 +337,7 @@ if ( ! class_exists( 'LP_Abstract_User' ) ) {
337
  ///$records = array_filter( $records );
338
  }
339
 
340
- if ( $return_last ) {
341
  $records = reset( $records );
342
  }
343
 
337
  ///$records = array_filter( $records );
338
  }
339
 
340
+ if ( $return_last && is_array( $records ) ) {
341
  $records = reset( $records );
342
  }
343
 
inc/user/class-lp-profile.php CHANGED
@@ -656,7 +656,7 @@ if ( ! class_exists( 'LP_Profile' ) ) {
656
  }
657
 
658
  if ( empty( $query_args['status'] ) ) {
659
- $query_args['status'] = 'completed processing cancelled';
660
  }
661
 
662
  if ( $order_ids = $this->get_user_orders( $query_args ) ) {
656
  }
657
 
658
  if ( empty( $query_args['status'] ) ) {
659
+ $query_args['status'] = 'completed processing cancelled pending';
660
  }
661
 
662
  if ( $order_ids = $this->get_user_orders( $query_args ) ) {
inc/user/lp-user-functions.php CHANGED
@@ -1460,8 +1460,6 @@ function learn_press_update_user_profile_basic_information( $wp_error = false )
1460
 
1461
  $user_id = get_current_user_id();
1462
 
1463
- $_POST['description'] = 1000;
1464
-
1465
  $update_data = array(
1466
  'ID' => $user_id,
1467
  'first_name' => filter_input( INPUT_POST, 'first_name', FILTER_SANITIZE_STRING ),
@@ -1470,9 +1468,7 @@ function learn_press_update_user_profile_basic_information( $wp_error = false )
1470
  'nickname' => filter_input( INPUT_POST, 'nickname', FILTER_SANITIZE_STRING ),
1471
  'description' => filter_input( INPUT_POST, 'description', FILTER_SANITIZE_STRING ),
1472
  );
1473
- print_r( $update_data );
1474
- print_r( $_POST );
1475
- echo "xxxxx";
1476
  $update_data = apply_filters( 'learn-press/update-profile-basic-information-data', $update_data );
1477
  $return = wp_update_user( $update_data );
1478
 
1460
 
1461
  $user_id = get_current_user_id();
1462
 
 
 
1463
  $update_data = array(
1464
  'ID' => $user_id,
1465
  'first_name' => filter_input( INPUT_POST, 'first_name', FILTER_SANITIZE_STRING ),
1468
  'nickname' => filter_input( INPUT_POST, 'nickname', FILTER_SANITIZE_STRING ),
1469
  'description' => filter_input( INPUT_POST, 'description', FILTER_SANITIZE_STRING ),
1470
  );
1471
+
 
 
1472
  $update_data = apply_filters( 'learn-press/update-profile-basic-information-data', $update_data );
1473
  $return = wp_update_user( $update_data );
1474
 
learnpress.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: LearnPress
4
  Plugin URI: http://thimpress.com/learnpress
5
  Description: LearnPress is a WordPress complete solution for creating a Learning Management System (LMS). It can help you to create courses, lessons and quizzes.
6
  Author: ThimPress
7
- Version: 3.0.4
8
  Author URI: http://thimpress.com
9
  Requires at least: 3.8
10
  Tested up to: 4.9.4
4
  Plugin URI: http://thimpress.com/learnpress
5
  Description: LearnPress is a WordPress complete solution for creating a Learning Management System (LMS). It can help you to create courses, lessons and quizzes.
6
  Author: ThimPress
7
+ Version: 3.0.5
8
  Author URI: http://thimpress.com
9
  Requires at least: 3.8
10
  Tested up to: 4.9.4
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link:
4
  Tags: WordPress LMS, LMS, eLearning, e-Learning, Learning Management System, LMS WordPress, Course, Courses, Quiz, Quizzes, Training, Guru, Sell Courses
5
  Requires at least: 3.8
6
  Tested up to: 4.9.4
7
- Stable tag: 3.0.4
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -198,6 +198,15 @@ https://www.transifex.com/projects/p/learnpress/
198
  8. Add-ons of LearnPress.
199
 
200
  == Changelog ==
 
 
 
 
 
 
 
 
 
201
  = 3.0.4 =
202
  ~ Improved: action when clicking to close upgrade notice
203
  ~ Fixed: can not add course from other users to order
4
  Tags: WordPress LMS, LMS, eLearning, e-Learning, Learning Management System, LMS WordPress, Course, Courses, Quiz, Quizzes, Training, Guru, Sell Courses
5
  Requires at least: 3.8
6
  Tested up to: 4.9.4
7
+ Stable tag: 3.0.5
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
198
  8. Add-ons of LearnPress.
199
 
200
  == Changelog ==
201
+ = 3.0.5 =
202
+ + Added: missing single course permalink options
203
+ ~ Fixed: error notice when saving user profile
204
+ ~ Fixed: date translation
205
+ ~ Fixed: notice when viewing courses with Yoast SEO
206
+ ~ Fixed: can't change author of the course
207
+ ~ Fixed: preview lesson will redirect back to course
208
+ ~ Fixed: some other bugs...
209
+
210
  = 3.0.4 =
211
  ~ Improved: action when clicking to close upgrade notice
212
  ~ Fixed: can not add course from other users to order
templates/single-course/content-item-lp_lesson.php CHANGED
@@ -25,6 +25,7 @@ $item = LP_Global::course_item();
25
  do_action( 'learn-press/content-item-summary/' . $item->get_item_type() );
26
 
27
  do_action( 'learn-press/after-content-item-summary/' . $item->get_item_type() );
 
28
  ?>
29
 
30
  </div>
25
  do_action( 'learn-press/content-item-summary/' . $item->get_item_type() );
26
 
27
  do_action( 'learn-press/after-content-item-summary/' . $item->get_item_type() );
28
+
29
  ?>
30
 
31
  </div>
templates/single-course/progress.php CHANGED
@@ -35,7 +35,7 @@ $passing_condition = $course->get_passing_condition();
35
  <div class="items-progress">
36
 
37
  <?php if ( false !== ( $heading = apply_filters( 'learn-press/course/items-completed-heading', __( 'Items completed', 'learnpress' ) ) ) ) { ?>
38
- <h4 class="lp-course-progress-heading"><?php esc_html( $heading ); ?></h4>
39
  <?php } ?>
40
 
41
  <span class="number"><?php printf( __( '%d of %d items', 'learnpress' ), $course_results['completed_items'], $course->count_items('', false) ); ?></span>
@@ -54,7 +54,7 @@ $passing_condition = $course->get_passing_condition();
54
 
55
  <?php if ( false !== ( $heading = apply_filters( 'learn-press/course/result-heading', __( 'Course results', 'learnpress' ) ) ) ) { ?>
56
  <h4 class="lp-course-progress-heading">
57
- <?php esc_html( $heading ); ?>
58
  </h4>
59
  <?php } ?>
60
 
35
  <div class="items-progress">
36
 
37
  <?php if ( false !== ( $heading = apply_filters( 'learn-press/course/items-completed-heading', __( 'Items completed', 'learnpress' ) ) ) ) { ?>
38
+ <h4 class="lp-course-progress-heading"><?php echo esc_html( $heading ); ?></h4>
39
  <?php } ?>
40
 
41
  <span class="number"><?php printf( __( '%d of %d items', 'learnpress' ), $course_results['completed_items'], $course->count_items('', false) ); ?></span>
54
 
55
  <?php if ( false !== ( $heading = apply_filters( 'learn-press/course/result-heading', __( 'Course results', 'learnpress' ) ) ) ) { ?>
56
  <h4 class="lp-course-progress-heading">
57
+ <?php echo esc_html( $heading ); ?>
58
  </h4>
59
  <?php } ?>
60