LearnPress – WordPress LMS Plugin - Version 3.2.2

Version Description

~ Fixed review quiz doesn't work properly. ~ Fixed table session create a lot of rows. ~ Fixed can't enroll to a course purchased. ~ Removed unused functions.

Download this release

Release Info

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

Code changes from version 3.2.1 to 3.2.2

inc/background-process/class-lp-background-installer.php CHANGED
@@ -80,16 +80,18 @@ if ( ! class_exists( 'LP_Background_Installer' ) ) {
80
  }
81
 
82
  /**
83
- * Filter callback
84
  *
85
- * @param $prop
 
 
86
  *
87
  * @return bool
88
  */
89
  protected function _filter_tables( $prop ) {
90
  global $wpdb;
91
 
92
- return is_string( $prop ) && strpos( $prop, $wpdb->prefix . 'learnpress' ) !== false;
93
  }
94
 
95
  /**
80
  }
81
 
82
  /**
83
+ * Filter callback to get all tables of LP assigned to $wpdb.
84
  *
85
+ * @version 3.2.2
86
+ *
87
+ * @param string $prop
88
  *
89
  * @return bool
90
  */
91
  protected function _filter_tables( $prop ) {
92
  global $wpdb;
93
 
94
+ return is_string( $prop ) && strpos( $prop, $wpdb->prefix . 'learnpress' ) === 0;
95
  }
96
 
97
  /**
inc/class-lp-page-controller.php CHANGED
@@ -167,7 +167,7 @@ class LP_Page_Controller {
167
  $redirect = false;
168
  $quiz_status = $quiz_data ? $quiz_data->get_status() : false;
169
 
170
- if ( $quiz_status === 'started' ) {
171
  $current_question = 0;
172
  if ( empty( $vars['question'] ) ) {
173
  $current_question = learn_press_get_user_item_meta( $quiz_data->get_user_item_id(), '_current_question', true );
@@ -188,7 +188,8 @@ class LP_Page_Controller {
188
  if ( ! $question ) {
189
  $redirect = $lp_course_item->get_question_link( $current_question );
190
  }
191
-
 
192
  } elseif ( $quiz_status !== 'completed' ) {
193
  if ( $question ) {
194
  $this->set_404( true );
167
  $redirect = false;
168
  $quiz_status = $quiz_data ? $quiz_data->get_status() : false;
169
 
170
+ if ( $quiz_status == 'started' ) {
171
  $current_question = 0;
172
  if ( empty( $vars['question'] ) ) {
173
  $current_question = learn_press_get_user_item_meta( $quiz_data->get_user_item_id(), '_current_question', true );
188
  if ( ! $question ) {
189
  $redirect = $lp_course_item->get_question_link( $current_question );
190
  }
191
+ } elseif ( $quiz_status === 'completed' ) {
192
+ $current_question = $question ? $question->ID : null;
193
  } elseif ( $quiz_status !== 'completed' ) {
194
  if ( $question ) {
195
  $this->set_404( true );
inc/class-lp-schedules.php CHANGED
@@ -19,6 +19,58 @@ class LP_Schedules {
19
 
20
  if ( learn_press_get_request( 'action' ) == 'heartbeat' || ! is_admin() ) {
21
  add_filter( 'init', array( $this, '_update_current_user_course_expired' ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  }
23
  }
24
 
@@ -31,16 +83,6 @@ class LP_Schedules {
31
  if ( empty( $wpdb->learnpress_user_items ) ) {
32
  return;
33
  }
34
- // $course = learn_press_get_course();
35
- // $query = $wpdb->prepare( "
36
- // SELECT *
37
- // FROM {$wpdb->prefix}learnpress_user_items
38
- // WHERE end_time = %s
39
- // AND item_type = %s
40
- // AND status <> %s
41
- // AND user_id = %s
42
- // LIMIT 0, 10
43
- // ", '0000-00-00 00:00:00', 'lp_course', 'finished', $user_id );
44
 
45
  $query = $wpdb->prepare( "
46
  SELECT *
@@ -48,13 +90,14 @@ class LP_Schedules {
48
  SELECT *
49
  FROM {$wpdb->learnpress_user_items}
50
  WHERE item_type = %s
51
- AND user_id = %d AND status <> %s
52
  AND end_time = %s
 
53
  ORDER BY item_id, user_item_id DESC
54
  ) X
55
  GROUP BY item_id
56
  LIMIT 0, 10
57
- ", LP_COURSE_CPT, $user_id, 'finished', '0000-00-00 00:00:00' );
58
 
59
  $results = $wpdb->get_results( $query );
60
 
@@ -225,21 +268,6 @@ class LP_Schedules {
225
  if ( empty( $wpdb->learnpress_user_items ) ) {
226
  return;
227
  }
228
- /* $query = $wpdb->prepare( "
229
- SELECT *
230
- FROM {$wpdb->prefix}learnpress_user_items
231
- WHERE user_item_id IN(
232
- SELECT user_item_id FROM(
233
- SELECT user_item_id
234
- FROM {$wpdb->prefix}learnpress_user_items
235
- WHERE end_time = %s
236
- AND item_type = %s
237
- GROUP BY item_id
238
- ORDER BY user_item_id DESC
239
- ) AS X
240
- )
241
- LIMIT 0, 10
242
- ", '0000-00-00 00:00:00', 'lp_course' );*/
243
 
244
  $query = $wpdb->prepare( "
245
  SELECT *
@@ -249,11 +277,12 @@ class LP_Schedules {
249
  FROM {$wpdb->prefix}learnpress_user_items
250
  WHERE end_time = %s
251
  AND item_type = %s
252
- AND status <> %s
 
253
  GROUP BY item_id, user_id
254
  )
255
  LIMIT 0, 10
256
- ", '0000-00-00 00:00:00', 'lp_course', 'finished' );
257
 
258
  if ( $results = $wpdb->get_results( $query ) ) {
259
  $ids = array();
19
 
20
  if ( learn_press_get_request( 'action' ) == 'heartbeat' || ! is_admin() ) {
21
  add_filter( 'init', array( $this, '_update_current_user_course_expired' ) );
22
+ add_filter( 'init', array( $this, 'fix_bug_auto_finish_not_enrolled_course' ) );// remove this code on LP 3.2.3
23
+ }
24
+ }
25
+
26
+ /**
27
+ * since version 3.2.2
28
+ * Temp method use to fix bug. It will be remove in next version
29
+ */
30
+ public function fix_bug_auto_finish_not_enrolled_course(){
31
+ global $wpdb;
32
+ $user_id = get_current_user_id();
33
+ if ( empty( $wpdb->learnpress_user_items ) ) {
34
+ return;
35
+ }
36
+ $query = $wpdb->prepare( "
37
+ SELECT user_item_id
38
+ FROM `{$wpdb->learnpress_user_items}`
39
+ WHERE
40
+ `user_id` = %s
41
+ AND `ref_type` = %s
42
+ AND `status` = %s
43
+ AND `start_time` = %s
44
+ ",
45
+ $user_id, LP_ORDER_CPT, 'finished','0000-00-00 00:00:00' );
46
+
47
+ $user_item_ids = $wpdb->get_results( $query );
48
+
49
+ // $user_item_ids = array(99991,99992,99993,99994,99995);// test data
50
+ if(!empty($user_item_ids)){
51
+
52
+ // clear item metas
53
+ $sql_delete = $wpdb->prepare("
54
+ DELETE
55
+ FROM `{$wpdb->learnpress_user_itemmeta}`
56
+ WHERE `learnpress_user_item_id` IN (".implode(', ', array_fill(0, count($user_item_ids), '%s')).")
57
+ ",
58
+ $user_item_ids
59
+ );
60
+ $wpdb->query( $sql_delete );
61
+
62
+ // update status of item to purchased
63
+ $sql_update = $wpdb->prepare("
64
+ UPDATE `{$wpdb->learnpress_user_items}`
65
+ SET `start_time_gmt` = %s,
66
+ `end_time` = %s,
67
+ `end_time_gmt` = %s,
68
+ `status` = %s
69
+ WHERE `user_item_id` IN (".implode(', ', array_fill(0, count($user_item_ids), '%s')).")
70
+ ",
71
+ array_merge( array('0000-00-00 00:00:00', '0000-00-00 00:00:00', '0000-00-00 00:00:00', 'purchased'), $user_item_ids)
72
+ );
73
+ $wpdb->query( $sql_update );
74
  }
75
  }
76
 
83
  if ( empty( $wpdb->learnpress_user_items ) ) {
84
  return;
85
  }
 
 
 
 
 
 
 
 
 
 
86
 
87
  $query = $wpdb->prepare( "
88
  SELECT *
90
  SELECT *
91
  FROM {$wpdb->learnpress_user_items}
92
  WHERE item_type = %s
93
+ AND user_id = %d AND status = %s
94
  AND end_time = %s
95
+ AND start_time <> %s
96
  ORDER BY item_id, user_item_id DESC
97
  ) X
98
  GROUP BY item_id
99
  LIMIT 0, 10
100
+ ", LP_COURSE_CPT, $user_id, 'enrolled', '0000-00-00 00:00:00', '0000-00-00 00:00:00' );
101
 
102
  $results = $wpdb->get_results( $query );
103
 
268
  if ( empty( $wpdb->learnpress_user_items ) ) {
269
  return;
270
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
271
 
272
  $query = $wpdb->prepare( "
273
  SELECT *
277
  FROM {$wpdb->prefix}learnpress_user_items
278
  WHERE end_time = %s
279
  AND item_type = %s
280
+ AND status = %s
281
+ AND start_time <> %s
282
  GROUP BY item_id, user_id
283
  )
284
  LIMIT 0, 10
285
+ ", '0000-00-00 00:00:00', 'lp_course', 'enrolled', '0000-00-00 00:00:00' );
286
 
287
  if ( $results = $wpdb->get_results( $query ) ) {
288
  $ids = array();
inc/class-lp-session-handler.php CHANGED
@@ -35,6 +35,13 @@ class LP_Session_Handler implements ArrayAccess {
35
  */
36
  private $_has_cookie = false;
37
 
 
 
 
 
 
 
 
38
  /**
39
  * @var string Custom session table name
40
  */
@@ -92,12 +99,27 @@ class LP_Session_Handler implements ArrayAccess {
92
  }
93
  }
94
 
 
 
 
 
 
95
  public function __construct() {
96
  global $wpdb;
97
 
98
  $this->_cookie = 'wp_learn_press_session_' . COOKIEHASH;
99
  $this->_table = $wpdb->prefix . 'learnpress_sessions';
100
 
 
 
 
 
 
 
 
 
 
 
101
  if ( $cookie = $this->get_session_cookie() ) {
102
  $this->_customer_id = $cookie[0];
103
  $this->_session_expiration = $cookie[1];
@@ -137,6 +159,10 @@ class LP_Session_Handler implements ArrayAccess {
137
  }
138
  }
139
 
 
 
 
 
140
  public function has_session() {
141
  return isset( $_COOKIE[ $this->_cookie ] ) || $this->_has_cookie || is_user_logged_in();
142
  }
@@ -164,10 +190,18 @@ class LP_Session_Handler implements ArrayAccess {
164
 
165
  list( $customer_id, $session_expiration, $cookie_hash ) = explode( '||', $_COOKIE[ $this->_cookie ] );
166
 
167
-
168
  $to_hash = $customer_id . '|' . $session_expiration;
169
  $hash = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) );
170
 
 
 
 
 
 
 
 
 
 
171
  if ( empty( $cookie_hash ) || ! hash_equals( $hash, $cookie_hash ) ) {
172
  return false;
173
  }
@@ -202,7 +236,7 @@ class LP_Session_Handler implements ArrayAccess {
202
 
203
  public function save_data() {
204
 
205
- if ( $this->_changed && $this->has_session() ) {
206
  global $wpdb;
207
 
208
  $wpdb->replace(
@@ -218,6 +252,14 @@ class LP_Session_Handler implements ArrayAccess {
218
  '%d'
219
  )
220
  );
 
 
 
 
 
 
 
 
221
 
222
  // Set cache
223
  LP_Object_Cache::set( $this->get_cache_prefix() . $this->_customer_id, $this->_data, LP_SESSION_CACHE_GROUP, $this->_session_expiration - time() );
@@ -314,6 +356,7 @@ class LP_Session_Handler implements ArrayAccess {
314
  '%d'
315
  )
316
  );
 
317
  }
318
 
319
  /**
35
  */
36
  private $_has_cookie = false;
37
 
38
+ /**
39
+ * @since 3.2.2
40
+ *
41
+ * @var bool
42
+ */
43
+ private $_has_browser_cookie = true;
44
+
45
  /**
46
  * @var string Custom session table name
47
  */
99
  }
100
  }
101
 
102
+ /**
103
+ * LP_Session_Handler constructor.
104
+ *
105
+ * @version 3.2.2
106
+ */
107
  public function __construct() {
108
  global $wpdb;
109
 
110
  $this->_cookie = 'wp_learn_press_session_' . COOKIEHASH;
111
  $this->_table = $wpdb->prefix . 'learnpress_sessions';
112
 
113
+ // Check cookie ...
114
+ if ( ! isset( $_COOKIE ) || sizeof( $_COOKIE ) == 0 ) {
115
+ $this->_has_browser_cookie = false;
116
+ }
117
+
118
+ // ...and user-agent to ensure user a viewing in a web browser
119
+ if ( empty( $_SERVER['HTTP_USER_AGENT'] ) || strpos( $_SERVER['HTTP_USER_AGENT'], 'Mozilla' ) === false ) {
120
+ $this->_has_browser_cookie = false;
121
+ }
122
+
123
  if ( $cookie = $this->get_session_cookie() ) {
124
  $this->_customer_id = $cookie[0];
125
  $this->_session_expiration = $cookie[1];
159
  }
160
  }
161
 
162
+ public function has_cookie() {
163
+ return $this->_has_cookie && $this->_has_browser_cookie;
164
+ }
165
+
166
  public function has_session() {
167
  return isset( $_COOKIE[ $this->_cookie ] ) || $this->_has_cookie || is_user_logged_in();
168
  }
190
 
191
  list( $customer_id, $session_expiration, $cookie_hash ) = explode( '||', $_COOKIE[ $this->_cookie ] );
192
 
 
193
  $to_hash = $customer_id . '|' . $session_expiration;
194
  $hash = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) );
195
 
196
+ // LP_Debug::instance()->add( array(
197
+ // $this->_customer_id,
198
+ // $_COOKIE,
199
+ // $_REQUEST,
200
+ // $_POST,
201
+ // $_GET,
202
+ // $_SERVER
203
+ // ), 'sessions-cookie' );
204
+
205
  if ( empty( $cookie_hash ) || ! hash_equals( $hash, $cookie_hash ) ) {
206
  return false;
207
  }
236
 
237
  public function save_data() {
238
 
239
+ if ( $this->_changed && $this->has_session() && $this->has_cookie() ) {
240
  global $wpdb;
241
 
242
  $wpdb->replace(
252
  '%d'
253
  )
254
  );
255
+ // LP_Debug::instance()->add( array(
256
+ // $this->_customer_id,
257
+ // $_COOKIE,
258
+ // $_REQUEST,
259
+ // $_POST,
260
+ // $_GET,
261
+ // $_SERVER
262
+ // ), __FUNCTION__ );
263
 
264
  // Set cache
265
  LP_Object_Cache::set( $this->get_cache_prefix() . $this->_customer_id, $this->_data, LP_SESSION_CACHE_GROUP, $this->_session_expiration - time() );
356
  '%d'
357
  )
358
  );
359
+ //LP_Debug::instance()->add( $customer_id, __FUNCTION__ );
360
  }
361
 
362
  /**
inc/custom-post-types/order.php CHANGED
@@ -381,7 +381,7 @@ if ( ! class_exists( 'LP_Order_Post_Type' ) ) {
381
  $new_order->save();
382
  $new_status = get_post_status( $new_order->get_id() );
383
 
384
- if ( ( $new_status !== $old_status ) || $trigger_action ) {
385
  $status = str_replace( 'lp-', '', $new_status );
386
  $old_status = str_replace( 'lp-', '', $new_status );
387
  do_action( 'learn-press/order/status-' . $status, $new_order->get_id(), $status );
381
  $new_order->save();
382
  $new_status = get_post_status( $new_order->get_id() );
383
 
384
+ if ( ( $new_status == $old_status ) && $trigger_action ) {
385
  $status = str_replace( 'lp-', '', $new_status );
386
  $old_status = str_replace( 'lp-', '', $new_status );
387
  do_action( 'learn-press/order/status-' . $status, $new_order->get_id(), $status );
inc/lp-constants.php CHANGED
@@ -4,7 +4,7 @@
4
  */
5
  $upload_dir = wp_upload_dir();
6
  // version
7
- define( 'LEARNPRESS_VERSION', '3.2.1' );
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.2.2' );
8
 
9
  define( 'LP_WP_CONTENT', basename( WP_CONTENT_DIR ) );
10
 
inc/order/class-lp-order.php CHANGED
@@ -1034,6 +1034,7 @@ if ( ! class_exists( 'LP_Order' ) ) {
1034
  public function get_user_data() {
1035
  $data = array();
1036
  if ( $user_ids = $this->get_data( 'user_id' ) ) {
 
1037
  if ( is_array( $user_ids ) ) {
1038
  foreach ( $user_ids as $user_id ) {
1039
  $user = learn_press_get_user( $user_id );
1034
  public function get_user_data() {
1035
  $data = array();
1036
  if ( $user_ids = $this->get_data( 'user_id' ) ) {
1037
+ $user_ids = (array)$user_ids;
1038
  if ( is_array( $user_ids ) ) {
1039
  foreach ( $user_ids as $user_id ) {
1040
  $user = learn_press_get_user( $user_id );
inc/question/class-lp-question.php CHANGED
@@ -635,7 +635,7 @@ if ( ! class_exists( 'LP_Question' ) ) {
635
  */
636
  public function get_answers( $field = null, $exclude = null ) {
637
  $answers = array();
638
- LP_Debug::logTime( __FUNCTION__ );
639
  if ( false === ( $answers = LP_Object_Cache::get( 'answer-options-' . $this->get_id(), 'learn-press/questions' ) ) ) {
640
 
641
  if ( ! $answers = $this->_curd->load_answer_options( $this->get_id() ) ) {
@@ -651,7 +651,6 @@ if ( ! class_exists( 'LP_Question' ) ) {
651
 
652
  // @deprecated
653
  $answers = apply_filters( 'learn_press_question_answers', $answers, $this );
654
- LP_Debug::logTime( __FUNCTION__ );
655
 
656
  return apply_filters( 'learn-press/questions/answers', $answers, $this->get_id() );
657
  }
635
  */
636
  public function get_answers( $field = null, $exclude = null ) {
637
  $answers = array();
638
+
639
  if ( false === ( $answers = LP_Object_Cache::get( 'answer-options-' . $this->get_id(), 'learn-press/questions' ) ) ) {
640
 
641
  if ( ! $answers = $this->_curd->load_answer_options( $this->get_id() ) ) {
651
 
652
  // @deprecated
653
  $answers = apply_filters( 'learn_press_question_answers', $answers, $this );
 
654
 
655
  return apply_filters( 'learn-press/questions/answers', $answers, $this->get_id() );
656
  }
inc/quiz/lp-quiz-functions.php CHANGED
@@ -432,7 +432,6 @@ if ( ! function_exists( 'learn_press_quiz_get_questions_order' ) ) {
432
  function learn_press_is_review_questions() {
433
  if ( ( $item = LP_Global::course_item() ) && ( $user = learn_press_get_current_user() ) ) {
434
  $quiz_data = $user->get_item_data( $item->get_id(), LP_Global::course( 'id' ) );
435
-
436
  return $quiz_data && $quiz_data->is_review_questions();
437
  }
438
 
432
  function learn_press_is_review_questions() {
433
  if ( ( $item = LP_Global::course_item() ) && ( $user = learn_press_get_current_user() ) ) {
434
  $quiz_data = $user->get_item_data( $item->get_id(), LP_Global::course( 'id' ) );
 
435
  return $quiz_data && $quiz_data->is_review_questions();
436
  }
437
 
inc/user/abstract-lp-user.php CHANGED
@@ -1766,12 +1766,12 @@ if ( ! class_exists( 'LP_Abstract_User' ) ) {
1766
  public function has_passed_course( $course_id ) {
1767
  $course = learn_press_get_course( $course_id );
1768
  if ( $course ) {
1769
- $results = $this->evaluate_course_results( $this->get_id() );
1770
  } else {
1771
  $results = 0;
1772
  }
1773
 
1774
- return apply_filters( 'learn_press_user_has_passed_course', $results >= $course->passing_condition ? $results : false, $course_id, $this );
1775
  }
1776
 
1777
  /**
1766
  public function has_passed_course( $course_id ) {
1767
  $course = learn_press_get_course( $course_id );
1768
  if ( $course ) {
1769
+ $results = $this->evaluate_course_results( $course_id );
1770
  } else {
1771
  $results = 0;
1772
  }
1773
 
1774
+ return apply_filters( 'learn_press_user_has_passed_course', $results >= $course->get_passing_condition() ? $results : false, $course_id, $this );
1775
  }
1776
 
1777
  /**
inc/user/lp-user-functions.php CHANGED
@@ -798,318 +798,6 @@ function learn_press_user_has_quiz_status( $status, $quiz_id = 0, $user_id = 0,
798
  return $user->has_quiz_status( $status, $quiz_id, $course_id );
799
  }
800
 
801
- //add_action( 'init', 'learn_press_user_update_user_info' );
802
-
803
- function learn_press_user_update_user_info() {
804
- global $wp, $wpdb;
805
- $user = learn_press_get_current_user();
806
- $user_id = learn_press_get_current_user_id();
807
- $message_template = '<div class="learn-press-message %s">'
808
- . '<p>%s</p>'
809
- . '</div>';
810
-
811
- if ( ! $user_id || is_admin() ) {
812
- return;
813
- }
814
- if ( ! empty( $_POST ) && isset( $_POST['from'] ) && isset( $_POST['action'] ) && $_POST['from'] == 'profile' && $_POST['action'] == 'update' ) {
815
- # - - - - - - - - - - - - - - - - - - - -
816
- # CREATE SOME DIRECTORY
817
- #
818
- $upload = wp_get_upload_dir();
819
- $ppdir = $upload['basedir'] . DIRECTORY_SEPARATOR . 'learn-press-profile';
820
- if ( ! is_dir( $ppdir ) ) {
821
- mkdir( $ppdir );
822
- }
823
- $upload_dir = $ppdir . DIRECTORY_SEPARATOR . $user_id;
824
- if ( ! is_dir( $upload_dir ) ) {
825
- mkdir( $upload_dir );
826
- }
827
- $upload_dir_tmp = $upload_dir . DIRECTORY_SEPARATOR . 'tmp';
828
- if ( ! is_dir( $upload_dir_tmp ) ) {
829
- mkdir( $upload_dir_tmp );
830
- }
831
- $lp_profile_url = $upload['baseurl'] . '/learn-press-profile/' . $user_id . '/';
832
- #
833
- # CREATE SOME DIRECTORY
834
- # - - - - - - - - - - - - - - - - - - - -
835
-
836
-
837
- # - - - - - - - - - - - - - - - - - - - -
838
- # UPLOAD TEMP PICTURE PROFILE
839
- #
840
- if ( isset( $_POST['sub_action'] ) && 'upload_avatar' === $_POST['sub_action'] && isset( $_FILES['image'] ) ) {
841
- $image_name = $_FILES['image']['name'];
842
- $image_tmp = $_FILES['image']['tmp_name'];
843
- $image_size = intval( $_FILES['image']['size'] );
844
- $image_type = strtolower( $_FILES['image']['type'] );
845
- $filename = strtolower( pathinfo( $image_name, PATHINFO_FILENAME ) );
846
- $file_ext = strtolower( pathinfo( $image_name, PATHINFO_EXTENSION ) );
847
-
848
- if ( ( ! empty( $_FILES["image"] ) ) && ( $_FILES['image']['error'] == 0 ) ) {
849
- $allowed_image_types = array(
850
- 'image/pjpeg' => "jpg",
851
- 'image/jpeg' => "jpg",
852
- 'image/jpg' => "jpg",
853
- 'image/png' => "png",
854
- 'image/x-png' => "png",
855
- 'image/gif' => "gif"
856
- );
857
- $mine_types = array_keys( $allowed_image_types );
858
- $image_exts = array_values( $allowed_image_types );
859
- # caculate $image_size_limit
860
- $max_upload = intval( ini_get( 'upload_max_filesize' ) );
861
- $max_post = intval( ini_get( 'post_max_size' ) );
862
- $memory_limit = intval( ini_get( 'memory_limit' ) );
863
- $image_size_limit = min( $max_upload, $max_post, $memory_limit, WP_MEMORY_LIMIT );
864
- if ( ! $image_size_limit ) {
865
- $image_size_limit = 1;
866
- }
867
- if ( ! in_array( $image_type, $mine_types ) ) {
868
- $_message = __( 'Only', 'learnpress' ) . ' <strong>' . implode( ',', $image_exts ) . '</strong> ' . __( 'images accepted for upload', 'learnpress' );
869
- $message = sprintf( $message_template, 'error', $_message );
870
- $return = array(
871
- 'return' => false,
872
- 'message' => $message
873
- );
874
- learn_press_send_json( $return );
875
- }
876
- if ( $image_size > $image_size_limit * 1048576 ) {
877
- $message = __( 'Images must be under', 'learnpress' ) . ' ' . $image_size_limit . __( 'MB in size', 'learnpress' );
878
- $return = array(
879
- 'return' => false,
880
- 'message' => $message
881
- );
882
- learn_press_send_json( $return );
883
- }
884
- } else {
885
- $message = __( 'Please select an image for upload', 'learnpress' );
886
- $return = array(
887
- 'return' => false,
888
- 'message' => $message
889
- );
890
- learn_press_send_json( $return );
891
- }
892
-
893
- if ( isset( $_FILES['image']['name'] ) ) {
894
- // upload picture to tmp folder
895
- $path_image_tmp = $upload_dir_tmp . DIRECTORY_SEPARATOR . $filename . '.' . $file_ext;
896
- if ( file_exists( $path_image_tmp ) ) {
897
- $filename .= '1';
898
- $path_image_tmp = $upload_dir_tmp . DIRECTORY_SEPARATOR . $filename . '.' . $file_ext;
899
- }
900
- $uploaded = move_uploaded_file( $image_tmp, $path_image_tmp );
901
- chmod( $path_image_tmp, 0777 );
902
- if ( $uploaded ) {
903
- $editor3 = wp_get_image_editor( $path_image_tmp );
904
- if ( ! is_wp_error( $editor3 ) ) {
905
- # Calculator new width height
906
- $size_current = $editor3->get_size();
907
- if ( $size_current['width'] < 250 || $size_current['width'] < 250 ) {
908
- $editor3->resize( 250, 250, true );
909
- $saved = $editor3->save();
910
- }
911
- }
912
- }
913
-
914
- $_message = $uploaded ? __( 'Image is uploaded success', 'learnpress' ) : __( 'Error in uploading image', 'learnpress' );
915
- $message = sprintf( $message_template, 'success', $_message );
916
- $return = array(
917
- 'return' => $uploaded,
918
- 'message' => $message
919
- );
920
- if ( $uploaded ) {
921
- $return['avatar_tmp'] = $lp_profile_url . 'tmp/' . $filename . '.' . $file_ext;
922
- $return['avatar_tmp_filename'] = $filename . '.' . $file_ext;
923
- }
924
- learn_press_send_json( $return );
925
- }
926
- exit();
927
- }
928
- #
929
- # END OF UPLOAD TEMP PROFILE PICTURE
930
- # - - - - - - - - - - - - - - - - - - - -
931
-
932
- # - - - - - - - - - - - - - - - - - - - -
933
- # CREATE PROFILE PICTURE & THUMBNAIL
934
- #
935
- if ( isset( $_POST['sub_action'] ) && 'crop_avatar' === $_POST['sub_action'] && isset( $_POST['avatar_filename'] ) ) {
936
- $avatar_filename = filter_input( INPUT_POST, 'avatar_filename', FILTER_SANITIZE_STRING );
937
- $avatar_filepath = $upload_dir . DIRECTORY_SEPARATOR . $avatar_filename;
938
- $editor = wp_get_image_editor( $upload_dir_tmp . DIRECTORY_SEPARATOR . $avatar_filename );
939
- if ( is_wp_error( $editor ) ) {
940
- learn_press_add_message( __( 'Thumbnail of image profile not created', 'learnpress' ) );
941
- } else {
942
- # Calculator new width height
943
- $size_current = $editor->get_size();
944
- $zoom = floatval( $_POST['zoom'] );
945
- $offset = $_POST['offset'];
946
- $size_new = array(
947
- 'width' => $size_current['width'] * $zoom,
948
- 'height' => $size_current['height'] * $zoom
949
- );
950
- $editor->resize( $size_new['width'], $size_new['height'], true );
951
- $offset_x = max( intval( $offset['x'] ), - intval( $offset['x'] ) );
952
- $offset_y = max( intval( $offset['y'] ), - intval( $offset['y'] ) );
953
- $editor->crop( $offset_x, $offset_y, 248, 248 );
954
- $saved = $editor->save( $upload_dir . DIRECTORY_SEPARATOR . $avatar_filename );
955
- $res = array();
956
- $res['message'] = '';
957
- if ( is_wp_error( $saved ) ) {
958
- $_message = __( 'Error in cropping user picture profile', 'learnpress' );
959
- $message = sprintf( $message_template, 'error', $_message );
960
- $res['return'] = false;
961
- $res['message'] = $message;
962
- $res['avatar_filename'] = '';
963
- $res['avatar_url'] = '';
964
- } else {
965
- # - - - - - - - - - - - - - - - - - - - -
966
- # Create Thumbnai
967
- #
968
- if ( file_exists( $avatar_filepath ) ) {
969
- $editor2 = wp_get_image_editor( $avatar_filepath );
970
- if ( is_wp_error( $editor2 ) ) {
971
- $_message = __( 'Thumbnail of image profile not created', 'learnpress' );
972
- $message = sprintf( $message_template, 'error', $_message );
973
- $res['message'] .= $message;
974
- } else {
975
- $editor2->set_quality( 90 );
976
- $lp = LP();
977
- $lp_setting = $lp->settings;
978
- $size = $lp_setting->get( 'profile_picture_thumbnail_size' );
979
- if ( empty( $size ) || ! isset( $size['width'] ) ) {
980
- $size = array( 'width' => 150, 'height' => 150, 'crop' => 'yes' );
981
- }
982
- if ( isset( $size['crop'] ) && $size['crop'] == 'yes' ) {
983
- $size_width = $size['width'];
984
- $size_height = $size['height'];
985
- $resized = $editor2->resize( $size_width, $size_height, true );
986
- if ( is_wp_error( $resized ) ) {
987
- $_message = __( 'Thumbnail of image profile not created', 'learnpress' );
988
- $message = sprintf( $message_template, 'error', $_message );
989
- $res['message'] .= $message;
990
- } else {
991
- $dest_file = $editor2->generate_filename( 'thumb' );
992
- $saved = $editor2->save( $dest_file );
993
- if ( is_wp_error( $saved ) ) {
994
- $_message = __( 'Thumbnail of image profile not created', 'learnpress' );
995
- $message = sprintf( $message_template, 'error', $_message );
996
- $res['message'] .= $message;
997
- } else {
998
- // save thumbnail profile picture to user option
999
- $avatar_thumbnail_filename = pathinfo( $dest_file, PATHINFO_BASENAME );
1000
- update_user_option( $user->get_id(), '_lp_profile_picture_thumbnail_url', $lp_profile_url . $avatar_thumbnail_filename, true );
1001
- }
1002
- }
1003
- }
1004
- }
1005
- }
1006
- #
1007
- # Create Thumbnai for Profile Picture
1008
- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1009
- update_user_option( $user->get_id(), '_lp_profile_picture_type', 'picture', true );
1010
- update_user_option( $user->get_id(), '_lp_profile_picture', $avatar_filename, true );
1011
- update_user_option( $user->get_id(), '_lp_profile_picture_url', $lp_profile_url . $avatar_filename, true );
1012
-
1013
- $_message = __( 'Profile picture is changed', 'learnpress' );
1014
- $message = sprintf( $message_template, 'success', $_message );
1015
- $res['return'] = true;
1016
- $res['message'] .= $message;
1017
- $res['avatar_filename'] = $avatar_filename;
1018
- $res['avatar_url'] = $lp_profile_url . $avatar_filename;
1019
- }
1020
- learn_press_send_json( $res );
1021
- }
1022
- exit();
1023
- }
1024
- #
1025
- # CREATE PROFILE PICTURE & THUMBNAIL
1026
- # - - - - - - - - - - - - - - - - - - - -
1027
-
1028
-
1029
- # - - - - - - - - - - - - - - - - - - - -
1030
- # UPDATE USER INFO
1031
- #
1032
- $return = array();
1033
- $update_data = array(
1034
- 'ID' => $user_id,
1035
- 'first_name' => filter_input( INPUT_POST, 'first_name', FILTER_SANITIZE_STRING ),
1036
- 'last_name' => filter_input( INPUT_POST, 'last_name', FILTER_SANITIZE_STRING ),
1037
- 'display_name' => filter_input( INPUT_POST, 'display_name', FILTER_SANITIZE_STRING ),
1038
- 'nickname' => filter_input( INPUT_POST, 'nickname', FILTER_SANITIZE_STRING ),
1039
- 'description' => filter_input( INPUT_POST, 'description', FILTER_SANITIZE_STRING ),
1040
- );
1041
- # check and update pass word
1042
- if ( ! empty( $_POST['pass0'] ) && ! empty( $_POST['pass1'] ) && ! empty( $_POST['pass1'] ) ) {
1043
- // check old pass
1044
- $old_pass = filter_input( INPUT_POST, 'pass0' );
1045
- $check_old_pass = false;
1046
- if ( ! $old_pass ) {
1047
- $check_old_pass = false;
1048
- } else {
1049
- $cuser = wp_get_current_user();
1050
- require_once( ABSPATH . 'wp-includes/class-phpass.php' );
1051
- $wp_hasher = new PasswordHash( 8, true );
1052
- if ( $wp_hasher->CheckPassword( $old_pass, $cuser->data->user_pass ) ) {
1053
- $check_old_pass = true;
1054
- }
1055
- }
1056
- if ( ! $check_old_pass ) {
1057
- $_message = __( 'Old password incorrect!', 'learnpress' );
1058
- $message = sprintf( $message_template, 'error', $_message );
1059
- $return['return'] = false;
1060
- $return['message'] = $message;
1061
- $return['redirect_url'] = '';
1062
- learn_press_send_json( $return );
1063
- exit();
1064
-
1065
- return;
1066
- } else {
1067
- // check new pass
1068
- $new_pass = filter_input( INPUT_POST, 'pass1' );
1069
- $new_pass2 = filter_input( INPUT_POST, 'pass2' );
1070
- if ( $new_pass != $new_pass2 ) {
1071
- $_message = __( 'Confirmation password incorrect!', 'learnpress' );
1072
- $message = sprintf( $message_template, 'error', $_message );
1073
- $return['return'] = false;
1074
- $return['message'] = $message;
1075
- $return['redirect_url'] = '';
1076
- learn_press_send_json( $return );
1077
- exit();
1078
-
1079
- return;
1080
- } else {
1081
- $update_data['user_pass'] = $new_pass;
1082
- }
1083
- }
1084
- }
1085
-
1086
- $profile_picture_type = filter_input( INPUT_POST, 'profile_picture_type', FILTER_SANITIZE_STRING );
1087
- update_user_option( $user->get_id(), '_lp_profile_picture_type', $profile_picture_type, true );
1088
- $res = wp_update_user( $update_data );
1089
- if ( $res ) {
1090
- $_message = __( 'Your changes are saved', 'learnpress' );
1091
- $message = sprintf( $message_template, 'success', $_message );
1092
- $return['return'] = true;
1093
- $return['message'] = $message;
1094
- $return['redirect_url'] = '';
1095
- learn_press_send_json( $return );
1096
- exit();
1097
- } else {
1098
- $_message = __( 'Error in update your profile info', 'learnpress' );
1099
- $message = sprintf( $message_template, 'error', $_message );
1100
- $return['return'] = false;
1101
- $return['message'] = $message;
1102
- $return['redirect_url'] = '';
1103
- learn_press_send_json( $return );
1104
- exit();
1105
- }
1106
-
1107
- $current_url = learn_press_get_page_link( 'profile' ) . $user->user_login . '/edit';
1108
- wp_redirect( $current_url );
1109
- exit();
1110
- }
1111
- }
1112
-
1113
  if ( ! function_exists( 'learn_press_pre_get_avatar_callback' ) ) {
1114
  /**
1115
  * Filter the avatar
798
  return $user->has_quiz_status( $status, $quiz_id, $course_id );
799
  }
800
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
801
  if ( ! function_exists( 'learn_press_pre_get_avatar_callback' ) ) {
802
  /**
803
  * Filter the avatar
learnpress.php CHANGED
@@ -4,10 +4,10 @@ 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.2.1
8
  Author URI: http://thimpress.com
9
  Requires at least: 3.8
10
- Tested up to: 4.9.6
11
 
12
  Text Domain: learnpress
13
  Domain Path: /languages/
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.2.2
8
  Author URI: http://thimpress.com
9
  Requires at least: 3.8
10
+ Tested up to: 5.0.2
11
 
12
  Text Domain: learnpress
13
  Domain Path: /languages/
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.5
7
- Stable tag: 3.2.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -199,6 +199,12 @@ https://www.transifex.com/projects/p/learnpress/
199
  8. Add-ons of LearnPress.
200
 
201
  == Changelog ==
 
 
 
 
 
 
202
  = 3.2.1 =
203
  ~ Fixed can't enroll course.
204
  ~ Fixed upload issue and drag user avatar on mobile.
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.5
7
+ Stable tag: 3.2.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
199
  8. Add-ons of LearnPress.
200
 
201
  == Changelog ==
202
+ = 3.2.2 =
203
+ ~ Fixed review quiz doesn't work properly.
204
+ ~ Fixed table session create a lot of rows.
205
+ ~ Fixed can't enroll to a course purchased.
206
+ ~ Removed unused functions.
207
+
208
  = 3.2.1 =
209
  ~ Fixed can't enroll course.
210
  ~ Fixed upload issue and drag user avatar on mobile.