LearnPress – WordPress LMS Plugin - Version 3.1.0

Version Description

~ Fixed issue vulnerabilities. ~ Fixed issue related to object cache when doing quiz. ~ Fixed lesson 404 with Polylang. ~ Fixed PHP Fatal error class LP_Plugins_Helper not found

Download this release

Release Info

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

Code changes from version 3.0.12.1 to 3.1.0

Files changed (43) hide show
  1. inc/admin/lp-admin-actions.php +33 -39
  2. inc/cache.php +572 -0
  3. inc/class-lp-helper.php +1 -1
  4. inc/class-lp-install.php +1 -9
  5. inc/class-lp-page-controller.php +1 -1
  6. inc/class-lp-preview-course.php +2 -2
  7. inc/class-lp-query.php +70 -51
  8. inc/class-lp-session-handler.php +4 -4
  9. inc/class-lp-settings.php +4 -4
  10. inc/class-lp-strings.php +3 -3
  11. inc/course/abstract-course.php +10 -10
  12. inc/course/class-lp-course-item.php +10 -10
  13. inc/course/class-lp-course-section.php +1 -1
  14. inc/course/class-lp-course.php +1 -1
  15. inc/course/lp-course-functions.php +4 -4
  16. inc/curds/class-lp-course-curd.php +26 -26
  17. inc/curds/class-lp-helper-curd.php +1 -1
  18. inc/curds/class-lp-order-curd.php +4 -4
  19. inc/curds/class-lp-question-curd.php +4 -4
  20. inc/curds/class-lp-quiz-curd.php +5 -5
  21. inc/curds/class-lp-section-curd.php +10 -10
  22. inc/curds/class-lp-user-curd.php +22 -22
  23. inc/curds/class-lp-user-item-curd.php +6 -6
  24. inc/custom-post-types/abstract.php +50 -7
  25. inc/custom-post-types/course.php +11 -36
  26. inc/custom-post-types/lesson.php +1 -29
  27. inc/custom-post-types/order.php +30 -128
  28. inc/custom-post-types/question.php +10 -12
  29. inc/custom-post-types/quiz.php +10 -47
  30. inc/interfaces/interface-curd.php +1 -1
  31. inc/lp-constants.php +1 -1
  32. inc/lp-core-functions.php +8 -8
  33. inc/order/class-lp-order.php +1 -1
  34. inc/question/class-lp-question.php +3 -3
  35. inc/quiz/class-lp-quiz-factory.php +21 -10
  36. inc/user-item/class-lp-user-item-course.php +14 -14
  37. inc/user-item/class-lp-user-item-quiz.php +2 -2
  38. inc/user-item/class-lp-user-item.php +1 -1
  39. inc/user/abstract-lp-user.php +13 -13
  40. inc/user/class-lp-user-factory.php +2 -2
  41. inc/user/lp-user-functions.php +4 -4
  42. learnpress.php +5 -2
  43. readme.txt +8 -137
inc/admin/lp-admin-actions.php CHANGED
@@ -23,7 +23,8 @@ function _learn_press_set_user_items( $query ) {
23
  LP_LESSON_CPT,
24
  LP_QUIZ_CPT,
25
  LP_QUESTION_CPT
26
- ) ) ) ) {
 
27
  return;
28
  }
29
  $items = $wpdb->get_col(
@@ -152,49 +153,42 @@ if ( ! function_exists( 'learnpress_dashboard_widgets' ) ) {
152
  }
153
 
154
  /**
155
- * Add js to footer for activating course menu if user is viewing/editing course
 
 
156
  */
157
- function learn_press_show_menu() {
158
- if ( ( isset( $_GET['post_type'] ) && $_GET['post_type'] == 'lp_course' ) ) {
159
- ?>
160
- <script type="text/javascript">
161
- jQuery(window).load(function ($) {
162
- <?php
163
- if ( isset ( $_GET['taxonomy'] ) ) {
164
- ?>
165
- jQuery("body").removeClass("sticky-menu");
166
- jQuery("#toplevel_page_learn_press").addClass('wp-has-current-submenu wp-menu-open').removeClass('wp-not-current-submenu');
167
- jQuery("#toplevel_page_learn_press > a").addClass('wp-has-current-submenu wp-menu-open').removeClass('wp-not-current-submenu');
168
- <?php
169
- }
170
- ?>
171
- jQuery("#toplevel_page_learn_press .wp-first-item").addClass('current');
172
- });
173
- </script>
174
- <?php
175
- }
176
-
177
- if ( isset( $_GET['post_type'] ) ) {
178
- ?>
179
- <script type="text/javascript">
180
- (function ($) {
181
-
182
- var $lpMainMenu = $('#toplevel_page_learn_press'),
183
- href = 'edit.php?post_type=<?php echo $_GET['post_type']; ?>',
184
- $current = $('a[href="' + href + '"]', $lpMainMenu);
185
-
186
- if ($current.length) {
187
- $current.addClass('current');
188
- $current.parent('li').addClass('current');
189
- }
190
- })(jQuery)
191
- </script>
192
- <?php
193
 
 
 
194
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
195
  }
196
 
197
- add_action( 'admin_footer', 'learn_press_show_menu' );
198
 
199
  /*
200
  * Display tabs related to course in admin when user
23
  LP_LESSON_CPT,
24
  LP_QUIZ_CPT,
25
  LP_QUESTION_CPT
26
+ ) ) )
27
+ ) {
28
  return;
29
  }
30
  $items = $wpdb->get_col(
153
  }
154
 
155
  /**
156
+ * Active Courses menu under LearnPress
157
+ * when user is editing course and course
158
+ * category.
159
  */
160
+ function learn_press_active_course_menu() {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
161
 
162
+ if ( ! $post_type = LP_Request::get( 'post_type' ) ) {
163
+ return;
164
  }
165
+
166
+ ?>
167
+ <script type="text/javascript">
168
+ jQuery(function ($) {
169
+ var $lpMainMenu = $('#toplevel_page_learn_press'),
170
+ href = 'edit.php?post_type=<?php echo esc_js( $_GET['post_type'] ); ?>',
171
+ $current = $('a[href="' + href + '"]', $lpMainMenu);
172
+
173
+ if ($current.length) {
174
+ $current.addClass('current');
175
+ $current.parent('li').addClass('current');
176
+ }
177
+
178
+ <?php if ( $post_type === LP_COURSE_CPT && LP_Request::get( 'taxonomy' ) === 'course_category' ) {?>
179
+ $("body").removeClass('sticky-menu');
180
+ $lpMainMenu.addClass('wp-has-current-submenu wp-menu-open').removeClass('wp-not-current-submenu');
181
+ $lpMainMenu.children('a').addClass('wp-has-current-submenu wp-menu-open').removeClass('wp-not-current-submenu');
182
+ <?php
183
+ }
184
+ ?>
185
+ $lpMainMenu.find('.wp-first-item').addClass('current');
186
+ });
187
+ </script>
188
+ <?php
189
  }
190
 
191
+ add_action( 'admin_footer', 'learn_press_active_course_menu' );
192
 
193
  /*
194
  * Display tabs related to course in admin when user
inc/cache.php ADDED
@@ -0,0 +1,572 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class LP_Object_Cache {
4
+
5
+ /**
6
+ * Holds the cached objects.
7
+ *
8
+ * @since 2.0.0
9
+ * @var array
10
+ */
11
+ private $cache = array();
12
+
13
+ /**
14
+ * The amount of times the cache data was already stored in the cache.
15
+ *
16
+ * @since 2.5.0
17
+ * @var int
18
+ */
19
+ public $cache_hits = 0;
20
+
21
+ /**
22
+ * Amount of times the cache did not have the request in cache.
23
+ *
24
+ * @since 2.0.0
25
+ * @var int
26
+ */
27
+ public $cache_misses = 0;
28
+
29
+ /**
30
+ * List of global cache groups.
31
+ *
32
+ * @since 3.0.0
33
+ * @var array
34
+ */
35
+ protected $global_groups = array();
36
+
37
+ /**
38
+ * The blog prefix to prepend to keys in non-global groups.
39
+ *
40
+ * @since 3.5.0
41
+ * @var int
42
+ */
43
+ private $blog_prefix;
44
+
45
+ /**
46
+ * Holds the value of is_multisite().
47
+ *
48
+ * @since 3.5.0
49
+ * @var bool
50
+ */
51
+ private $multisite;
52
+
53
+ /**
54
+ * @var bool
55
+ */
56
+ protected static $_use_core = false;
57
+
58
+ /**
59
+ * @var LP_Object_Cache
60
+ */
61
+ protected static $instance = null;
62
+
63
+ /**
64
+ * @return LP_Object_Cache
65
+ */
66
+ public static function instance() {
67
+ if ( ! self::$instance ) {
68
+ self::$instance = new self();
69
+ }
70
+
71
+ return self::$instance;
72
+ }
73
+
74
+ public static function init() {
75
+ add_action( 'shutdown', array( __CLASS__, 'wp_cache_flush' ), 9999 );
76
+ }
77
+
78
+ public static function wp_cache_flush() {
79
+
80
+ }
81
+
82
+ /**
83
+ * Makes private properties readable for backward compatibility.
84
+ *
85
+ * @since 4.0.0
86
+ *
87
+ * @param string $name Property to get.
88
+ *
89
+ * @return mixed Property.
90
+ */
91
+ public function __get( $name ) {
92
+ return $this->$name;
93
+ }
94
+
95
+ /**
96
+ * Makes private properties settable for backward compatibility.
97
+ *
98
+ * @since 4.0.0
99
+ *
100
+ * @param string $name Property to set.
101
+ * @param mixed $value Property value.
102
+ *
103
+ * @return mixed Newly-set property.
104
+ */
105
+ public function __set( $name, $value ) {
106
+ return $this->$name = $value;
107
+ }
108
+
109
+ /**
110
+ * Makes private properties checkable for backward compatibility.
111
+ *
112
+ * @since 4.0.0
113
+ *
114
+ * @param string $name Property to check if set.
115
+ *
116
+ * @return bool Whether the property is set.
117
+ */
118
+ public function __isset( $name ) {
119
+ return isset( $this->$name );
120
+ }
121
+
122
+ /**
123
+ * Makes private properties un-settable for backward compatibility.
124
+ *
125
+ * @since 4.0.0
126
+ *
127
+ * @param string $name Property to unset.
128
+ */
129
+ public function __unset( $name ) {
130
+ unset( $this->$name );
131
+ }
132
+
133
+ /**
134
+ * Adds data to the cache if it doesn't already exist.
135
+ *
136
+ * @since 2.0.0
137
+ *
138
+ * @uses WP_Object_Cache::_exists() Checks to see if the cache already has data.
139
+ * @uses WP_Object_Cache::set() Sets the data after the checking the cache
140
+ * contents existence.
141
+ *
142
+ * @param int|string $key What to call the contents in the cache.
143
+ * @param mixed $data The contents to store in the cache.
144
+ * @param string $group Optional. Where to group the cache contents. Default 'default'.
145
+ * @param int $expire Optional. When to expire the cache contents. Default 0 (no expiration).
146
+ *
147
+ * @return bool False if cache key and group already exist, true on success
148
+ */
149
+ public static function add( $key, $data, $group = 'default', $expire = 0 ) {
150
+
151
+ if ( self::$_use_core ) {
152
+ return wp_cache_add( $key, $data, $group, $expire );
153
+ }
154
+
155
+ if ( wp_suspend_cache_addition() ) {
156
+ return false;
157
+ }
158
+
159
+ if ( empty( $group ) ) {
160
+ $group = 'default';
161
+ }
162
+
163
+ $self = self::instance();
164
+
165
+ $id = $key;
166
+ if ( $self->multisite && ! isset( $self->global_groups[ $group ] ) ) {
167
+ $id = $self->blog_prefix . $key;
168
+ }
169
+
170
+ if ( self::_exists( $id, $group ) ) {
171
+ return false;
172
+ }
173
+
174
+ return self::set( $key, $data, $group, (int) $expire );
175
+ }
176
+
177
+ /**
178
+ * Sets the list of global cache groups.
179
+ *
180
+ * @since 3.0.0
181
+ *
182
+ * @param array $groups List of groups that are global.
183
+ */
184
+ public static function add_global_groups( $groups ) {
185
+ $groups = (array) $groups;
186
+ $self = self::instance();
187
+
188
+ $groups = array_fill_keys( $groups, true );
189
+ $self->global_groups = array_merge( $self->global_groups, $groups );
190
+ }
191
+
192
+ /**
193
+ * Decrements numeric cache item's value.
194
+ *
195
+ * @since 3.3.0
196
+ *
197
+ * @param int|string $key The cache key to decrement.
198
+ * @param int $offset Optional. The amount by which to decrement the item's value. Default 1.
199
+ * @param string $group Optional. The group the key is in. Default 'default'.
200
+ *
201
+ * @return false|int False on failure, the item's new value on success.
202
+ */
203
+ public static function decr( $key, $offset = 1, $group = 'default' ) {
204
+ if ( empty( $group ) ) {
205
+ $group = 'default';
206
+ }
207
+
208
+ $self = self::instance();
209
+
210
+ if ( $self->multisite && ! isset( $self->global_groups[ $group ] ) ) {
211
+ $key = $self->blog_prefix . $key;
212
+ }
213
+
214
+ if ( ! self::_exists( $key, $group ) ) {
215
+ return false;
216
+ }
217
+
218
+ if ( ! is_numeric( $self->cache[ $group ][ $key ] ) ) {
219
+ $self->cache[ $group ][ $key ] = 0;
220
+ }
221
+
222
+ $offset = (int) $offset;
223
+
224
+ $self->cache[ $group ][ $key ] -= $offset;
225
+
226
+ if ( $self->cache[ $group ][ $key ] < 0 ) {
227
+ $self->cache[ $group ][ $key ] = 0;
228
+ }
229
+
230
+ return $self->cache[ $group ][ $key ];
231
+ }
232
+
233
+ /**
234
+ * Removes the contents of the cache key in the group.
235
+ *
236
+ * If the cache key does not exist in the group, then nothing will happen.
237
+ *
238
+ * @since 2.0.0
239
+ *
240
+ * @param int|string $key What the contents in the cache are called.
241
+ * @param string $group Optional. Where the cache contents are grouped. Default 'default'.
242
+ * @param bool $deprecated Optional. Unused. Default false.
243
+ *
244
+ * @return bool False if the contents weren't deleted and true on success.
245
+ */
246
+ public static function delete( $key, $group = 'default', $deprecated = false ) {
247
+
248
+ if ( self::$_use_core ) {
249
+ return wp_cache_delete( $key, $group );
250
+ }
251
+
252
+ if ( empty( $group ) ) {
253
+ $group = 'default';
254
+ }
255
+
256
+ $self = self::instance();
257
+
258
+ if ( $self->multisite && ! isset( $self->global_groups[ $group ] ) ) {
259
+ $key = $self->blog_prefix . $key;
260
+ }
261
+
262
+ if ( ! self::_exists( $key, $group ) ) {
263
+ return false;
264
+ }
265
+
266
+ unset( $self->cache[ $group ][ $key ] );
267
+
268
+ return true;
269
+ }
270
+
271
+ /**
272
+ * Clears the object cache of all data.
273
+ *
274
+ * @since 2.0.0
275
+ *
276
+ * @return true Always returns true.
277
+ */
278
+ public static function flush() {
279
+ if ( self::$_use_core ) {
280
+ return wp_cache_flush();
281
+ }
282
+
283
+ $self = self::instance();
284
+
285
+ $self->cache = array();
286
+
287
+ return true;
288
+ }
289
+
290
+ /**
291
+ * Retrieves the cache contents, if it exists.
292
+ *
293
+ * The contents will be first attempted to be retrieved by searching by the
294
+ * key in the cache group. If the cache is hit (success) then the contents
295
+ * are returned.
296
+ *
297
+ * On failure, the number of cache misses will be incremented.
298
+ *
299
+ * @since 2.0.0
300
+ *
301
+ * @param int|string $key What the contents in the cache are called.
302
+ * @param string $group Optional. Where the cache contents are grouped. Default 'default'.
303
+ * @param string $force Optional. Unused. Whether to force a refetch rather than relying on the local
304
+ * cache. Default false.
305
+ * @param bool $found Optional. Whether the key was found in the cache (passed by reference).
306
+ * Disambiguates a return of false, a storable value. Default null.
307
+ *
308
+ * @return false|mixed False on failure to retrieve contents or the cache contents on success.
309
+ */
310
+ public static function get( $key, $group = 'default', $force = false, &$found = null ) {
311
+
312
+ if ( self::$_use_core ) {
313
+ return wp_cache_get( $key, $group, $force, $found );
314
+ }
315
+
316
+ if ( empty( $group ) ) {
317
+ $group = 'default';
318
+ }
319
+
320
+ $self = self::instance();
321
+
322
+ if ( $self->multisite && ! isset( $self->global_groups[ $group ] ) ) {
323
+ $key = $self->blog_prefix . $key;
324
+ }
325
+
326
+ if ( self::_exists( $key, $group ) ) {
327
+ $found = true;
328
+ $self->cache_hits += 1;
329
+ if ( is_object( $self->cache[ $group ][ $key ] ) ) {
330
+ return clone $self->cache[ $group ][ $key ];
331
+ } else {
332
+ return $self->cache[ $group ][ $key ];
333
+ }
334
+ }
335
+
336
+ $found = false;
337
+ $self->cache_misses += 1;
338
+
339
+ return false;
340
+ }
341
+
342
+ /**
343
+ * Increments numeric cache item's value.
344
+ *
345
+ * @since 3.3.0
346
+ *
347
+ * @param int|string $key The cache key to increment
348
+ * @param int $offset Optional. The amount by which to increment the item's value. Default 1.
349
+ * @param string $group Optional. The group the key is in. Default 'default'.
350
+ *
351
+ * @return false|int False on failure, the item's new value on success.
352
+ */
353
+ public static function incr( $key, $offset = 1, $group = 'default' ) {
354
+ if ( empty( $group ) ) {
355
+ $group = 'default';
356
+ }
357
+ $self = self::instance();
358
+
359
+ if ( $self->multisite && ! isset( $self->global_groups[ $group ] ) ) {
360
+ $key = $self->blog_prefix . $key;
361
+ }
362
+
363
+ if ( ! self::_exists( $key, $group ) ) {
364
+ return false;
365
+ }
366
+
367
+ if ( ! is_numeric( $self->cache[ $group ][ $key ] ) ) {
368
+ $self->cache[ $group ][ $key ] = 0;
369
+ }
370
+
371
+ $offset = (int) $offset;
372
+
373
+ $self->cache[ $group ][ $key ] += $offset;
374
+
375
+ if ( $self->cache[ $group ][ $key ] < 0 ) {
376
+ $self->cache[ $group ][ $key ] = 0;
377
+ }
378
+
379
+ return $self->cache[ $group ][ $key ];
380
+ }
381
+
382
+ /**
383
+ * Replaces the contents in the cache, if contents already exist.
384
+ *
385
+ * @since 2.0.0
386
+ *
387
+ * @see WP_Object_Cache::set()
388
+ *
389
+ * @param int|string $key What to call the contents in the cache.
390
+ * @param mixed $data The contents to store in the cache.
391
+ * @param string $group Optional. Where to group the cache contents. Default 'default'.
392
+ * @param int $expire Optional. When to expire the cache contents. Default 0 (no expiration).
393
+ *
394
+ * @return bool False if not exists, true if contents were replaced.
395
+ */
396
+ public static function replace( $key, $data, $group = 'default', $expire = 0 ) {
397
+
398
+ if ( self::$_use_core ) {
399
+ return wp_cache_replace( $key, $data, $group, $expire );
400
+ }
401
+
402
+ if ( empty( $group ) ) {
403
+ $group = 'default';
404
+ }
405
+
406
+ $self = self::instance();
407
+
408
+ $id = $key;
409
+ if ( $self->multisite && ! isset( $self->global_groups[ $group ] ) ) {
410
+ $id = $self->blog_prefix . $key;
411
+ }
412
+
413
+ if ( ! self::_exists( $id, $group ) ) {
414
+ return false;
415
+ }
416
+
417
+ return self::set( $key, $data, $group, (int) $expire );
418
+ }
419
+
420
+ /**
421
+ * Resets cache keys.
422
+ *
423
+ * @since 3.0.0
424
+ *
425
+ * @deprecated 3.5.0 Use switch_to_blog()
426
+ * @see switch_to_blog()
427
+ */
428
+ public static function reset() {
429
+
430
+ $self = self::instance();
431
+
432
+ _deprecated_function( __FUNCTION__, '3.5.0', 'switch_to_blog()' );
433
+
434
+ // Clear out non-global caches since the blog ID has changed.
435
+ foreach ( array_keys( $self->cache ) as $group ) {
436
+ if ( ! isset( $self->global_groups[ $group ] ) ) {
437
+ unset( $self->cache[ $group ] );
438
+ }
439
+ }
440
+ }
441
+
442
+ /**
443
+ * Sets the data contents into the cache.
444
+ *
445
+ * The cache contents is grouped by the $group parameter followed by the
446
+ * $key. This allows for duplicate ids in unique groups. Therefore, naming of
447
+ * the group should be used with care and should follow normal function
448
+ * naming guidelines outside of core WordPress usage.
449
+ *
450
+ * The $expire parameter is not used, because the cache will automatically
451
+ * expire for each time a page is accessed and PHP finishes. The method is
452
+ * more for cache plugins which use files.
453
+ *
454
+ * @since 2.0.0
455
+ *
456
+ * @param int|string $key What to call the contents in the cache.
457
+ * @param mixed $data The contents to store in the cache.
458
+ * @param string $group Optional. Where to group the cache contents. Default 'default'.
459
+ * @param int $expire Not Used.
460
+ *
461
+ * @return true Always returns true.
462
+ */
463
+ public static function set( $key, $data, $group = 'default', $expire = 0 ) {
464
+
465
+ if ( self::$_use_core ) {
466
+ return wp_cache_set( $key, $data, $group, $expire );
467
+ }
468
+
469
+ if ( empty( $group ) ) {
470
+ $group = 'default';
471
+ }
472
+
473
+ $self = self::instance();
474
+
475
+ if ( $self->multisite && ! isset( $self->global_groups[ $group ] ) ) {
476
+ $key = $self->blog_prefix . $key;
477
+ }
478
+
479
+ if ( is_object( $data ) ) {
480
+ $data = clone $data;
481
+ }
482
+
483
+ $self->cache[ $group ][ $key ] = $data;
484
+
485
+ return true;
486
+ }
487
+
488
+ /**
489
+ * Echoes the stats of the caching.
490
+ *
491
+ * Gives the cache hits, and cache misses. Also prints every cached group,
492
+ * key and the data.
493
+ *
494
+ * @since 2.0.0
495
+ */
496
+ public static function stats() {
497
+ $self = self::instance();
498
+ echo "<p>";
499
+ echo "<strong>Cache Hits:</strong> {$self->cache_hits}<br />";
500
+ echo "<strong>Cache Misses:</strong> {$self->cache_misses}<br />";
501
+ echo "</p>";
502
+ echo '<ul>';
503
+ foreach ( $self->cache as $group => $cache ) {
504
+ echo "<li><strong>Group:</strong> $group - ( " . number_format( strlen( serialize( $cache ) ) / KB_IN_BYTES, 2 ) . 'k )</li>';
505
+ }
506
+ echo '</ul>';
507
+ }
508
+
509
+ /**
510
+ * Switches the internal blog ID.
511
+ *
512
+ * This changes the blog ID used to create keys in blog specific groups.
513
+ *
514
+ * @since 3.5.0
515
+ *
516
+ * @param int $blog_id Blog ID.
517
+ */
518
+ public static function switch_to_blog( $blog_id ) {
519
+ $self = self::instance();
520
+
521
+ $blog_id = (int) $blog_id;
522
+ $self->blog_prefix = $self->multisite ? $blog_id . ':' : '';
523
+ }
524
+
525
+ /**
526
+ * Serves as a utility function to determine whether a key exists in the cache.
527
+ *
528
+ * @since 3.4.0
529
+ *
530
+ * @param int|string $key Cache key to check for existence.
531
+ * @param string $group Cache group for the key existence check.
532
+ *
533
+ * @return bool Whether the key exists in the cache for the given group.
534
+ */
535
+ protected static function _exists( $key, $group ) {
536
+ $self = self::instance();
537
+
538
+ return isset( $self->cache[ $group ] ) && ( isset( $self->cache[ $group ][ $key ] ) || array_key_exists( $key, $self->cache[ $group ] ) );
539
+ }
540
+
541
+ /**
542
+ * Sets up object properties; PHP 5 style constructor.
543
+ *
544
+ * @since 2.0.8
545
+ */
546
+ public function __construct() {
547
+ $this->multisite = is_multisite();
548
+ $this->blog_prefix = $this->multisite ? get_current_blog_id() . ':' : '';
549
+
550
+
551
+ /**
552
+ * @todo This should be moved to the PHP4 style constructor, PHP5
553
+ * already calls __destruct()
554
+ */
555
+ register_shutdown_function( array( $this, '__destruct' ) );
556
+ }
557
+
558
+ /**
559
+ * Saves the object cache before object is completely destroyed.
560
+ *
561
+ * Called upon object destruction, which should be when PHP ends.
562
+ *
563
+ * @since 2.0.8
564
+ *
565
+ * @return true Always returns true.
566
+ */
567
+ public function __destruct() {
568
+ return true;
569
+ }
570
+ }
571
+
572
+ LP_Object_Cache::init();
inc/class-lp-helper.php CHANGED
@@ -292,7 +292,7 @@ class LP_Helper {
292
  // Update cache
293
  $page_ids = learn_press_static_page_ids();
294
  $page_ids[ $assign_to ] = $page_id;
295
- wp_cache_set( 'static-page-ids', $page_ids, 'learnpress' );
296
  }
297
  }
298
 
292
  // Update cache
293
  $page_ids = learn_press_static_page_ids();
294
  $page_ids[ $assign_to ] = $page_id;
295
+ LP_Object_Cache::set( 'static-page-ids', $page_ids, 'learnpress' );
296
  }
297
  }
298
 
inc/class-lp-install.php CHANGED
@@ -74,7 +74,7 @@ if ( ! function_exists( 'LP_Install' ) ) {
74
  }
75
 
76
  if ( ! empty( $_REQUEST['redirect'] ) ) {
77
- wp_redirect( urldecode( $_REQUEST['redirect'] ) );
78
  }
79
  }
80
 
@@ -172,14 +172,6 @@ if ( ! function_exists( 'LP_Install' ) ) {
172
 
173
  self::update_db_version();
174
  self::update_version();
175
-
176
- return;
177
- // Fix for WP 4.7
178
- if ( did_action( 'admin_init' ) ) {
179
- self::_auto_update();
180
- } else {
181
- add_action( 'admin_init', array( __CLASS__, '_auto_update' ), - 15 );
182
- }
183
  }
184
 
185
  protected static function _clear_backgrounds() {
74
  }
75
 
76
  if ( ! empty( $_REQUEST['redirect'] ) ) {
77
+ wp_safe_redirect( urldecode( $_REQUEST['redirect'] ) );
78
  }
79
  }
80
 
172
 
173
  self::update_db_version();
174
  self::update_version();
 
 
 
 
 
 
 
 
175
  }
176
 
177
  protected static function _clear_backgrounds() {
inc/class-lp-page-controller.php CHANGED
@@ -627,7 +627,7 @@ class LP_Page_Controller {
627
 
628
  add_filter( 'the_content', array( $this, 'single_content' ), $this->_filter_content_priority );
629
 
630
- wp_cache_set( 'course-' . get_the_ID(), $content, 'course-content' );
631
 
632
  return $content;
633
  }
627
 
628
  add_filter( 'the_content', array( $this, 'single_content' ), $this->_filter_content_priority );
629
 
630
+ LP_Object_Cache::set( 'course-' . get_the_ID(), $content, 'course-content' );
631
 
632
  return $content;
633
  }
inc/class-lp-preview-course.php CHANGED
@@ -158,7 +158,7 @@ class LP_Preview_Course {
158
  }
159
 
160
  public static function get_preview_courses() {
161
- if ( false === ( $ids = wp_cache_get( 'preview-courses', 'learnpress' ) ) ) {
162
  global $wpdb;
163
  $query = $wpdb->prepare( "
164
  SELECT post_id
@@ -167,7 +167,7 @@ class LP_Preview_Course {
167
  ", '_lp_preview_course', 'yes' );
168
 
169
  $ids = $wpdb->get_col( $query );
170
- wp_cache_set( 'preview-courses', $ids, 'learnpress' );
171
  }
172
 
173
  return $ids;
158
  }
159
 
160
  public static function get_preview_courses() {
161
+ if ( false === ( $ids = LP_Object_Cache::get( 'preview-courses', 'learnpress' ) ) ) {
162
  global $wpdb;
163
  $query = $wpdb->prepare( "
164
  SELECT post_id
167
  ", '_lp_preview_course', 'yes' );
168
 
169
  $ids = $wpdb->get_col( $query );
170
+ LP_Object_Cache::set( 'preview-courses', $ids, 'learnpress' );
171
  }
172
 
173
  return $ids;
inc/class-lp-query.php CHANGED
@@ -113,18 +113,17 @@ class LP_Query {
113
  */
114
  function add_rewrite_rules() {
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;
 
122
  if ( preg_match( '!(%?course_category%?)!', $slug ) ) {
123
  $slug = preg_replace( '!(%?course_category%?)!', '(.+?)/([^/]+)', $slug );
124
  $has_category = true;
125
  }
126
- $current_url = learn_press_get_current_url();
127
- $query_string = str_replace( trailingslashit( get_home_url() /* SITE_URL */ ), '', $current_url );
128
  $custom_slug_lesson = sanitize_title_with_dashes( LP()->settings->get( 'lesson_slug' ) );
129
  $custom_slug_quiz = sanitize_title_with_dashes( LP()->settings->get( 'quiz_slug' ) );
130
 
@@ -136,68 +135,47 @@ class LP_Query {
136
  if ( ! empty( $custom_slug_lesson ) ) {
137
  $post_types['lp_lesson']->rewrite['slug'] = urldecode( $custom_slug_lesson );
138
  }
 
139
  if ( ! empty( $custom_slug_quiz ) ) {
140
  $post_types['lp_quiz']->rewrite['slug'] = urldecode( $custom_slug_quiz );
141
  }
142
 
143
- $popup_slug = 'popup';
 
144
  if ( $has_category ) {
145
- add_rewrite_rule(
146
  '^' . $slug . '(?:/' . $post_types['lp_lesson']->rewrite['slug'] . '/([^/]+))/?$',
147
  'index.php?' . $course_type . '=$matches[2]&course_category=$matches[1]&course-item=$matches[3]&item-type=lp_lesson',
148
  'top'
149
  );
150
- add_rewrite_rule(
 
151
  '^' . $slug . '(?:/' . $post_types['lp_quiz']->rewrite['slug'] . '/([^/]+)/?([^/]+)?)/?$',
152
  'index.php?' . $course_type . '=$matches[2]&course_category=$matches[1]&course-item=$matches[3]&question=$matches[4]&item-type=lp_quiz',
153
  'top'
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(
 
 
172
  '^' . $slug . '/([^/]+)(?:/' . $post_types['lp_lesson']->rewrite['slug'] . '/([^/]+))/?$',
173
  'index.php?' . $course_type . '=$matches[1]&course-item=$matches[2]&item-type=lp_lesson',
174
  'top'
175
  );
176
- add_rewrite_rule(
177
  '^' . $slug . '/([^/]+)(?:/' . $post_types['lp_quiz']->rewrite['slug'] . '/([^/]+)/?([^/]+)?)/?$',
178
  'index.php?' . $course_type . '=$matches[1]&course-item=$matches[2]&question=$matches[3]&item-type=lp_quiz',
179
  'top'
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
198
  if ( $profile_id = learn_press_get_page_id( 'profile' ) ) {
199
 
200
- add_rewrite_rule(
201
  '^' . get_post_field( 'post_name', $profile_id ) . '/([^/]*)/?$',
202
  'index.php?page_id=' . $profile_id . '&user=$matches[1]',
203
  'top'
@@ -207,7 +185,7 @@ class LP_Query {
207
  if ( $tabs = $profile->get_tabs()->get() ) {
208
  foreach ( $tabs as $slug => $args ) {
209
  $tab_slug = isset( $args['slug'] ) ? $args['slug'] : $slug;
210
- add_rewrite_rule(
211
  '^' . get_post_field( 'post_name', $profile_id ) . '/([^/]*)/?(' . $tab_slug . ')/?([0-9]*)/?$',
212
  'index.php?page_id=' . $profile_id . '&user=$matches[1]&view=$matches[2]&view_id=$matches[3]',
213
  'top'
@@ -216,38 +194,79 @@ class LP_Query {
216
  if ( ! empty( $args['sections'] ) ) {
217
  foreach ( $args['sections'] as $section_slug => $section ) {
218
  $section_slug = isset( $section['slug'] ) ? $section['slug'] : $section_slug;
219
- add_rewrite_rule(
220
  '^' . get_post_field( 'post_name', $profile_id ) . '/([^/]*)/?(' . $tab_slug . ')/(' . $section_slug . ')/?([0-9]*)?$',
221
  'index.php?page_id=' . $profile_id . '&user=$matches[1]&view=$matches[2]&section=$matches[3]&view_id=$matches[4]',
222
  'top'
223
  );
224
  }
225
- // add_rewrite_rule(
226
- // '^' . get_post_field( 'post_name', $profile_id ) . '/([^/]*)/?(' . $tab_slug . ')/([^/]*)/?$',
227
- // 'index.php?page_id=' . $profile_id . '&user=$matches[1]&view=$matches[2]&section=$matches[3]',
228
- // 'top'
229
- // );
230
  }
231
  }
232
- // add_rewrite_rule(
233
- // '^' . get_post_field( 'post_name', $profile_id ) . '/([^/]*)/?([^/]*)/?([0-9]*)/?$',
234
- // 'index.php?page_id=' . $profile_id . '&user=$matches[1]&view=$matches[2]&lp-paged=$matches[3]',
235
- // 'top'
236
- // );
237
  }
238
-
239
-
240
  }
241
 
242
  // Archive course
243
  if ( $course_page_id = learn_press_get_page_id( 'courses' ) ) {
244
- add_rewrite_rule(
245
  '^' . get_post_field( 'post_name', $course_page_id ) . '/page/([0-9]{1,})/?$',
246
  'index.php?pagename=' . get_post_field( 'post_name', $course_page_id ) . '&page=$matches[1]',
247
  'top'
248
  );
249
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
250
  do_action( 'learn_press_add_rewrite_rules' );
 
251
  }
252
 
253
 
113
  */
114
  function add_rewrite_rules() {
115
 
 
116
  // lesson
117
  $course_type = LP_COURSE_CPT;
118
  $post_types = get_post_types( '', 'objects' );
119
  $slug = preg_replace( '!^/!', '', $post_types[ $course_type ]->rewrite['slug'] );
120
  $has_category = false;
121
+
122
  if ( preg_match( '!(%?course_category%?)!', $slug ) ) {
123
  $slug = preg_replace( '!(%?course_category%?)!', '(.+?)/([^/]+)', $slug );
124
  $has_category = true;
125
  }
126
+
 
127
  $custom_slug_lesson = sanitize_title_with_dashes( LP()->settings->get( 'lesson_slug' ) );
128
  $custom_slug_quiz = sanitize_title_with_dashes( LP()->settings->get( 'quiz_slug' ) );
129
 
135
  if ( ! empty( $custom_slug_lesson ) ) {
136
  $post_types['lp_lesson']->rewrite['slug'] = urldecode( $custom_slug_lesson );
137
  }
138
+
139
  if ( ! empty( $custom_slug_quiz ) ) {
140
  $post_types['lp_quiz']->rewrite['slug'] = urldecode( $custom_slug_quiz );
141
  }
142
 
143
+ $rules = array();
144
+
145
  if ( $has_category ) {
146
+ $rules[] = array(
147
  '^' . $slug . '(?:/' . $post_types['lp_lesson']->rewrite['slug'] . '/([^/]+))/?$',
148
  'index.php?' . $course_type . '=$matches[2]&course_category=$matches[1]&course-item=$matches[3]&item-type=lp_lesson',
149
  'top'
150
  );
151
+
152
+ $rules[] = array(
153
  '^' . $slug . '(?:/' . $post_types['lp_quiz']->rewrite['slug'] . '/([^/]+)/?([^/]+)?)/?$',
154
  'index.php?' . $course_type . '=$matches[2]&course_category=$matches[1]&course-item=$matches[3]&question=$matches[4]&item-type=lp_quiz',
155
  'top'
156
  );
157
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
  } else {
159
+ if ( ! empty( $_REQUEST['xxx'] ) ) {
160
+ echo '^' . $slug . '/([^/]+)(?:/' . $post_types['lp_lesson']->rewrite['slug'] . '/([^/]+))/?$';
161
+ }
162
+ $rules[] = array(
163
  '^' . $slug . '/([^/]+)(?:/' . $post_types['lp_lesson']->rewrite['slug'] . '/([^/]+))/?$',
164
  'index.php?' . $course_type . '=$matches[1]&course-item=$matches[2]&item-type=lp_lesson',
165
  'top'
166
  );
167
+ $rules[] = array(
168
  '^' . $slug . '/([^/]+)(?:/' . $post_types['lp_quiz']->rewrite['slug'] . '/([^/]+)/?([^/]+)?)/?$',
169
  'index.php?' . $course_type . '=$matches[1]&course-item=$matches[2]&question=$matches[3]&item-type=lp_quiz',
170
  'top'
171
  );
172
 
 
 
 
 
 
 
 
 
 
 
 
 
 
173
  }
174
 
175
  // Profile
176
  if ( $profile_id = learn_press_get_page_id( 'profile' ) ) {
177
 
178
+ $rules[] = array(
179
  '^' . get_post_field( 'post_name', $profile_id ) . '/([^/]*)/?$',
180
  'index.php?page_id=' . $profile_id . '&user=$matches[1]',
181
  'top'
185
  if ( $tabs = $profile->get_tabs()->get() ) {
186
  foreach ( $tabs as $slug => $args ) {
187
  $tab_slug = isset( $args['slug'] ) ? $args['slug'] : $slug;
188
+ $rules[] = array(
189
  '^' . get_post_field( 'post_name', $profile_id ) . '/([^/]*)/?(' . $tab_slug . ')/?([0-9]*)/?$',
190
  'index.php?page_id=' . $profile_id . '&user=$matches[1]&view=$matches[2]&view_id=$matches[3]',
191
  'top'
194
  if ( ! empty( $args['sections'] ) ) {
195
  foreach ( $args['sections'] as $section_slug => $section ) {
196
  $section_slug = isset( $section['slug'] ) ? $section['slug'] : $section_slug;
197
+ $rules[] = array(
198
  '^' . get_post_field( 'post_name', $profile_id ) . '/([^/]*)/?(' . $tab_slug . ')/(' . $section_slug . ')/?([0-9]*)?$',
199
  'index.php?page_id=' . $profile_id . '&user=$matches[1]&view=$matches[2]&section=$matches[3]&view_id=$matches[4]',
200
  'top'
201
  );
202
  }
 
 
 
 
 
203
  }
204
  }
 
 
 
 
 
205
  }
 
 
206
  }
207
 
208
  // Archive course
209
  if ( $course_page_id = learn_press_get_page_id( 'courses' ) ) {
210
+ $rules[] = array(
211
  '^' . get_post_field( 'post_name', $course_page_id ) . '/page/([0-9]{1,})/?$',
212
  'index.php?pagename=' . get_post_field( 'post_name', $course_page_id ) . '&page=$matches[1]',
213
  'top'
214
  );
215
  }
216
+
217
+ global $wp_rewrite;
218
+
219
+ /**
220
+ * Polylang compatibility
221
+ */
222
+ if ( function_exists( 'PLL' ) ) {
223
+ $pll = PLL();
224
+ $pll_languages = $pll->model->get_languages_list( array( 'fields' => 'slug' ) );
225
+
226
+ if ( $pll->options['hide_default'] ) {
227
+ if ( isset( $pll->options['default_lang'] ) ) {
228
+ $pll_languages = array_diff( $pll_languages, array( $pll->options['default_lang'] ) );
229
+ }
230
+ }
231
+
232
+ if ( ! empty( $pll_languages ) ) {
233
+ $pll_languages = $wp_rewrite->root . ( $pll->options['rewrite'] ? '' : 'language/' ) . '(' . implode( '|', $pll_languages ) . ')/';
234
+ }else{
235
+ $pll_languages = '';
236
+ }
237
+
238
+ }
239
+ $new_rules = array();
240
+ foreach ( $rules as $k => $rule ) {
241
+ $new_rules[] = $rule;
242
+ call_user_func_array( 'add_rewrite_rule', $rule );
243
+
244
+ /**
245
+ * Modify rewrite rule
246
+ */
247
+ if ( isset( $pll_languages ) ) {
248
+
249
+ $rule[0] = $pll_languages . str_replace( $wp_rewrite->root, '', ltrim( $rule[0], '^' ) );
250
+ $rule[1] = str_replace(
251
+ array( '[8]', '[7]', '[6]', '[5]', '[4]', '[3]', '[2]', '[1]', '?' ),
252
+ array( '[9]', '[8]', '[7]', '[6]', '[5]', '[4]', '[3]', '[2]', '?lang=$matches[1]&' ),
253
+ $rule[1]
254
+ );
255
+ $new_rules[] = $rule;
256
+ call_user_func_array( 'add_rewrite_rule', $rule );
257
+ }
258
+ }
259
+
260
+ $new_rules = md5( serialize( $new_rules ) );
261
+ $old_rules = get_transient( 'lp_rewrite_rules_hash' );
262
+
263
+ if ( $old_rules !== $new_rules ) {
264
+ set_transient( 'lp_rewrite_rules_hash', $new_rules, DAY_IN_SECONDS );
265
+ flush_rewrite_rules();
266
+ }
267
+
268
  do_action( 'learn_press_add_rewrite_rules' );
269
+
270
  }
271
 
272
 
inc/class-lp-session-handler.php CHANGED
@@ -180,11 +180,11 @@ class LP_Session_Handler implements ArrayAccess {
180
  }
181
 
182
  public function get_cache_prefix( $group = LP_SESSION_CACHE_GROUP ) {
183
- $prefix = wp_cache_get( 'learn_press_' . $group . '_cache_prefix', $group );
184
 
185
  if ( false === $prefix ) {
186
  $prefix = 1;
187
- wp_cache_set( 'learn_press_' . $group . '_cache_prefix', $prefix, $group );
188
  }
189
 
190
  return 'learn_press_cache_' . $prefix . '_';
@@ -220,7 +220,7 @@ class LP_Session_Handler implements ArrayAccess {
220
  );
221
 
222
  // Set cache
223
- wp_cache_set( $this->get_cache_prefix() . $this->_customer_id, $this->_data, LP_SESSION_CACHE_GROUP, $this->_session_expiration - time() );
224
 
225
  // Mark session clean after saving
226
  $this->_changed = false;
@@ -272,7 +272,7 @@ class LP_Session_Handler implements ArrayAccess {
272
  }
273
 
274
  // Try get it from the cache, it will return false if not present or if object cache not in use
275
- $value = wp_cache_get( $this->get_cache_prefix() . $customer_id, LP_SESSION_CACHE_GROUP );
276
  ///echo "KEY:" . $this->get_cache_prefix() . $customer_id . "]";
277
  if ( false === $value ) {
278
  $q = $wpdb->prepare( "SELECT session_value FROM $this->_table WHERE session_key = %s", $customer_id );
180
  }
181
 
182
  public function get_cache_prefix( $group = LP_SESSION_CACHE_GROUP ) {
183
+ $prefix = LP_Object_Cache::get( 'learn_press_' . $group . '_cache_prefix', $group );
184
 
185
  if ( false === $prefix ) {
186
  $prefix = 1;
187
+ LP_Object_Cache::set( 'learn_press_' . $group . '_cache_prefix', $prefix, $group );
188
  }
189
 
190
  return 'learn_press_cache_' . $prefix . '_';
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() );
224
 
225
  // Mark session clean after saving
226
  $this->_changed = false;
272
  }
273
 
274
  // Try get it from the cache, it will return false if not present or if object cache not in use
275
+ $value = LP_Object_Cache::get( $this->get_cache_prefix() . $customer_id, LP_SESSION_CACHE_GROUP );
276
  ///echo "KEY:" . $this->get_cache_prefix() . $customer_id . "]";
277
  if ( false === $value ) {
278
  $q = $wpdb->prepare( "SELECT session_value FROM $this->_table WHERE session_key = %s", $customer_id );
inc/class-lp-settings.php CHANGED
@@ -340,7 +340,7 @@ class LP_Settings {
340
  * @return array
341
  */
342
  public function get_checkout_endpoints() {
343
- if ( false === ( $endpoints = wp_cache_get( 'checkout', 'learn-press-endpoints' ) ) ) {
344
  $defaults = array(
345
  'lp-order-received' => 'lp-order-received'
346
  );
@@ -359,7 +359,7 @@ class LP_Settings {
359
  }
360
  }
361
 
362
- wp_cache_set( 'checkout', $endpoints, 'learn-press-endpoints' );
363
  }
364
 
365
  return apply_filters( 'learn-press/endpoints/checkout', $endpoints );
@@ -373,7 +373,7 @@ class LP_Settings {
373
  * @return array
374
  */
375
  public function get_profile_endpoints() {
376
- if ( false === ( $endpoints = wp_cache_get( 'profile', 'learn-press-endpoints' ) ) ) {
377
  $defaults = array();
378
 
379
  $endpoints = array();
@@ -390,7 +390,7 @@ class LP_Settings {
390
  }
391
  }
392
 
393
- wp_cache_set( 'profile', $endpoints, 'learn-press-endpoints' );
394
  }
395
 
396
  return apply_filters( 'learn-press/endpoints/profile', $endpoints );
340
  * @return array
341
  */
342
  public function get_checkout_endpoints() {
343
+ if ( false === ( $endpoints = LP_Object_Cache::get( 'checkout', 'learn-press-endpoints' ) ) ) {
344
  $defaults = array(
345
  'lp-order-received' => 'lp-order-received'
346
  );
359
  }
360
  }
361
 
362
+ LP_Object_Cache::set( 'checkout', $endpoints, 'learn-press-endpoints' );
363
  }
364
 
365
  return apply_filters( 'learn-press/endpoints/checkout', $endpoints );
373
  * @return array
374
  */
375
  public function get_profile_endpoints() {
376
+ if ( false === ( $endpoints = LP_Object_Cache::get( 'profile', 'learn-press-endpoints' ) ) ) {
377
  $defaults = array();
378
 
379
  $endpoints = array();
390
  }
391
  }
392
 
393
+ LP_Object_Cache::set( 'profile', $endpoints, 'learn-press-endpoints' );
394
  }
395
 
396
  return apply_filters( 'learn-press/endpoints/profile', $endpoints );
inc/class-lp-strings.php CHANGED
@@ -10,7 +10,7 @@ if ( isset( $strings ) ) {
10
  $__strings = $strings;
11
  }
12
 
13
- if ( false === ( $strings = wp_cache_get( 'strings', 'learnpress' ) ) ) {
14
 
15
  $strings = array(
16
  'confirm-redo-quiz' => __( 'Do you want to redo quiz "%s"?', 'learnpress' ),
@@ -20,7 +20,7 @@ if ( false === ( $strings = wp_cache_get( 'strings', 'learnpress' ) ) ) {
20
  'confirm-retake-course' => __( 'Do you want to retake course "%s"?', 'learnpress' ),
21
  );
22
 
23
- wp_cache_set( 'strings', $strings, 'learnpress' );
24
  }
25
 
26
  /**
@@ -33,7 +33,7 @@ if ( isset( $__strings ) ) {
33
  class LP_Strings {
34
  public static function get( $str, $context = '', $args = '' ) {
35
  $string = $str;
36
- if ( $strings = wp_cache_get( 'strings', 'learnpress' ) ) {
37
  if ( array_key_exists( $str, $strings ) ) {
38
  $texts = $strings[ $str ];
39
 
10
  $__strings = $strings;
11
  }
12
 
13
+ if ( false === ( $strings = LP_Object_Cache::get( 'strings', 'learnpress' ) ) ) {
14
 
15
  $strings = array(
16
  'confirm-redo-quiz' => __( 'Do you want to redo quiz "%s"?', 'learnpress' ),
20
  'confirm-retake-course' => __( 'Do you want to retake course "%s"?', 'learnpress' ),
21
  );
22
 
23
+ LP_Object_Cache::set( 'strings', $strings, 'learnpress' );
24
  }
25
 
26
  /**
33
  class LP_Strings {
34
  public static function get( $str, $context = '', $args = '' ) {
35
  $string = $str;
36
+ if ( $strings = LP_Object_Cache::get( 'strings', 'learnpress' ) ) {
37
  if ( array_key_exists( $str, $strings ) ) {
38
  $texts = $strings[ $str ];
39
 
inc/course/abstract-course.php CHANGED
@@ -412,7 +412,7 @@ if ( ! function_exists( 'LP_Abstract_Course' ) ) {
412
  // get course items from cache
413
 
414
  if ( ! $type && $preview ) {
415
- $items = apply_filters( 'learn-press/course-items', wp_cache_get( 'course-' . $this->get_id(), 'lp-course-items' ) );
416
  } else {
417
 
418
  if ( ! $type ) {
@@ -422,11 +422,11 @@ if ( ! function_exists( 'LP_Abstract_Course' ) ) {
422
  }
423
 
424
  $key = $this->get_id() . '-' . md5( serialize( func_get_args() ) );
425
- if ( false === ( $items = wp_cache_get( 'course-' . $key, 'lp-course-items' ) ) ) {
426
 
427
  $items = array();
428
  foreach ( $type as $t ) {
429
- if ( $items_by_type = wp_cache_get( 'course-' . $this->get_id(), 'lp-course-' . $t ) ) {
430
  $items = array_merge( $items, $items_by_type );
431
  }
432
  }
@@ -435,7 +435,7 @@ if ( ! function_exists( 'LP_Abstract_Course' ) ) {
435
  $items = array_diff( $items, $preview_items );
436
  }
437
 
438
- wp_cache_set( 'course-' . $key, $items, 'lp-course-items' );
439
 
440
  }
441
  }
@@ -979,7 +979,7 @@ if ( ! function_exists( 'LP_Abstract_Course' ) ) {
979
  */
980
  public function get_item_links() {
981
 
982
- if ( false === ( $item_links = wp_cache_get( 'course-' . $this->get_id(), 'course-item-links' ) ) ) {
983
 
984
  if ( $items = $this->get_items() ) {
985
 
@@ -1042,7 +1042,7 @@ if ( ! function_exists( 'LP_Abstract_Course' ) ) {
1042
  }
1043
  }
1044
 
1045
- wp_cache_set( 'course-' . $this->get_id(), $item_links, 'course-item-links' );
1046
  }
1047
 
1048
  return $item_links;
@@ -1476,14 +1476,14 @@ if ( ! function_exists( 'LP_Abstract_Course' ) ) {
1476
 
1477
  $key = md5( serialize( array( 'course' => $this->get_id(), 'type' => $type, 'preview' => $preview ) ) );
1478
 
1479
- if ( false === ( $count_items = wp_cache_get( $key, 'count-items' ) ) ) {
1480
  $count_items = 0;
1481
 
1482
  if ( $items = $this->get_items( $type, $preview ) ) {
1483
  $count_items = sizeof( $items );
1484
  }
1485
 
1486
- wp_cache_set( $key, $count_items, 'count-items' );
1487
  }
1488
 
1489
  return apply_filters( 'learn-press/count-items', $count_items, $type, $preview, $this->get_id() );
@@ -1511,7 +1511,7 @@ if ( ! function_exists( 'LP_Abstract_Course' ) ) {
1511
  $count_preview = $count_all - $count_no_preview;
1512
  }
1513
 
1514
- //wp_cache_set( 'course-' . $this->get_id(), $count_preview, 'lp-course-preview-items' );
1515
  } else {
1516
  $count_preview = sizeof( $count_preview );
1517
  }
@@ -1520,7 +1520,7 @@ if ( ! function_exists( 'LP_Abstract_Course' ) ) {
1520
  }
1521
 
1522
  public function get_preview_items() {
1523
- return wp_cache_get( 'course-' . $this->get_id(), 'lp-course-preview-items' );
1524
  }
1525
 
1526
  /**
412
  // get course items from cache
413
 
414
  if ( ! $type && $preview ) {
415
+ $items = apply_filters( 'learn-press/course-items', LP_Object_Cache::get( 'course-' . $this->get_id(), 'lp-course-items' ) );
416
  } else {
417
 
418
  if ( ! $type ) {
422
  }
423
 
424
  $key = $this->get_id() . '-' . md5( serialize( func_get_args() ) );
425
+ if ( false === ( $items = LP_Object_Cache::get( 'course-' . $key, 'lp-course-items' ) ) ) {
426
 
427
  $items = array();
428
  foreach ( $type as $t ) {
429
+ if ( $items_by_type = LP_Object_Cache::get( 'course-' . $this->get_id(), 'lp-course-' . $t ) ) {
430
  $items = array_merge( $items, $items_by_type );
431
  }
432
  }
435
  $items = array_diff( $items, $preview_items );
436
  }
437
 
438
+ LP_Object_Cache::set( 'course-' . $key, $items, 'lp-course-items' );
439
 
440
  }
441
  }
979
  */
980
  public function get_item_links() {
981
 
982
+ if ( false === ( $item_links = LP_Object_Cache::get( 'course-' . $this->get_id(), 'course-item-links' ) ) ) {
983
 
984
  if ( $items = $this->get_items() ) {
985
 
1042
  }
1043
  }
1044
 
1045
+ LP_Object_Cache::set( 'course-' . $this->get_id(), $item_links, 'course-item-links' );
1046
  }
1047
 
1048
  return $item_links;
1476
 
1477
  $key = md5( serialize( array( 'course' => $this->get_id(), 'type' => $type, 'preview' => $preview ) ) );
1478
 
1479
+ if ( false === ( $count_items = LP_Object_Cache::get( $key, 'count-items' ) ) ) {
1480
  $count_items = 0;
1481
 
1482
  if ( $items = $this->get_items( $type, $preview ) ) {
1483
  $count_items = sizeof( $items );
1484
  }
1485
 
1486
+ LP_Object_Cache::set( $key, $count_items, 'count-items' );
1487
  }
1488
 
1489
  return apply_filters( 'learn-press/count-items', $count_items, $type, $preview, $this->get_id() );
1511
  $count_preview = $count_all - $count_no_preview;
1512
  }
1513
 
1514
+ //LP_Object_Cache::set( 'course-' . $this->get_id(), $count_preview, 'lp-course-preview-items' );
1515
  } else {
1516
  $count_preview = sizeof( $count_preview );
1517
  }
1520
  }
1521
 
1522
  public function get_preview_items() {
1523
+ return LP_Object_Cache::get( 'course-' . $this->get_id(), 'lp-course-preview-items' );
1524
  }
1525
 
1526
  /**
inc/course/class-lp-course-item.php CHANGED
@@ -101,13 +101,13 @@ if ( ! class_exists( 'LP_Course_Item' ) ) {
101
  if ( $course = $this->get_course() ) {
102
  $user_id = get_current_user_id();
103
 
104
- if ( false === ( $cached = wp_cache_get( 'item-' . $user_id . '-' . $course->get_id() . '-' . $this->get_id(), 'lp-preview-items' ) ) ) {
105
  $user = learn_press_get_current_user();
106
 
107
  if ( $user->has_enrolled_course( $course->get_id() ) ) {
108
  $is_preview = false;
109
  }
110
- wp_cache_set( 'item-' . $user_id . '-' . $course->get_id() . '-' . $this->get_id(), $is_preview ? 'yes' : 'no', 'lp-preview-items' );
111
  } else {
112
  $is_preview = $cached === 'yes' ? true : false;
113
  }
@@ -131,7 +131,7 @@ if ( ! class_exists( 'LP_Course_Item' ) ) {
131
  * @return bool|false|mixed|string
132
  */
133
  public function get_format() {
134
- $format = ( false !== ( $format = wp_cache_get( 'item-format-' . $this->get_id(), 'lp-item-formats' ) ) ) ? $format : get_post_format( $this->get_id() );
135
 
136
  if ( ! $format ) {
137
  $format = 'standard';
@@ -164,7 +164,7 @@ if ( ! class_exists( 'LP_Course_Item' ) ) {
164
 
165
  $course_id = get_the_ID();
166
 
167
- if ( false === ( $classes = wp_cache_get( 'item-' . $user_id . '-' . $this->get_id(), 'lp-post-classes' ) ) ) {
168
  if ( ! $user_id ) {
169
  $user_id = get_current_user_id();
170
  }
@@ -239,7 +239,7 @@ if ( ! class_exists( 'LP_Course_Item' ) ) {
239
  $classes = array_filter( $classes );
240
  $classes = array_unique( $classes );
241
 
242
- wp_cache_set( 'item-' . $user_id . '-' . $this->get_id(), $classes, 'lp-post-classes' );
243
  }
244
 
245
  return apply_filters( 'learn-press/course-item-class-cached', $classes, $this->get_item_type(), $this->get_id(), $course_id );
@@ -316,7 +316,7 @@ if ( ! class_exists( 'LP_Course_Item' ) ) {
316
  $item_id = $post->ID;
317
  }
318
 
319
- if ( false === ( $item = wp_cache_get( $item_id, 'lp-object-classes' ) ) ) {
320
 
321
  if ( $item_type ) {
322
  if ( learn_press_is_support_course_item_type( $item_type ) ) {
@@ -343,7 +343,7 @@ if ( ! class_exists( 'LP_Course_Item' ) ) {
343
  }
344
  }
345
  }
346
- wp_cache_set( $item_id, $item, 'lp-object-classes' );
347
 
348
  if ( $course ) {
349
  $item->set_course( $course );
@@ -536,7 +536,7 @@ if ( ! class_exists( 'LP_Course_Item' ) ) {
536
 
537
  $key = 'course-item-' . $user_id . '-' . $course_id;
538
 
539
- if ( false === ( $blocked_items = wp_cache_get( $key, 'blocked-items' ) ) ) {
540
  $blocked_items = $this->_parse_item_block_status( $course_id, $user_id, $key );
541
  }
542
 
@@ -573,7 +573,7 @@ if ( ! class_exists( 'LP_Course_Item' ) ) {
573
  }
574
  $blocked_items[ $this->get_id() ] = $blocked;
575
 
576
- wp_cache_set( $key, $blocked_items, 'blocked-items' );
577
  $is_blocked = $blocked;
578
  //return apply_filters( 'learn-press/course-item/is-blocked', $blocked === 'yes' ? true : false, $this->get_id(), $course_id, $user_id );
579
  }
@@ -615,7 +615,7 @@ if ( ! class_exists( 'LP_Course_Item' ) ) {
615
 
616
  $blocked_items = apply_filters( 'learn-press/course-item/parse-block-statuses', $blocked_items, $course_id, $user_id );
617
 
618
- wp_cache_set( $cache_key, $blocked_items, 'blocked-items' );
619
 
620
  return $blocked_items;
621
  }
101
  if ( $course = $this->get_course() ) {
102
  $user_id = get_current_user_id();
103
 
104
+ if ( false === ( $cached = LP_Object_Cache::get( 'item-' . $user_id . '-' . $course->get_id() . '-' . $this->get_id(), 'lp-preview-items' ) ) ) {
105
  $user = learn_press_get_current_user();
106
 
107
  if ( $user->has_enrolled_course( $course->get_id() ) ) {
108
  $is_preview = false;
109
  }
110
+ LP_Object_Cache::set( 'item-' . $user_id . '-' . $course->get_id() . '-' . $this->get_id(), $is_preview ? 'yes' : 'no', 'lp-preview-items' );
111
  } else {
112
  $is_preview = $cached === 'yes' ? true : false;
113
  }
131
  * @return bool|false|mixed|string
132
  */
133
  public function get_format() {
134
+ $format = ( false !== ( $format = LP_Object_Cache::get( 'item-format-' . $this->get_id(), 'lp-item-formats' ) ) ) ? $format : get_post_format( $this->get_id() );
135
 
136
  if ( ! $format ) {
137
  $format = 'standard';
164
 
165
  $course_id = get_the_ID();
166
 
167
+ if ( false === ( $classes = LP_Object_Cache::get( 'item-' . $user_id . '-' . $this->get_id(), 'lp-post-classes' ) ) ) {
168
  if ( ! $user_id ) {
169
  $user_id = get_current_user_id();
170
  }
239
  $classes = array_filter( $classes );
240
  $classes = array_unique( $classes );
241
 
242
+ LP_Object_Cache::set( 'item-' . $user_id . '-' . $this->get_id(), $classes, 'lp-post-classes' );
243
  }
244
 
245
  return apply_filters( 'learn-press/course-item-class-cached', $classes, $this->get_item_type(), $this->get_id(), $course_id );
316
  $item_id = $post->ID;
317
  }
318
 
319
+ if ( false === ( $item = LP_Object_Cache::get( $item_id, 'lp-object-classes' ) ) ) {
320
 
321
  if ( $item_type ) {
322
  if ( learn_press_is_support_course_item_type( $item_type ) ) {
343
  }
344
  }
345
  }
346
+ LP_Object_Cache::set( $item_id, $item, 'lp-object-classes' );
347
 
348
  if ( $course ) {
349
  $item->set_course( $course );
536
 
537
  $key = 'course-item-' . $user_id . '-' . $course_id;
538
 
539
+ if ( false === ( $blocked_items = LP_Object_Cache::get( $key, 'blocked-items' ) ) ) {
540
  $blocked_items = $this->_parse_item_block_status( $course_id, $user_id, $key );
541
  }
542
 
573
  }
574
  $blocked_items[ $this->get_id() ] = $blocked;
575
 
576
+ LP_Object_Cache::set( $key, $blocked_items, 'blocked-items' );
577
  $is_blocked = $blocked;
578
  //return apply_filters( 'learn-press/course-item/is-blocked', $blocked === 'yes' ? true : false, $this->get_id(), $course_id, $user_id );
579
  }
615
 
616
  $blocked_items = apply_filters( 'learn-press/course-item/parse-block-statuses', $blocked_items, $course_id, $user_id );
617
 
618
+ LP_Object_Cache::set( $cache_key, $blocked_items, 'blocked-items' );
619
 
620
  return $blocked_items;
621
  }
inc/course/class-lp-course-section.php CHANGED
@@ -55,7 +55,7 @@ class LP_Course_Section extends LP_Abstract_Object_Data {
55
  }
56
 
57
  // All items
58
- $curriculum = wp_cache_get( 'course-' . $this->get_course_id(), 'lp-course-curriculum' );
59
 
60
  if ( ! $curriculum ) {
61
  return false;
55
  }
56
 
57
  // All items
58
+ $curriculum = LP_Object_Cache::get( 'course-' . $this->get_course_id(), 'lp-course-curriculum' );
59
 
60
  if ( ! $curriculum ) {
61
  return false;
inc/course/class-lp-course.php CHANGED
@@ -145,7 +145,7 @@ if ( ! class_exists( 'LP_Course' ) ) {
145
  * Force to reload course data into cache if it is not
146
  * loaded or has been deleted for some reasons.
147
  */
148
- if ( false === wp_cache_get( 'course-' . $course->get_id(), 'lp-course-curriculum' ) ) {
149
  $curd = new LP_Course_CURD();
150
  $curd->load( $course );
151
  }
145
  * Force to reload course data into cache if it is not
146
  * loaded or has been deleted for some reasons.
147
  */
148
+ if ( false === LP_Object_Cache::get( 'course-' . $course->get_id(), 'lp-course-curriculum' ) ) {
149
  $curd = new LP_Course_CURD();
150
  $curd->load( $course );
151
  }
inc/course/lp-course-functions.php CHANGED
@@ -210,7 +210,7 @@ add_filter( 'post_type_link', 'learn_press_course_post_type_link', 10, 2 );
210
  */
211
  function learn_press_get_final_quiz( $course_id ) {
212
 
213
- if ( false === ( $final_quiz = wp_cache_get( 'final-quiz-' . $course_id, 'lp-final-quiz' ) ) ) {
214
 
215
  $course = learn_press_get_course( $course_id );
216
  if ( ! $course ) {
@@ -237,7 +237,7 @@ function learn_press_get_final_quiz( $course_id ) {
237
  delete_post_meta( $course_id, '_lp_final_quiz' );
238
  }
239
 
240
- wp_cache_set( 'final-quiz-' . $course_id, $final_quiz ? $final_quiz : 0, 'lp-final-quiz' );
241
  }
242
 
243
  return $final_quiz;
@@ -854,7 +854,7 @@ if ( ! function_exists( 'learn_press_get_item_course_id' ) ) {
854
 
855
  $course_id = false;
856
 
857
- if ( false !== ( $courses = wp_cache_get( 'item-course-ids', 'learn-press' ) ) ) {
858
 
859
  foreach ( $courses as $course_id => $items ) {
860
  if ( in_array( $post_id, $items ) ) {
@@ -890,7 +890,7 @@ if ( ! function_exists( 'learn_press_get_item_course_id' ) ) {
890
  if ( ! in_array( $post_id, $courses[ $course_id ] ) ) {
891
  $courses[ $course_id ][] = $post_id;
892
  }
893
- wp_cache_set( 'item-course-ids', $courses, 'learn-press' );
894
 
895
  }
896
 
210
  */
211
  function learn_press_get_final_quiz( $course_id ) {
212
 
213
+ if ( false === ( $final_quiz = LP_Object_Cache::get( 'final-quiz-' . $course_id, 'lp-final-quiz' ) ) ) {
214
 
215
  $course = learn_press_get_course( $course_id );
216
  if ( ! $course ) {
237
  delete_post_meta( $course_id, '_lp_final_quiz' );
238
  }
239
 
240
+ LP_Object_Cache::set( 'final-quiz-' . $course_id, $final_quiz ? $final_quiz : 0, 'lp-final-quiz' );
241
  }
242
 
243
  return $final_quiz;
854
 
855
  $course_id = false;
856
 
857
+ if ( false !== ( $courses = LP_Object_Cache::get( 'item-course-ids', 'learn-press' ) ) ) {
858
 
859
  foreach ( $courses as $course_id => $items ) {
860
  if ( in_array( $post_id, $items ) ) {
890
  if ( ! in_array( $post_id, $courses[ $course_id ] ) ) {
891
  $courses[ $course_id ][] = $post_id;
892
  }
893
+ LP_Object_Cache::set( 'item-course-ids', $courses, 'learn-press' );
894
 
895
  }
896
 
inc/curds/class-lp-course-curd.php CHANGED
@@ -249,12 +249,12 @@ if ( ! class_exists( 'LP_Course_CURD' ) ) {
249
  * Get course's data from cache and if it is already existed
250
  * then ignore that course.
251
  */
252
- if ( wp_cache_get( 'course-' . $course_id, 'lp-course-curriculum' ) ) {
253
  return false;
254
  }
255
 
256
  // Set cache
257
- wp_cache_set( 'course-' . $course_id, array(), 'lp-course-curriculum' );
258
 
259
  $item_ids = array();
260
  $meta_cache_ids = array( $course_id );
@@ -298,7 +298,7 @@ if ( ! class_exists( 'LP_Course_CURD' ) ) {
298
 
299
  // If $cur_id is already set to a course
300
  if ( $cur_id ) {
301
- wp_cache_set( 'course-' . $cur_id, $curriculum, 'lp-course-curriculum' );
302
  }
303
 
304
  // Set $cur_id to new course and reset $curriculum
@@ -334,21 +334,21 @@ if ( ! class_exists( 'LP_Course_CURD' ) ) {
334
  }
335
  }
336
 
337
- //wp_cache_set( 'course-' . $cur_id, $quiz_ids, 'lp-course-' . LP_QUIZ_CPT );
338
- //wp_cache_set( 'course-' . $cur_id, $lesson_ids, 'lp-course-' . LP_LESSON_CPT );
339
 
340
  if ( $group_items ) {
341
  foreach ( $group_items as $type => $group_item_ids ) {
342
- wp_cache_set( 'course-' . $cur_id, $group_item_ids, 'lp-course-' . $type );
343
  }
344
  }
345
 
346
- wp_cache_set( 'course-' . $cur_id, $curriculum, 'lp-course-curriculum' );
347
- wp_cache_set( 'course-' . $cur_id, $preview_ids, 'lp-course-preview-items' );
348
 
349
  // Cache items ids for using in some cases
350
  foreach ( $item_ids as $cid => $ids ) {
351
- wp_cache_set( 'course-' . $cid, $ids, 'lp-course-items' );
352
  }
353
 
354
  LP_Hard_Cache::set( $course_id, $curriculum, 'lp-course-curriculum' );
@@ -372,11 +372,11 @@ if ( ! class_exists( 'LP_Course_CURD' ) ) {
372
  }
373
 
374
  // Set cache
375
- wp_cache_set( 'course-' . $course_id, $curriculum, 'lp-course-curriculum' );
376
- wp_cache_set( 'course-' . $course_id, $item_ids, 'lp-course-items' );
377
- wp_cache_set( 'course-' . $course_id, $lesson_ids, 'lp-course-' . LP_LESSON_CPT );
378
- wp_cache_set( 'course-' . $course_id, $quiz_ids, 'lp-course-' . LP_QUIZ_CPT );
379
- wp_cache_set( 'course-' . $course_id, $preview_ids, 'lp-course-preview-items' );
380
 
381
  }
382
 
@@ -405,9 +405,9 @@ if ( ! class_exists( 'LP_Course_CURD' ) ) {
405
 
406
  $course = learn_press_get_course( $course_id );
407
 
408
- if ( false === ( $curriculum = wp_cache_get( 'course-' . $course_id, 'lp-course-curriculum-sections' ) ) ) {
409
 
410
- if ( $sections = wp_cache_get( 'course-' . $course_id, 'lp-course-sections' ) ) {
411
  $position = 0;
412
  foreach ( $sections as $k => $section ) {
413
  $_section = new LP_Course_Section( $section );
@@ -447,11 +447,11 @@ if ( ! class_exists( 'LP_Course_CURD' ) ) {
447
  if ( empty( $item_formats[ $item_id ] ) ) {
448
  $item_formats[ $item_id ] = 'standard';
449
  }
450
- wp_cache_set( 'item-format-' . $item_id, $item_formats[ $item_id ], 'lp-item-formats' );
451
  }
452
  }
453
  }
454
- wp_cache_set( 'course-' . $course_id, $curriculum, 'lp-course-curriculum-sections' );
455
 
456
  }
457
  LP_Debug::log_function( __CLASS__ . '::' . __FUNCTION__ );
@@ -469,7 +469,7 @@ if ( ! class_exists( 'LP_Course_CURD' ) ) {
469
  public function get_course_sections( $course_id ) {
470
  $this->read_course_sections( $course_id );
471
 
472
- return wp_cache_get( 'course-' . $course_id, 'lp-course-sections' );
473
  }
474
 
475
  /**
@@ -496,11 +496,11 @@ if ( ! class_exists( 'LP_Course_CURD' ) ) {
496
  * Get course's data from cache and if it is already existed
497
  * then ignore that course.
498
  */
499
- if ( false !== wp_cache_get( 'course-' . $fetch_id, 'lp-course-sections' ) ) {
500
  continue;
501
  }
502
 
503
- wp_cache_set( 'course-' . $fetch_id, array(), 'lp-course-sections' );
504
 
505
  $section_curd = new LP_Section_CURD( $fetch_id );
506
  $section_curd->read_sections_ids();
@@ -530,20 +530,20 @@ if ( ! class_exists( 'LP_Course_CURD' ) ) {
530
  foreach ( $results as $row ) {
531
  if ( $row->section_course_id !== $cur_id ) {
532
  if ( $cur_id ) {
533
- wp_cache_set( 'course-' . $cur_id, $course_sections, 'lp-course-sections' );
534
  }
535
  $cur_id = $row->section_course_id;
536
  $course_sections = array();
537
  }
538
  $course_sections[] = $row;
539
  }
540
- wp_cache_set( 'course-' . $cur_id, $course_sections, 'lp-course-sections' );
541
  }
542
 
543
  LP_Hard_Cache::set( $cache_key, $course_sections, 'lp-course-sections' );
544
  } else {
545
  foreach ( $fetch_ids as $cid ) {
546
- wp_cache_set( 'course-' . $cid, $course_sections, 'lp-course-sections' );
547
  }
548
  }
549
  unset( $course_sections );
@@ -741,7 +741,7 @@ if ( ! class_exists( 'LP_Course_CURD' ) ) {
741
  sort( $statuses );
742
  $cache_key = md5( serialize( $statuses ) );
743
 
744
- if ( false === ( $count = wp_cache_get( 'course-' . $course_id . '-' . $cache_key, 'lp-course-orders' ) ) ) {
745
  $in_clause = join( ',', array_fill( 0, sizeof( $statuses ), '%s' ) );
746
  $query_args = array_merge( array( '_course_id', $course_id, LP_ORDER_CPT ), $statuses );
747
 
@@ -758,7 +758,7 @@ if ( ! class_exists( 'LP_Course_CURD' ) ) {
758
 
759
  $count = absint( $wpdb->get_var( $query ) );
760
 
761
- wp_cache_set( 'course-' . $course_id . '-' . $cache_key, $count, 'lp-course-orders' );
762
  }
763
 
764
  return $count;
249
  * Get course's data from cache and if it is already existed
250
  * then ignore that course.
251
  */
252
+ if ( LP_Object_Cache::get( 'course-' . $course_id, 'lp-course-curriculum' ) ) {
253
  return false;
254
  }
255
 
256
  // Set cache
257
+ LP_Object_Cache::set( 'course-' . $course_id, array(), 'lp-course-curriculum' );
258
 
259
  $item_ids = array();
260
  $meta_cache_ids = array( $course_id );
298
 
299
  // If $cur_id is already set to a course
300
  if ( $cur_id ) {
301
+ LP_Object_Cache::set( 'course-' . $cur_id, $curriculum, 'lp-course-curriculum' );
302
  }
303
 
304
  // Set $cur_id to new course and reset $curriculum
334
  }
335
  }
336
 
337
+ //LP_Object_Cache::set( 'course-' . $cur_id, $quiz_ids, 'lp-course-' . LP_QUIZ_CPT );
338
+ //LP_Object_Cache::set( 'course-' . $cur_id, $lesson_ids, 'lp-course-' . LP_LESSON_CPT );
339
 
340
  if ( $group_items ) {
341
  foreach ( $group_items as $type => $group_item_ids ) {
342
+ LP_Object_Cache::set( 'course-' . $cur_id, $group_item_ids, 'lp-course-' . $type );
343
  }
344
  }
345
 
346
+ LP_Object_Cache::set( 'course-' . $cur_id, $curriculum, 'lp-course-curriculum' );
347
+ LP_Object_Cache::set( 'course-' . $cur_id, $preview_ids, 'lp-course-preview-items' );
348
 
349
  // Cache items ids for using in some cases
350
  foreach ( $item_ids as $cid => $ids ) {
351
+ LP_Object_Cache::set( 'course-' . $cid, $ids, 'lp-course-items' );
352
  }
353
 
354
  LP_Hard_Cache::set( $course_id, $curriculum, 'lp-course-curriculum' );
372
  }
373
 
374
  // Set cache
375
+ LP_Object_Cache::set( 'course-' . $course_id, $curriculum, 'lp-course-curriculum' );
376
+ LP_Object_Cache::set( 'course-' . $course_id, $item_ids, 'lp-course-items' );
377
+ LP_Object_Cache::set( 'course-' . $course_id, $lesson_ids, 'lp-course-' . LP_LESSON_CPT );
378
+ LP_Object_Cache::set( 'course-' . $course_id, $quiz_ids, 'lp-course-' . LP_QUIZ_CPT );
379
+ LP_Object_Cache::set( 'course-' . $course_id, $preview_ids, 'lp-course-preview-items' );
380
 
381
  }
382
 
405
 
406
  $course = learn_press_get_course( $course_id );
407
 
408
+ if ( false === ( $curriculum = LP_Object_Cache::get( 'course-' . $course_id, 'lp-course-curriculum-sections' ) ) ) {
409
 
410
+ if ( $sections = LP_Object_Cache::get( 'course-' . $course_id, 'lp-course-sections' ) ) {
411
  $position = 0;
412
  foreach ( $sections as $k => $section ) {
413
  $_section = new LP_Course_Section( $section );
447
  if ( empty( $item_formats[ $item_id ] ) ) {
448
  $item_formats[ $item_id ] = 'standard';
449
  }
450
+ LP_Object_Cache::set( 'item-format-' . $item_id, $item_formats[ $item_id ], 'lp-item-formats' );
451
  }
452
  }
453
  }
454
+ LP_Object_Cache::set( 'course-' . $course_id, $curriculum, 'lp-course-curriculum-sections' );
455
 
456
  }
457
  LP_Debug::log_function( __CLASS__ . '::' . __FUNCTION__ );
469
  public function get_course_sections( $course_id ) {
470
  $this->read_course_sections( $course_id );
471
 
472
+ return LP_Object_Cache::get( 'course-' . $course_id, 'lp-course-sections' );
473
  }
474
 
475
  /**
496
  * Get course's data from cache and if it is already existed
497
  * then ignore that course.
498
  */
499
+ if ( false !== LP_Object_Cache::get( 'course-' . $fetch_id, 'lp-course-sections' ) ) {
500
  continue;
501
  }
502
 
503
+ LP_Object_Cache::set( 'course-' . $fetch_id, array(), 'lp-course-sections' );
504
 
505
  $section_curd = new LP_Section_CURD( $fetch_id );
506
  $section_curd->read_sections_ids();
530
  foreach ( $results as $row ) {
531
  if ( $row->section_course_id !== $cur_id ) {
532
  if ( $cur_id ) {
533
+ LP_Object_Cache::set( 'course-' . $cur_id, $course_sections, 'lp-course-sections' );
534
  }
535
  $cur_id = $row->section_course_id;
536
  $course_sections = array();
537
  }
538
  $course_sections[] = $row;
539
  }
540
+ LP_Object_Cache::set( 'course-' . $cur_id, $course_sections, 'lp-course-sections' );
541
  }
542
 
543
  LP_Hard_Cache::set( $cache_key, $course_sections, 'lp-course-sections' );
544
  } else {
545
  foreach ( $fetch_ids as $cid ) {
546
+ LP_Object_Cache::set( 'course-' . $cid, $course_sections, 'lp-course-sections' );
547
  }
548
  }
549
  unset( $course_sections );
741
  sort( $statuses );
742
  $cache_key = md5( serialize( $statuses ) );
743
 
744
+ if ( false === ( $count = LP_Object_Cache::get( 'course-' . $course_id . '-' . $cache_key, 'lp-course-orders' ) ) ) {
745
  $in_clause = join( ',', array_fill( 0, sizeof( $statuses ), '%s' ) );
746
  $query_args = array_merge( array( '_course_id', $course_id, LP_ORDER_CPT ), $statuses );
747
 
758
 
759
  $count = absint( $wpdb->get_var( $query ) );
760
 
761
+ LP_Object_Cache::set( 'course-' . $course_id . '-' . $cache_key, $count, 'lp-course-orders' );
762
  }
763
 
764
  return $count;
inc/curds/class-lp-helper-curd.php CHANGED
@@ -50,7 +50,7 @@ class LP_Helper_CURD {
50
  $meta_data[ $id ] = array();
51
  }
52
 
53
- wp_cache_set( $id, $meta_data[ $id ], "{$type}_meta" );
54
  }
55
 
56
  }
50
  $meta_data[ $id ] = array();
51
  }
52
 
53
+ LP_Object_Cache::set( $id, $meta_data[ $id ], "{$type}_meta" );
54
  }
55
 
56
  }
inc/curds/class-lp-order-curd.php CHANGED
@@ -96,7 +96,7 @@ class LP_Order_CURD extends LP_Object_Data_CURD implements LP_Interface_CURD {
96
  */
97
  public function read_items( $order ) {
98
 
99
- if ( false === ( $items = wp_cache_get( 'order-' . $order->get_id(), 'lp-order-items' ) ) ) {
100
 
101
  global $wpdb;
102
 
@@ -122,7 +122,7 @@ class LP_Order_CURD extends LP_Object_Data_CURD implements LP_Interface_CURD {
122
  }
123
  }
124
 
125
- wp_cache_set( 'order-' . $order->get_id(), $items, 'lp-order-items' );
126
  }
127
 
128
  return $items;// apply_filters( 'learn_press_order_get_items', $items, $this );
@@ -544,7 +544,7 @@ class LP_Order_CURD extends LP_Object_Data_CURD implements LP_Interface_CURD {
544
  public function get_child_orders( $order_id ) {
545
  global $wpdb;
546
 
547
- if ( false === ( $orders = wp_cache_get( 'order-' . $order_id, 'lp-child-orders' ) ) ) {
548
  $query = $wpdb->prepare( "
549
  SELECT *
550
  FROM {$wpdb->posts}
@@ -558,7 +558,7 @@ class LP_Order_CURD extends LP_Object_Data_CURD implements LP_Interface_CURD {
558
  } else {
559
  $orders = array();
560
  }
561
- wp_cache_set( 'order-' . $order_id, $orders, 'lp-child-orders' );
562
  }
563
 
564
  return $orders;
96
  */
97
  public function read_items( $order ) {
98
 
99
+ if ( false === ( $items = LP_Object_Cache::get( 'order-' . $order->get_id(), 'lp-order-items' ) ) ) {
100
 
101
  global $wpdb;
102
 
122
  }
123
  }
124
 
125
+ LP_Object_Cache::set( 'order-' . $order->get_id(), $items, 'lp-order-items' );
126
  }
127
 
128
  return $items;// apply_filters( 'learn_press_order_get_items', $items, $this );
544
  public function get_child_orders( $order_id ) {
545
  global $wpdb;
546
 
547
+ if ( false === ( $orders = LP_Object_Cache::get( 'order-' . $order_id, 'lp-child-orders' ) ) ) {
548
  $query = $wpdb->prepare( "
549
  SELECT *
550
  FROM {$wpdb->posts}
558
  } else {
559
  $orders = array();
560
  }
561
+ LP_Object_Cache::set( 'order-' . $order_id, $orders, 'lp-child-orders' );
562
  }
563
 
564
  return $orders;
inc/curds/class-lp-question-curd.php CHANGED
@@ -355,7 +355,7 @@ if ( ! class_exists( 'LP_Question_CURD' ) ) {
355
  ) );
356
  }
357
 
358
- wp_cache_set( 'answer-options-' . $question_id, $answer_options, 'lp-questions' );
359
  $new_question->set_data( 'answer_options', $answer_options );
360
 
361
  return $new_question;
@@ -857,7 +857,7 @@ if ( ! class_exists( 'LP_Question_CURD' ) ) {
857
  protected function _load_answer_options( &$question ) {
858
 
859
  $id = $question->get_id();
860
- $answer_options = wp_cache_get( 'answer-options-' . $id, 'lp-questions' );
861
 
862
  if ( false === $answer_options ) {
863
  global $wpdb;
@@ -886,7 +886,7 @@ if ( ! class_exists( 'LP_Question_CURD' ) ) {
886
  if ( ! empty( $answer_options['question_answer_id'] ) && $answer_options['question_answer_id'] > 0 ) {
887
  $this->_load_answer_option_meta( $answer_options );
888
  }
889
- wp_cache_set( 'answer-options-' . $id, $answer_options, 'lp-questions' );
890
 
891
  $question->set_data( 'answer_options', $answer_options );
892
  }
@@ -948,7 +948,7 @@ if ( ! class_exists( 'LP_Question_CURD' ) ) {
948
 
949
  if ( $question_answers ) {
950
  foreach ( $question_answers as $question_id => $answer ) {
951
- wp_cache_set( 'answer-options-' . $question_id, $answer, 'lp-questions' );
952
  }
953
  }
954
 
355
  ) );
356
  }
357
 
358
+ LP_Object_Cache::set( 'answer-options-' . $question_id, $answer_options, 'lp-questions' );
359
  $new_question->set_data( 'answer_options', $answer_options );
360
 
361
  return $new_question;
857
  protected function _load_answer_options( &$question ) {
858
 
859
  $id = $question->get_id();
860
+ $answer_options = LP_Object_Cache::get( 'answer-options-' . $id, 'lp-questions' );
861
 
862
  if ( false === $answer_options ) {
863
  global $wpdb;
886
  if ( ! empty( $answer_options['question_answer_id'] ) && $answer_options['question_answer_id'] > 0 ) {
887
  $this->_load_answer_option_meta( $answer_options );
888
  }
889
+ LP_Object_Cache::set( 'answer-options-' . $id, $answer_options, 'lp-questions' );
890
 
891
  $question->set_data( 'answer_options', $answer_options );
892
  }
948
 
949
  if ( $question_answers ) {
950
  foreach ( $question_answers as $question_id => $answer ) {
951
+ LP_Object_Cache::set( 'answer-options-' . $question_id, $answer, 'lp-questions' );
952
  }
953
  }
954
 
inc/curds/class-lp-quiz-curd.php CHANGED
@@ -196,7 +196,7 @@ if ( ! function_exists( 'LP_Quiz_CURD' ) ) {
196
  */
197
  protected function _load_questions( &$quiz ) {
198
  $id = $quiz->get_id();
199
- $questions = wp_cache_get( 'questions-' . $id, 'lp-quizzes' );
200
 
201
  if ( false === $questions || $quiz->get_no_cache() ) {
202
  $this->load_questions( $quiz->get_id() );
@@ -250,7 +250,7 @@ if ( ! function_exists( 'LP_Quiz_CURD' ) ) {
250
  //}
251
 
252
  foreach ( $questions as $quiz_id => $quiz_questions ) {
253
- wp_cache_set( 'questions-' . $quiz_id, $quiz_questions, 'lp-quizzes' );
254
  }
255
 
256
  LP_Helper_CURD::update_meta_cache( 'post', $question_ids );
@@ -262,7 +262,7 @@ if ( ! function_exists( 'LP_Quiz_CURD' ) ) {
262
  * @param LP_Quiz $quiz
263
  */
264
  protected function _update_meta_cache( &$quiz ) {
265
- $meta_ids = wp_cache_get( 'questions-' . $quiz->get_id(), 'lp-quizzes' );
266
 
267
  if ( false === $meta_ids ) {
268
  $meta_ids = array( $quiz->get_id() );
@@ -386,7 +386,7 @@ if ( ! function_exists( 'LP_Quiz_CURD' ) ) {
386
  return $this->get_error( 'QUIZ_NOT_EXISTS' );
387
  }
388
 
389
- return wp_cache_get( 'questions-' . $the_quiz->get_id(), 'lp-quizzes' );
390
  }
391
 
392
  /**
@@ -414,7 +414,7 @@ if ( ! function_exists( 'LP_Quiz_CURD' ) ) {
414
  $list_questions = $this->get_questions( $the_quiz );
415
  // add new question and set to cache
416
  $list_questions[ $question_id ] = strval( $question_id );
417
- wp_cache_set( 'questions-' . $the_quiz->get_id(), $list_questions, 'lp-quizzes' );
418
 
419
  global $wpdb;
420
  $id = $the_quiz->get_id();
196
  */
197
  protected function _load_questions( &$quiz ) {
198
  $id = $quiz->get_id();
199
+ $questions = LP_Object_Cache::get( 'questions-' . $id, 'lp-quizzes' );
200
 
201
  if ( false === $questions || $quiz->get_no_cache() ) {
202
  $this->load_questions( $quiz->get_id() );
250
  //}
251
 
252
  foreach ( $questions as $quiz_id => $quiz_questions ) {
253
+ LP_Object_Cache::set( 'questions-' . $quiz_id, $quiz_questions, 'lp-quizzes' );
254
  }
255
 
256
  LP_Helper_CURD::update_meta_cache( 'post', $question_ids );
262
  * @param LP_Quiz $quiz
263
  */
264
  protected function _update_meta_cache( &$quiz ) {
265
+ $meta_ids = LP_Object_Cache::get( 'questions-' . $quiz->get_id(), 'lp-quizzes' );
266
 
267
  if ( false === $meta_ids ) {
268
  $meta_ids = array( $quiz->get_id() );
386
  return $this->get_error( 'QUIZ_NOT_EXISTS' );
387
  }
388
 
389
+ return LP_Object_Cache::get( 'questions-' . $the_quiz->get_id(), 'lp-quizzes' );
390
  }
391
 
392
  /**
414
  $list_questions = $this->get_questions( $the_quiz );
415
  // add new question and set to cache
416
  $list_questions[ $question_id ] = strval( $question_id );
417
+ LP_Object_Cache::set( 'questions-' . $the_quiz->get_id(), $list_questions, 'lp-quizzes' );
418
 
419
  global $wpdb;
420
  $id = $the_quiz->get_id();
inc/curds/class-lp-section-curd.php CHANGED
@@ -129,7 +129,7 @@ class LP_Section_CURD extends LP_Object_Data_CURD implements LP_Interface_CURD {
129
  */
130
  public function clear() {
131
 
132
- $sections_ids = wp_cache_get( 'course-' . $this->course_id, 'lp-course-sections-ids' );
133
 
134
  if ( ! $sections_ids ) {
135
  return false;
@@ -199,14 +199,14 @@ class LP_Section_CURD extends LP_Object_Data_CURD implements LP_Interface_CURD {
199
  public function read_sections_ids() {
200
 
201
  // Get course's sections id data from cache
202
- $ids = wp_cache_get( 'course-' . $this->course_id, 'lp-course-sections-ids' );
203
 
204
  if ( ! $ids ) {
205
  global $wpdb;
206
  // get sections id
207
  $ids = $wpdb->get_col( $wpdb->prepare( "SELECT section_id FROM {$wpdb->prefix}learnpress_sections WHERE section_course_id = %d", $this->course_id ) );
208
  // Set cache
209
- wp_cache_set( 'course-' . $this->course_id, $ids, 'lp-course-sections-ids' );
210
  }
211
 
212
  return $ids;
@@ -238,7 +238,7 @@ class LP_Section_CURD extends LP_Object_Data_CURD implements LP_Interface_CURD {
238
  public function sort_sections( $sections ) {
239
  global $wpdb;
240
 
241
- $current_sections = wp_cache_get( 'course-' . $this->course_id, 'lp-course-sections' );
242
  $new_sections = array();
243
 
244
  $orders = array();
@@ -259,7 +259,7 @@ class LP_Section_CURD extends LP_Object_Data_CURD implements LP_Interface_CURD {
259
  $this->get_section_items( $section_id );
260
  }
261
 
262
- wp_cache_set( 'course-' . $this->course_id, $new_sections, 'lp-course-sections' );
263
 
264
  return $orders;
265
  }
@@ -290,7 +290,7 @@ class LP_Section_CURD extends LP_Object_Data_CURD implements LP_Interface_CURD {
290
  }
291
  }
292
 
293
- wp_cache_set( 'course-' . $this->course_id . '-' . $section_id, $return, 'lp-course-section-items' );
294
 
295
  return $return;
296
  }
@@ -404,7 +404,7 @@ class LP_Section_CURD extends LP_Object_Data_CURD implements LP_Interface_CURD {
404
  $order ++;
405
  }
406
 
407
- wp_cache_set( 'course-' . $this->course_id . '-' . $section_id, $all_items, 'lp-course-section-items' );
408
 
409
  // allow hook
410
  do_action( 'learn-press/after-add-items-section', $items, $section_id, $this->course_id, $result );
@@ -459,7 +459,7 @@ class LP_Section_CURD extends LP_Object_Data_CURD implements LP_Interface_CURD {
459
  */
460
  public function update_final_item() {
461
 
462
- $sections = wp_cache_get( 'course-' . $this->course_id, 'lp-course-sections' );
463
 
464
  if ( ! $sections ) {
465
  return false;
@@ -469,7 +469,7 @@ class LP_Section_CURD extends LP_Object_Data_CURD implements LP_Interface_CURD {
469
  $section_id = $last_section->section_id;
470
 
471
  // get last section items
472
- $section_items = wp_cache_get( 'course-' . $this->course_id . '-' . $section_id, 'lp-course-section-items' );
473
 
474
  $types = apply_filters( 'learn-press/post-types-support-assessment-by-final-item', array( LP_QUIZ_CPT ) );
475
 
@@ -574,7 +574,7 @@ class LP_Section_CURD extends LP_Object_Data_CURD implements LP_Interface_CURD {
574
  }
575
  }
576
 
577
- wp_cache_set( 'course-' . $this->course_id . '-' . $section_id, $items, 'lp-course-section-items' );
578
 
579
  return $items;
580
  }
129
  */
130
  public function clear() {
131
 
132
+ $sections_ids = LP_Object_Cache::get( 'course-' . $this->course_id, 'lp-course-sections-ids' );
133
 
134
  if ( ! $sections_ids ) {
135
  return false;
199
  public function read_sections_ids() {
200
 
201
  // Get course's sections id data from cache
202
+ $ids = LP_Object_Cache::get( 'course-' . $this->course_id, 'lp-course-sections-ids' );
203
 
204
  if ( ! $ids ) {
205
  global $wpdb;
206
  // get sections id
207
  $ids = $wpdb->get_col( $wpdb->prepare( "SELECT section_id FROM {$wpdb->prefix}learnpress_sections WHERE section_course_id = %d", $this->course_id ) );
208
  // Set cache
209
+ LP_Object_Cache::set( 'course-' . $this->course_id, $ids, 'lp-course-sections-ids' );
210
  }
211
 
212
  return $ids;
238
  public function sort_sections( $sections ) {
239
  global $wpdb;
240
 
241
+ $current_sections = LP_Object_Cache::get( 'course-' . $this->course_id, 'lp-course-sections' );
242
  $new_sections = array();
243
 
244
  $orders = array();
259
  $this->get_section_items( $section_id );
260
  }
261
 
262
+ LP_Object_Cache::set( 'course-' . $this->course_id, $new_sections, 'lp-course-sections' );
263
 
264
  return $orders;
265
  }
290
  }
291
  }
292
 
293
+ LP_Object_Cache::set( 'course-' . $this->course_id . '-' . $section_id, $return, 'lp-course-section-items' );
294
 
295
  return $return;
296
  }
404
  $order ++;
405
  }
406
 
407
+ LP_Object_Cache::set( 'course-' . $this->course_id . '-' . $section_id, $all_items, 'lp-course-section-items' );
408
 
409
  // allow hook
410
  do_action( 'learn-press/after-add-items-section', $items, $section_id, $this->course_id, $result );
459
  */
460
  public function update_final_item() {
461
 
462
+ $sections = LP_Object_Cache::get( 'course-' . $this->course_id, 'lp-course-sections' );
463
 
464
  if ( ! $sections ) {
465
  return false;
469
  $section_id = $last_section->section_id;
470
 
471
  // get last section items
472
+ $section_items = LP_Object_Cache::get( 'course-' . $this->course_id . '-' . $section_id, 'lp-course-section-items' );
473
 
474
  $types = apply_filters( 'learn-press/post-types-support-assessment-by-final-item', array( LP_QUIZ_CPT ) );
475
 
574
  }
575
  }
576
 
577
+ LP_Object_Cache::set( 'course-' . $this->course_id . '-' . $section_id, $items, 'lp-course-section-items' );
578
 
579
  return $items;
580
  }
inc/curds/class-lp-user-curd.php CHANGED
@@ -147,14 +147,14 @@ class LP_User_CURD extends LP_Object_Data_CURD implements LP_Interface_CURD {
147
  /**
148
  * Get orders from cache by args
149
  */
150
- if ( false !== ( $orders = wp_cache_get( "user-{$user_id}-" . $cache_key, 'lp-user-orders' ) ) ) {
151
  LP_Debug::log_function( __CLASS__ . '::' . __FUNCTION__ );
152
 
153
  return $orders;
154
  }
155
  }
156
  // Get orders for the user from cache
157
- $orders = wp_cache_get( 'user-' . $user_id, 'lp-user-orders' );
158
 
159
  if ( false === $orders ) {
160
  global $wpdb;
@@ -223,7 +223,7 @@ class LP_User_CURD extends LP_Object_Data_CURD implements LP_Interface_CURD {
223
  }
224
  }
225
  // Store to cache
226
- wp_cache_set( 'user-' . $user_id, $orders, 'lp-user-orders' );
227
  }
228
 
229
  if ( $orders ) {
@@ -247,7 +247,7 @@ class LP_User_CURD extends LP_Object_Data_CURD implements LP_Interface_CURD {
247
  }
248
 
249
  if ( $cache_key ) {
250
- wp_cache_set( "user-{$user_id}-" . $cache_key, $orders, 'lp-user-orders' );
251
  }
252
 
253
  LP_Debug::log_function( __CLASS__ . '::' . __FUNCTION__ );
@@ -313,9 +313,9 @@ class LP_User_CURD extends LP_Object_Data_CURD implements LP_Interface_CURD {
313
  wp_cache_delete( 'course-' . $user_id . '-' . $id, 'lp-user-courses' );
314
  }
315
 
316
- if ( false === wp_cache_get( 'course-' . $user_id . '-' . $id, 'lp-user-courses' ) ) {
317
  $fetch_ids[] = $id;
318
- //wp_cache_set( 'course-' . $user_id . '-' . $id, array( 'items' => array() ), 'lp-user-courses' );
319
  }
320
  }
321
 
@@ -391,13 +391,13 @@ class LP_User_CURD extends LP_Object_Data_CURD implements LP_Interface_CURD {
391
  * Ignore row if it is already added. We sort the rows by newest user_item_id
392
  * therefore the first row in a group of item_id is row we need.
393
  */
394
- if ( false !== wp_cache_get( 'course-' . $user_id . '-' . $result['item_id'], 'lp-user-courses' ) ) {
395
  continue;
396
  }
397
 
398
  $result['items'] = array();
399
  $this->_read_course_items( $result, $force );
400
- wp_cache_set( 'course-' . $user_id . '-' . $result['item_id'], $result, 'lp-user-courses' );
401
 
402
  // Remove the course has already read!
403
  $fetch_ids = array_diff( $fetch_ids, array( $result['item_id'] ) );
@@ -423,7 +423,7 @@ class LP_User_CURD extends LP_Object_Data_CURD implements LP_Interface_CURD {
423
  // 'items' => array()
424
  // );
425
  // foreach ( $fetch_ids as $fetch_id ) {
426
- // wp_cache_set( 'course-' . $user_id . '-' . $fetch_id, $defaults, 'lp-user-courses' );
427
  // }
428
  // }
429
  LP_Debug::log_function( __CLASS__ . '::' . __FUNCTION__ );
@@ -478,7 +478,7 @@ class LP_User_CURD extends LP_Object_Data_CURD implements LP_Interface_CURD {
478
  foreach ( $items as $user_item_id => $_items ) {
479
  $cache_name = sprintf( 'course-item-%d-%d-%d', $parent_item['user_id'], $parent_item['item_id'], $user_item_id );
480
  // Refresh caching
481
- wp_cache_set( $cache_name, $_items, 'lp-user-course-items' );
482
  }
483
  }
484
 
@@ -494,7 +494,7 @@ class LP_User_CURD extends LP_Object_Data_CURD implements LP_Interface_CURD {
494
  * @return mixed
495
  */
496
  public function get_user_items( $user_id, $course_id ) {
497
- if ( false === ( $course_data = wp_cache_get( 'course-' . $user_id . '-' . $course_id, 'lp-user-courses' ) ) ) {
498
  return false;
499
  }
500
 
@@ -669,7 +669,7 @@ class LP_User_CURD extends LP_Object_Data_CURD implements LP_Interface_CURD {
669
  if ( $is_course ) {
670
  $course_id = $item['item_id'];
671
  // Update cache to effect the change right way!
672
- wp_cache_set( 'course-' . $user_id . '-' . $course_id, $item, 'lp-user-courses' );
673
  } else {
674
 
675
  $user = learn_press_get_user( $user_id );
@@ -678,7 +678,7 @@ class LP_User_CURD extends LP_Object_Data_CURD implements LP_Interface_CURD {
678
  $user_course->set_item( $item );
679
 
680
  // Update cache
681
- $existed = false !== ( $items = wp_cache_get( 'course-item-' . $user_id . '-' . $course_id . '-' . $item_id, 'lp-user-course-items' ) );
682
 
683
  if ( false === $items || ! empty( $items[ $user_item_id ] ) ) {
684
  if ( is_array( $items ) ) {
@@ -690,7 +690,7 @@ class LP_User_CURD extends LP_Object_Data_CURD implements LP_Interface_CURD {
690
  $items = array( $user_item_id => $item ) + $items;
691
  }
692
 
693
- wp_cache_set( 'course-item-' . $user_id . '-' . $course_id . '-' . $item_id, $items, 'lp-user-course-items' );
694
 
695
  }
696
 
@@ -724,11 +724,11 @@ class LP_User_CURD extends LP_Object_Data_CURD implements LP_Interface_CURD {
724
 
725
  if ( $num_args == 2 ) {
726
  $this->read_course( $user_id, $item_id );
727
- $item = wp_cache_get( 'course-' . $user_id . '-' . $item_id, 'lp-user-courses' );
728
  } else {
729
  $this->read_course( $user_id, $course_id );
730
  $cache_name = sprintf( 'course-item-%d-%d-%d', $user_id, $course_id, $item_id );
731
- $item = wp_cache_get( $cache_name, 'lp-user-course-items' );
732
 
733
  if ( $last && $item ) {
734
  $item = reset( $item );
@@ -1010,7 +1010,7 @@ class LP_User_CURD extends LP_Object_Data_CURD implements LP_Interface_CURD {
1010
 
1011
  $cache_key = sprintf( 'own-courses-%d-%s', $user_id, md5( build_query( $args ) ) );
1012
 
1013
- if ( false === ( $courses = wp_cache_get( $cache_key, 'lp-user-courses' ) ) ) {
1014
 
1015
  $courses = array(
1016
  'total' => 0,
@@ -1076,7 +1076,7 @@ class LP_User_CURD extends LP_Object_Data_CURD implements LP_Interface_CURD {
1076
  learn_press_add_message( $ex->getMessage() );
1077
  }
1078
 
1079
- wp_cache_set( $cache_key, $courses, 'lp-user-courses' );
1080
  }
1081
 
1082
  $courses['single'] = __( 'course', 'learnpress' );
@@ -1119,7 +1119,7 @@ class LP_User_CURD extends LP_Object_Data_CURD implements LP_Interface_CURD {
1119
 
1120
  $cache_key = sprintf( 'purchased-courses-%d-%s', $user_id, md5( build_query( $args ) ) );
1121
 
1122
- if ( false === ( $courses = wp_cache_get( $cache_key, 'lp-user-courses' ) ) ) {
1123
 
1124
  $courses = array(
1125
  'total' => 0,
@@ -1269,7 +1269,7 @@ class LP_User_CURD extends LP_Object_Data_CURD implements LP_Interface_CURD {
1269
 
1270
  }
1271
 
1272
- wp_cache_set( $cache_key, $courses, 'lp-user-courses' );
1273
  }
1274
 
1275
  $courses['single'] = __( 'course', 'learnpress' );
@@ -1364,7 +1364,7 @@ class LP_User_CURD extends LP_Object_Data_CURD implements LP_Interface_CURD {
1364
 
1365
  $cache_key = sprintf( 'quizzes-%d-%s', $user_id, md5( build_query( $args ) ) );
1366
 
1367
- if ( false === ( $quizzes = wp_cache_get( $cache_key, 'lp-user-quizzes' ) ) ) {
1368
 
1369
  $orders = $this->get_orders( $user_id );
1370
  $query = array( 'total' => 0, 'pages' => 0, 'items' => false );
@@ -1467,7 +1467,7 @@ class LP_User_CURD extends LP_Object_Data_CURD implements LP_Interface_CURD {
1467
  } catch ( Exception $ex ) {
1468
 
1469
  }
1470
- wp_cache_set( $cache_key, $quizzes, 'lp-user-course' );
1471
  }
1472
 
1473
  $quizzes['single'] = __( 'quiz', 'learnpress' );
147
  /**
148
  * Get orders from cache by args
149
  */
150
+ if ( false !== ( $orders = LP_Object_Cache::get( "user-{$user_id}-" . $cache_key, 'lp-user-orders' ) ) ) {
151
  LP_Debug::log_function( __CLASS__ . '::' . __FUNCTION__ );
152
 
153
  return $orders;
154
  }
155
  }
156
  // Get orders for the user from cache
157
+ $orders = LP_Object_Cache::get( 'user-' . $user_id, 'lp-user-orders' );
158
 
159
  if ( false === $orders ) {
160
  global $wpdb;
223
  }
224
  }
225
  // Store to cache
226
+ LP_Object_Cache::set( 'user-' . $user_id, $orders, 'lp-user-orders' );
227
  }
228
 
229
  if ( $orders ) {
247
  }
248
 
249
  if ( $cache_key ) {
250
+ LP_Object_Cache::set( "user-{$user_id}-" . $cache_key, $orders, 'lp-user-orders' );
251
  }
252
 
253
  LP_Debug::log_function( __CLASS__ . '::' . __FUNCTION__ );
313
  wp_cache_delete( 'course-' . $user_id . '-' . $id, 'lp-user-courses' );
314
  }
315
 
316
+ if ( false === LP_Object_Cache::get( 'course-' . $user_id . '-' . $id, 'lp-user-courses' ) ) {
317
  $fetch_ids[] = $id;
318
+ //LP_Object_Cache::set( 'course-' . $user_id . '-' . $id, array( 'items' => array() ), 'lp-user-courses' );
319
  }
320
  }
321
 
391
  * Ignore row if it is already added. We sort the rows by newest user_item_id
392
  * therefore the first row in a group of item_id is row we need.
393
  */
394
+ if ( false !== LP_Object_Cache::get( 'course-' . $user_id . '-' . $result['item_id'], 'lp-user-courses' ) ) {
395
  continue;
396
  }
397
 
398
  $result['items'] = array();
399
  $this->_read_course_items( $result, $force );
400
+ LP_Object_Cache::set( 'course-' . $user_id . '-' . $result['item_id'], $result, 'lp-user-courses' );
401
 
402
  // Remove the course has already read!
403
  $fetch_ids = array_diff( $fetch_ids, array( $result['item_id'] ) );
423
  // 'items' => array()
424
  // );
425
  // foreach ( $fetch_ids as $fetch_id ) {
426
+ // LP_Object_Cache::set( 'course-' . $user_id . '-' . $fetch_id, $defaults, 'lp-user-courses' );
427
  // }
428
  // }
429
  LP_Debug::log_function( __CLASS__ . '::' . __FUNCTION__ );
478
  foreach ( $items as $user_item_id => $_items ) {
479
  $cache_name = sprintf( 'course-item-%d-%d-%d', $parent_item['user_id'], $parent_item['item_id'], $user_item_id );
480
  // Refresh caching
481
+ LP_Object_Cache::set( $cache_name, $_items, 'lp-user-course-items' );
482
  }
483
  }
484
 
494
  * @return mixed
495
  */
496
  public function get_user_items( $user_id, $course_id ) {
497
+ if ( false === ( $course_data = LP_Object_Cache::get( 'course-' . $user_id . '-' . $course_id, 'lp-user-courses' ) ) ) {
498
  return false;
499
  }
500
 
669
  if ( $is_course ) {
670
  $course_id = $item['item_id'];
671
  // Update cache to effect the change right way!
672
+ LP_Object_Cache::set( 'course-' . $user_id . '-' . $course_id, $item, 'lp-user-courses' );
673
  } else {
674
 
675
  $user = learn_press_get_user( $user_id );
678
  $user_course->set_item( $item );
679
 
680
  // Update cache
681
+ $existed = false !== ( $items = LP_Object_Cache::get( 'course-item-' . $user_id . '-' . $course_id . '-' . $item_id, 'lp-user-course-items' ) );
682
 
683
  if ( false === $items || ! empty( $items[ $user_item_id ] ) ) {
684
  if ( is_array( $items ) ) {
690
  $items = array( $user_item_id => $item ) + $items;
691
  }
692
 
693
+ LP_Object_Cache::set( 'course-item-' . $user_id . '-' . $course_id . '-' . $item_id, $items, 'lp-user-course-items' );
694
 
695
  }
696
 
724
 
725
  if ( $num_args == 2 ) {
726
  $this->read_course( $user_id, $item_id );
727
+ $item = LP_Object_Cache::get( 'course-' . $user_id . '-' . $item_id, 'lp-user-courses' );
728
  } else {
729
  $this->read_course( $user_id, $course_id );
730
  $cache_name = sprintf( 'course-item-%d-%d-%d', $user_id, $course_id, $item_id );
731
+ $item = LP_Object_Cache::get( $cache_name, 'lp-user-course-items' );
732
 
733
  if ( $last && $item ) {
734
  $item = reset( $item );
1010
 
1011
  $cache_key = sprintf( 'own-courses-%d-%s', $user_id, md5( build_query( $args ) ) );
1012
 
1013
+ if ( false === ( $courses = LP_Object_Cache::get( $cache_key, 'lp-user-courses' ) ) ) {
1014
 
1015
  $courses = array(
1016
  'total' => 0,
1076
  learn_press_add_message( $ex->getMessage() );
1077
  }
1078
 
1079
+ LP_Object_Cache::set( $cache_key, $courses, 'lp-user-courses' );
1080
  }
1081
 
1082
  $courses['single'] = __( 'course', 'learnpress' );
1119
 
1120
  $cache_key = sprintf( 'purchased-courses-%d-%s', $user_id, md5( build_query( $args ) ) );
1121
 
1122
+ if ( false === ( $courses = LP_Object_Cache::get( $cache_key, 'lp-user-courses' ) ) ) {
1123
 
1124
  $courses = array(
1125
  'total' => 0,
1269
 
1270
  }
1271
 
1272
+ LP_Object_Cache::set( $cache_key, $courses, 'lp-user-courses' );
1273
  }
1274
 
1275
  $courses['single'] = __( 'course', 'learnpress' );
1364
 
1365
  $cache_key = sprintf( 'quizzes-%d-%s', $user_id, md5( build_query( $args ) ) );
1366
 
1367
+ if ( false === ( $quizzes = LP_Object_Cache::get( $cache_key, 'lp-user-quizzes' ) ) ) {
1368
 
1369
  $orders = $this->get_orders( $user_id );
1370
  $query = array( 'total' => 0, 'pages' => 0, 'items' => false );
1467
  } catch ( Exception $ex ) {
1468
 
1469
  }
1470
+ LP_Object_Cache::set( $cache_key, $quizzes, 'lp-user-course' );
1471
  }
1472
 
1473
  $quizzes['single'] = __( 'quiz', 'learnpress' );
inc/curds/class-lp-user-item-curd.php CHANGED
@@ -76,7 +76,7 @@ class LP_User_Item_CURD implements LP_Interface_CURD {
76
  LP_Debug::log_function( __CLASS__ . '::' . __FUNCTION__ );
77
 
78
  $id = $quiz->get_id();
79
- $questions = wp_cache_get( 'questions-' . $id, 'lp-quizzes' );
80
  if ( false === $questions || $quiz->get_no_cache() ) {
81
  global $wpdb;
82
  $questions = array();
@@ -94,7 +94,7 @@ class LP_User_Item_CURD implements LP_Interface_CURD {
94
  $questions[ $v->ID ] = $v->ID;
95
  }
96
  }
97
- wp_cache_set( 'questions-' . $id, $questions, 'lp-quizzes' );
98
 
99
  $this->_load_question_answers( $quiz );
100
  }
@@ -107,7 +107,7 @@ class LP_User_Item_CURD implements LP_Interface_CURD {
107
  * @param LP_Quiz $quiz
108
  */
109
  protected function _update_meta_cache( &$quiz ) {
110
- $meta_ids = wp_cache_get( 'questions-' . $quiz->get_id(), 'lp-quizzes' );
111
 
112
  if ( false === $meta_ids ) {
113
  $meta_ids = array( $quiz->get_id() );
@@ -170,7 +170,7 @@ class LP_User_Item_CURD implements LP_Interface_CURD {
170
  }
171
 
172
  foreach ( $answer_options as $question_id => $options ) {
173
- wp_cache_set( 'answer-options-' . $question_id, $options, 'lp-questions' );
174
  }
175
 
176
  foreach ( $meta_ids as $meta_id ) {
@@ -185,7 +185,7 @@ class LP_User_Item_CURD implements LP_Interface_CURD {
185
  }
186
  if ( $un_fetched ) {
187
  foreach ( $un_fetched as $question_id ) {
188
- wp_cache_set( 'answer-options-' . $question_id, array(), 'lp-questions' );
189
  }
190
  }
191
  //
@@ -306,7 +306,7 @@ class LP_User_Item_CURD implements LP_Interface_CURD {
306
  return $this->get_error( 'QUESTION_NOT_EXISTS' );
307
  }
308
 
309
- return wp_cache_get( 'questions-' . $the_quiz->get_id(), 'lp-quizzes' );
310
  }
311
 
312
  /**
76
  LP_Debug::log_function( __CLASS__ . '::' . __FUNCTION__ );
77
 
78
  $id = $quiz->get_id();
79
+ $questions = LP_Object_Cache::get( 'questions-' . $id, 'lp-quizzes' );
80
  if ( false === $questions || $quiz->get_no_cache() ) {
81
  global $wpdb;
82
  $questions = array();
94
  $questions[ $v->ID ] = $v->ID;
95
  }
96
  }
97
+ LP_Object_Cache::set( 'questions-' . $id, $questions, 'lp-quizzes' );
98
 
99
  $this->_load_question_answers( $quiz );
100
  }
107
  * @param LP_Quiz $quiz
108
  */
109
  protected function _update_meta_cache( &$quiz ) {
110
+ $meta_ids = LP_Object_Cache::get( 'questions-' . $quiz->get_id(), 'lp-quizzes' );
111
 
112
  if ( false === $meta_ids ) {
113
  $meta_ids = array( $quiz->get_id() );
170
  }
171
 
172
  foreach ( $answer_options as $question_id => $options ) {
173
+ LP_Object_Cache::set( 'answer-options-' . $question_id, $options, 'lp-questions' );
174
  }
175
 
176
  foreach ( $meta_ids as $meta_id ) {
185
  }
186
  if ( $un_fetched ) {
187
  foreach ( $un_fetched as $question_id ) {
188
+ LP_Object_Cache::set( 'answer-options-' . $question_id, array(), 'lp-questions' );
189
  }
190
  }
191
  //
306
  return $this->get_error( 'QUESTION_NOT_EXISTS' );
307
  }
308
 
309
+ return LP_Object_Cache::get( 'questions-' . $the_quiz->get_id(), 'lp-quizzes' );
310
  }
311
 
312
  /**
inc/custom-post-types/abstract.php CHANGED
@@ -151,7 +151,7 @@ abstract class LP_Abstract_Post_Type {
151
  jQuery(function ($) {
152
  var $input = $('#post-search-input'),
153
  $form = $($input[0].form),
154
- $select = $('<select name="author" id="author"></select>').append('<?php echo esc_js($option);?>').insertAfter($input).select2({
155
  ajax: {
156
  url: window.location.href + '&lp-ajax=search-authors',
157
  dataType: 'json',
@@ -631,12 +631,30 @@ abstract class LP_Abstract_Post_Type {
631
  }
632
 
633
  public function columns_content( $column, $post_id = 0 ) {
634
- return;
635
- $callback = array( $this, "column_{$column}" );
636
- if ( is_callable( $callback ) ) {
637
- $func_args = func_get_args();
638
- call_user_func_array( $callback, $func_args );
639
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
640
  }
641
 
642
  public function _post_row_actions( $actions, $post ) {
@@ -781,4 +799,29 @@ abstract class LP_Abstract_Post_Type {
781
 
782
  return $messages;
783
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
784
  }
151
  jQuery(function ($) {
152
  var $input = $('#post-search-input'),
153
  $form = $($input[0].form),
154
+ $select = $('<select name="author" id="author"></select>').append('<?php echo esc_js( $option );?>').insertAfter($input).select2({
155
  ajax: {
156
  url: window.location.href + '&lp-ajax=search-authors',
157
  dataType: 'json',
631
  }
632
 
633
  public function columns_content( $column, $post_id = 0 ) {
634
+
635
+ }
636
+
637
+ /**
638
+ * Get string for searching
639
+ *
640
+ * @return string
641
+ */
642
+ private function _get_search() {
643
+ return LP_Request::get( 's' );
644
+ }
645
+
646
+ /**
647
+ * @return string
648
+ */
649
+ private function _get_order() {
650
+ return strtolower( LP_Request::get( 'order' ) ) === 'desc' ? 'DESC' : 'ASC';
651
+ }
652
+
653
+ /**
654
+ * @return mixed
655
+ */
656
+ private function _get_orderby() {
657
+ return LP_Request::get( 'orderby' );
658
  }
659
 
660
  public function _post_row_actions( $actions, $post ) {
799
 
800
  return $messages;
801
  }
802
+ }
803
+
804
+ class LP_Abstract_Post_Type_Core extends LP_Abstract_Post_Type{
805
+ /**
806
+ * Get string for searching
807
+ *
808
+ * @return string
809
+ */
810
+ protected function _get_search() {
811
+ return LP_Request::get( 's' );
812
+ }
813
+
814
+ /**
815
+ * @return string
816
+ */
817
+ protected function _get_order() {
818
+ return strtolower( LP_Request::get( 'order' ) ) === 'desc' ? 'DESC' : 'ASC';
819
+ }
820
+
821
+ /**
822
+ * @return mixed
823
+ */
824
+ protected function _get_orderby() {
825
+ return LP_Request::get( 'orderby' );
826
+ }
827
  }
inc/custom-post-types/course.php CHANGED
@@ -17,7 +17,7 @@ if ( ! class_exists( 'LP_Course_Post_Type' ) ) {
17
  /**
18
  * Class LP_Course_Post_Type
19
  */
20
- final class LP_Course_Post_Type extends LP_Abstract_Post_Type {
21
  /**
22
  * New version of course editor
23
  *
@@ -491,9 +491,11 @@ if ( ! class_exists( 'LP_Course_Post_Type' ) ) {
491
  if ( ! $this->_is_archive() ) {
492
  return $order_by_statement;
493
  }
 
 
494
  switch ( $this->_get_orderby() ) {
495
  case 'price':
496
- $order_by_statement = "pm_price.meta_value {$_GET['order']}";
497
  }
498
 
499
  return $order_by_statement;
@@ -520,14 +522,6 @@ if ( ! class_exists( 'LP_Course_Post_Type' ) ) {
520
  return true;
521
  }
522
 
523
- private function _get_orderby() {
524
- return isset( $_REQUEST['orderby'] ) ? $_REQUEST['orderby'] : '';
525
- }
526
-
527
- private function _get_search() {
528
- return isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : false;
529
- }
530
-
531
  /**
532
  * Add meta boxes to course post type page
533
  */
@@ -598,13 +592,6 @@ if ( ! class_exists( 'LP_Course_Post_Type' ) ) {
598
  'desc' => __( 'How many students have taken this course.', 'learnpress' ),
599
  'std' => 0,
600
  ),
601
- // array(
602
- // 'name' => __( 'Use Students Enrolled for counter', 'learnpress' ),
603
- // 'id' => '_lp_append_students',
604
- // 'type' => 'yes_no',
605
- // 'desc' => __( 'Append the value of Students Enrolled above for counting the real users enrolled course.', 'learnpress' ),
606
- // 'std' => 'yes',
607
- // ),
608
  array(
609
  'name' => __( 'Re-take Course', 'learnpress' ),
610
  'id' => '_lp_retake_count',
@@ -657,15 +644,8 @@ if ( ! class_exists( 'LP_Course_Post_Type' ) ) {
657
  $post_id = LP_Request::get_int( 'post' );
658
  $post_id = $post_id ? $post_id : ( ! empty( $post ) ? $post->ID : 0 );
659
 
 
660
  $course_result_desc = '';
661
-
662
- if ( $course_results = get_post_meta( $post_id, '_lp_course_result', true ) ) {
663
- if ( in_array( $course_results, array( '', 'evaluate_lesson', 'evaluate_final_quiz' ) ) ) {
664
- //$course_result_desc .= sprintf( '<a href="" data-advanced="%2$s" data-basic="%1$s" data-click="basic">%2$s</a>', __( 'Basic Options', 'learnpress' ), __( 'Advanced Options', 'learnpress' ) );
665
- }
666
- }
667
-
668
- //$course_result_desc = "<span id=\"learn-press-toggle-course-results\">{$course_result_desc}</span>";
669
  $course_result_desc .= __( 'The method to assess the result of a student for a course.', 'learnpress' );
670
 
671
  if ( $course_results == 'evaluate_final_quiz' && ! get_post_meta( $post_id, '_lp_final_quiz', true ) ) {
@@ -920,7 +900,7 @@ if ( ! class_exists( 'LP_Course_Post_Type' ) ) {
920
  */
921
  public static function author_meta_box() {
922
 
923
- $course_id = ! empty( $_GET['post'] ) ? $_GET['post'] : 0;
924
  $post = get_post( $course_id );
925
  $author = $post ? $post->post_author : get_current_user_id();
926
 
@@ -1277,6 +1257,10 @@ if ( ! class_exists( 'LP_Course_Post_Type' ) ) {
1277
  * @return array
1278
  */
1279
  public function columns_head( $columns ) {
 
 
 
 
1280
  $user = wp_get_current_user();
1281
  if ( in_array( 'lp_teacher', $user->roles ) ) {
1282
  unset( $columns['author'] );
@@ -1302,13 +1286,6 @@ if ( ! class_exists( 'LP_Course_Post_Type' ) ) {
1302
 
1303
  $columns['taxonomy-course_category'] = __( 'Categories', 'learnpress' );
1304
 
1305
- global $wp_query;
1306
- if ( $wp_query->is_main_query() ) {
1307
- if ( LP_COURSE_CPT == $wp_query->query['post_type'] && $wp_query->posts ) {
1308
- $post_ids = wp_list_pluck( $wp_query->posts, 'ID' );
1309
- }
1310
- }
1311
-
1312
  return $columns;
1313
  }
1314
 
@@ -1336,7 +1313,7 @@ if ( ! class_exists( 'LP_Course_Post_Type' ) ) {
1336
 
1337
  if ( $number_sections ) {
1338
  // get items
1339
- $items = wp_cache_get( 'course-' . $post->ID, 'lp-course-items' );
1340
 
1341
  $number_lessons = $number_quizzes = 0;
1342
  if ( $items ) {
@@ -1404,7 +1381,6 @@ if ( ! class_exists( 'LP_Course_Post_Type' ) ) {
1404
  }
1405
 
1406
  remove_action( 'save_post', array( $this, 'before_save_curriculum' ), 1 );
1407
- //remove_action( 'rwmb_course_curriculum_before_save_post', array( $this, 'before_save_curriculum' ) );
1408
 
1409
  $user = learn_press_get_current_user();
1410
  $required_review = LP()->settings->get( 'required_review' ) == 'yes';
@@ -1437,7 +1413,6 @@ if ( ! class_exists( 'LP_Course_Post_Type' ) ) {
1437
 
1438
  $this->_review_log();
1439
  delete_post_meta( $post->ID, '_lp_curriculum' );
1440
- //add_action( 'rwmb_course_curriculum_before_save_post', array( $this, 'before_save_curriculum' ) );
1441
  }
1442
 
1443
  public function currency_symbol( $input_html, $field, $sub_meta ) {
17
  /**
18
  * Class LP_Course_Post_Type
19
  */
20
+ final class LP_Course_Post_Type extends LP_Abstract_Post_Type_Core {
21
  /**
22
  * New version of course editor
23
  *
491
  if ( ! $this->_is_archive() ) {
492
  return $order_by_statement;
493
  }
494
+
495
+ $order = $this->_get_order();
496
  switch ( $this->_get_orderby() ) {
497
  case 'price':
498
+ $order_by_statement = "pm_price.meta_value {$order}";
499
  }
500
 
501
  return $order_by_statement;
522
  return true;
523
  }
524
 
 
 
 
 
 
 
 
 
525
  /**
526
  * Add meta boxes to course post type page
527
  */
592
  'desc' => __( 'How many students have taken this course.', 'learnpress' ),
593
  'std' => 0,
594
  ),
 
 
 
 
 
 
 
595
  array(
596
  'name' => __( 'Re-take Course', 'learnpress' ),
597
  'id' => '_lp_retake_count',
644
  $post_id = LP_Request::get_int( 'post' );
645
  $post_id = $post_id ? $post_id : ( ! empty( $post ) ? $post->ID : 0 );
646
 
647
+ $course_results = get_post_meta( $post_id, '_lp_course_result', true );
648
  $course_result_desc = '';
 
 
 
 
 
 
 
 
649
  $course_result_desc .= __( 'The method to assess the result of a student for a course.', 'learnpress' );
650
 
651
  if ( $course_results == 'evaluate_final_quiz' && ! get_post_meta( $post_id, '_lp_final_quiz', true ) ) {
900
  */
901
  public static function author_meta_box() {
902
 
903
+ $course_id = LP_Request::get_int('post');
904
  $post = get_post( $course_id );
905
  $author = $post ? $post->post_author : get_current_user_id();
906
 
1257
  * @return array
1258
  */
1259
  public function columns_head( $columns ) {
1260
+
1261
+ /**
1262
+ * @var WP_Query $wp_query
1263
+ */
1264
  $user = wp_get_current_user();
1265
  if ( in_array( 'lp_teacher', $user->roles ) ) {
1266
  unset( $columns['author'] );
1286
 
1287
  $columns['taxonomy-course_category'] = __( 'Categories', 'learnpress' );
1288
 
 
 
 
 
 
 
 
1289
  return $columns;
1290
  }
1291
 
1313
 
1314
  if ( $number_sections ) {
1315
  // get items
1316
+ $items = LP_Object_Cache::get( 'course-' . $post->ID, 'lp-course-items' );
1317
 
1318
  $number_lessons = $number_quizzes = 0;
1319
  if ( $items ) {
1381
  }
1382
 
1383
  remove_action( 'save_post', array( $this, 'before_save_curriculum' ), 1 );
 
1384
 
1385
  $user = learn_press_get_current_user();
1386
  $required_review = LP()->settings->get( 'required_review' ) == 'yes';
1413
 
1414
  $this->_review_log();
1415
  delete_post_meta( $post->ID, '_lp_curriculum' );
 
1416
  }
1417
 
1418
  public function currency_symbol( $input_html, $field, $sub_meta ) {
inc/custom-post-types/lesson.php CHANGED
@@ -17,7 +17,7 @@ if ( ! class_exists( 'LP_Lesson_Post_Type' ) ) {
17
  /**
18
  * Class LP_Lesson_Post_Type
19
  */
20
- final class LP_Lesson_Post_Type extends LP_Abstract_Post_Type {
21
  /**
22
  * @var null
23
  */
@@ -38,26 +38,6 @@ if ( ! class_exists( 'LP_Lesson_Post_Type' ) ) {
38
  parent::__construct( $post_type );
39
  }
40
 
41
- /**
42
- * @param $join
43
- *
44
- * @return string
45
- */
46
- public function posts_join_paged( $join ) {
47
- if ( ! $this->_is_archive() ) {
48
- return $join;
49
- }
50
- global $wpdb;
51
-
52
- // if ( $this->_filter_course() || ( $this->_get_orderby() == 'course-name' ) || $this->_get_search() ) {
53
- // $join .= " LEFT JOIN {$wpdb->prefix}learnpress_section_items si ON {$wpdb->posts}.ID = si.item_id";
54
- // $join .= " LEFT JOIN {$wpdb->prefix}learnpress_sections s ON s.section_id = si.section_id";
55
- // $join .= " LEFT JOIN {$wpdb->posts} c ON c.ID = s.section_course_id";
56
- // }
57
-
58
- return $join;
59
- }
60
-
61
  /**
62
  * Filter items unassigned.
63
  *
@@ -411,14 +391,6 @@ if ( ! class_exists( 'LP_Lesson_Post_Type' ) ) {
411
  return true;
412
  }
413
 
414
- private function _get_orderby() {
415
- return isset( $_REQUEST['orderby'] ) ? $_REQUEST['orderby'] : '';
416
- }
417
-
418
- private function _get_search() {
419
- return isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : false;
420
- }
421
-
422
  /**
423
  * Admin scripts.
424
  */
17
  /**
18
  * Class LP_Lesson_Post_Type
19
  */
20
+ final class LP_Lesson_Post_Type extends LP_Abstract_Post_Type_Core {
21
  /**
22
  * @var null
23
  */
38
  parent::__construct( $post_type );
39
  }
40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  /**
42
  * Filter items unassigned.
43
  *
391
  return true;
392
  }
393
 
 
 
 
 
 
 
 
 
394
  /**
395
  * Admin scripts.
396
  */
inc/custom-post-types/order.php CHANGED
@@ -7,7 +7,7 @@
7
  if ( ! class_exists( 'LP_Order_Post_Type' ) ) {
8
 
9
  // class LP_Order_Post_Type
10
- final class LP_Order_Post_Type extends LP_Abstract_Post_Type {
11
 
12
  /**
13
  * @var null
@@ -29,7 +29,6 @@ if ( ! class_exists( 'LP_Order_Post_Type' ) ) {
29
  add_action( 'transition_post_status', array( $this, 'restore_order' ), 10, 3 );
30
 
31
  add_filter( 'admin_footer', array( $this, 'admin_footer' ) );
32
- //add_action( 'add_meta_boxes', array( $this, 'post_new' ) );
33
 
34
  $this
35
  ->add_map_method( 'before_delete', 'delete_order_data' )
@@ -62,7 +61,7 @@ if ( ! class_exists( 'LP_Order_Post_Type' ) ) {
62
  if ( LP_ORDER_CPT === $type ) {
63
  $cache_key = 'lp-' . _count_posts_cache_key( $type, $perm );
64
 
65
- $counts = wp_cache_get( $cache_key, 'counts' );
66
 
67
  if ( false !== $counts ) {
68
  return $counts;
@@ -94,7 +93,7 @@ if ( ! class_exists( 'LP_Order_Post_Type' ) ) {
94
  }
95
 
96
  $counts = (object) $counts;
97
- wp_cache_set( $cache_key, $counts, 'counts' );
98
  }
99
 
100
  return $counts;
@@ -130,8 +129,8 @@ if ( ! class_exists( 'LP_Order_Post_Type' ) ) {
130
  return $where;
131
  }
132
 
133
- if ( isset( $_REQUEST['parent'] ) ) {
134
- $where .= sprintf( " AND post_parent = %d ", absint( $_REQUEST['parent'] ) );
135
  } else {
136
  $where .= " AND post_parent = 0 ";
137
  }
@@ -139,13 +138,6 @@ if ( ! class_exists( 'LP_Order_Post_Type' ) ) {
139
  return $where;
140
  }
141
 
142
- // public function post_new() {
143
- // global $post;
144
- // if ( $post && $post->post_type == 'lp_order' && $post->post_status == 'auto-draft' && learn_press_get_request( 'multi-users' ) == 'yes' ) {
145
- // update_post_meta( $post->ID, '_lp_multi_users', 'yes' );
146
- // }
147
- // }
148
-
149
  public function enqueue_scripts() {
150
  if ( get_post_type() != 'lp_order' ) {
151
  return;
@@ -179,8 +171,6 @@ if ( ! class_exists( 'LP_Order_Post_Type' ) ) {
179
  }
180
  }
181
 
182
- //return;
183
-
184
  $user_curd = new LP_User_CURD();
185
  $order_data = array();
186
  foreach ( $users as $user_id ) {
@@ -273,7 +263,7 @@ if ( ! class_exists( 'LP_Order_Post_Type' ) ) {
273
  continue;
274
  }
275
  $order_status = $order->get_order_status();
276
- $last_status = ( $order_status != '' && $order_status != 'completed' ) ? 'pending' : 'enrolled';
277
  $user_curd->update_user_item_status( $user_item_id, $last_status );
278
  // Restore data
279
  $user_curd->update_user_item_by_id(
@@ -308,96 +298,6 @@ if ( ! class_exists( 'LP_Order_Post_Type' ) ) {
308
  return false;
309
  }
310
 
311
- /**
312
- * @return string
313
- */
314
- private function _get_orderby() {
315
- return isset( $_REQUEST['orderby'] ) ? $_REQUEST['orderby'] : '';
316
- }
317
-
318
- /**
319
- * Process when saving order with multi users
320
- *
321
- * @param $post_id
322
- * @param $user_id
323
- */
324
- private function _save_order_multi_users( $post_id, $user_id ) {
325
- global $wpdb;
326
- settype( $user_id, 'array' );
327
-
328
- update_post_meta( $post_id, '_user_id', $user_id );
329
-
330
- // return;
331
- //
332
- // $sql = "
333
- // SELECT meta_id, meta_value
334
- // FROM {$wpdb->postmeta}
335
- // WHERE post_id = %d
336
- // AND meta_key = %s
337
- // ";
338
- // $sql = $wpdb->prepare( $sql, $post_id, '_user_id' );
339
- // /**
340
- // * A simpler way is remove all meta_key are _user_id and then
341
- // * add new user_id as new meta_key but this maybe make our database
342
- // * increase the auto-increment each time order is updated
343
- // * in case the user_id is not changed
344
- // */
345
- // if ( $existed = $wpdb->get_results( $sql ) ) {
346
- // $cases = array();
347
- // $edited = array();
348
- // $meta_ids = array();
349
- // $remove_ids = array( 0 );
350
- // foreach ( $existed as $k => $r ) {
351
- // if ( empty( $user_id[ $k ] ) ) {
352
- // $remove_ids[] = $r->meta_id;
353
- // continue;
354
- // }
355
- // $cases[] = $wpdb->prepare( "WHEN meta_id = %d THEN %d", $r->meta_id, $user_id[ $k ] );
356
- // $edited[] = $user_id[ $k ];
357
- // $meta_ids[] = $r->meta_id;
358
- // }
359
- // $sql = "
360
- // UPDATE {$wpdb->postmeta}
361
- // SET meta_value = CASE
362
- // " . join( "\n", $cases ) . "
363
- // ELSE meta_value
364
- // END
365
- // WHERE meta_id IN(" . join( ', ', $meta_ids ) . ")
366
- // AND post_id = %d
367
- // AND meta_key = %s
368
- // ";
369
- // $sql = $wpdb->prepare( $sql, $post_id, '_user_id' );
370
- // $wpdb->query( $sql );
371
- // $user_id = array_diff( $user_id, $edited );
372
- // }
373
- // if ( $user_id ) {
374
- // $values = array();
375
- // foreach ( $user_id as $id ) {
376
- // $values[] = sprintf( "(%d, '%s', %d)", $post_id, '_user_id', $id );
377
- // }
378
- // $sql = "INSERT INTO {$wpdb->postmeta}(post_id, meta_key, meta_value) VALUES" . join( ',', $values );
379
- // $wpdb->query( $sql );
380
- // }
381
- // $sql = "
382
- // SELECT meta_id FROM {$wpdb->postmeta} WHERE meta_id NOT IN(" . join( ',', $remove_ids ) . ") AND post_id = %d AND meta_key = %s GROUP BY meta_value
383
- // ";
384
- // $sql = $wpdb->prepare( $sql, $post_id, '_user_id' );
385
- // $keep_users = $wpdb->get_col( $sql );
386
- // if ( $keep_users ) {
387
- // $sql = "
388
- // DELETE
389
- // FROM {$wpdb->postmeta}
390
- // WHERE post_id = %d
391
- // AND meta_key = %s
392
- // AND ( meta_id NOT IN(" . join( ',', $keep_users ) . ") OR meta_value = 0)
393
- // ";
394
- // $sql = $wpdb->prepare( $sql, $post_id, '_user_id' );
395
- // $wpdb->query( $sql );
396
- // }
397
- // update_post_meta( $post_id, '_lp_multi_users', 'yes', 'yes' );
398
- // learn_press_reset_auto_increment( 'postmeta' );
399
- }
400
-
401
  /**
402
  * @param LP_Order $order
403
  * @param array $user_ids
@@ -427,7 +327,7 @@ if ( ! class_exists( 'LP_Order_Post_Type' ) ) {
427
  }
428
 
429
  $old_status = get_post_status( $new_order->get_id() );
430
- $new_order->set_order_date( $order->get_order_date('edit') );
431
  $new_order->set_parent_id( $order->get_id() );
432
  $new_order->set_user_id( $uid );
433
  $new_order->set_total( $order->get_total() );
@@ -438,7 +338,7 @@ if ( ! class_exists( 'LP_Order_Post_Type' ) ) {
438
  $new_status = get_post_status( $new_order->get_id() );
439
 
440
  if ( ( $new_status !== $old_status ) || $trigger_action ) {
441
- $status = str_replace( 'lp-', '', $new_status );
442
  $old_status = str_replace( 'lp-', '', $new_status );
443
  do_action( 'learn-press/order/status-' . $status, $new_order->get_id(), $status );
444
  do_action( 'learn-press/order/status-' . $old_status . '-to-' . $status, $new_order->get_id() );
@@ -530,10 +430,10 @@ if ( ! class_exists( 'LP_Order_Post_Type' ) ) {
530
 
531
  # filter by user id
532
  preg_match( "#{$wpdb->posts}\.post_author IN\s*\((\d+)\)#", $where, $matches );
533
- if ( !empty($matches) && isset($matches[1]) ) {
534
 
535
- $author_id = intval($matches[1]);
536
- $sql = " {$wpdb->posts}.ID IN ( SELECT
537
  IF( p.post_parent >0, p.post_parent, p.ID)
538
  FROM
539
  {$wpdb->posts} AS p
@@ -546,14 +446,14 @@ if ( ! class_exists( 'LP_Order_Post_Type' ) ) {
546
  p.post_type = 'lp_order'
547
  AND u.ID = %d ) ";
548
 
549
- $sql = $wpdb->prepare( $sql, array( LP_ORDER_CPT, '_user_id', $author_id));
550
  $where = str_replace( $matches[0], $sql, $where );
551
  }
552
-
553
  $s = $wp_query->get( 's' );
554
 
555
  if ( $s ) {
556
- $s = '%' . $wpdb->esc_like( $s ) . '%';
557
  preg_match( "#{$wpdb->posts}\.post_title LIKE#", $where, $matches2 );
558
  $sql = " {$wpdb->posts}.ID IN (
559
  SELECT
@@ -572,11 +472,11 @@ if ( ! class_exists( 'LP_Order_Post_Type' ) ) {
572
  OR u.display_name LIKE %s
573
  OR {$wpdb->posts}.ID LIKE %s
574
  ) ";
575
- $sql = $wpdb->prepare( $sql, array( LP_ORDER_CPT, '_user_id', $s, $s, $s, $s, $s ));
576
- if( !empty($matches2) && isset($matches2[0]) ) {
577
- $where = str_replace( $matches2[0], $sql. ' OR '.$matches2[0], $where );
578
  } else {
579
- $where .= " AND ".$sql;
580
  }
581
  }
582
 
@@ -593,22 +493,26 @@ if ( ! class_exists( 'LP_Order_Post_Type' ) ) {
593
  }
594
 
595
  public function posts_orderby( $orderby ) {
 
 
596
  if ( ! $this->_is_archive() ) {
597
  return $orderby;
598
  }
599
- global $wpdb;
 
 
600
  switch ( $this->_get_orderby() ) {
601
  case 'title':
602
- $orderby = "{$wpdb->posts}.ID {$_GET['order']}";
603
  break;
604
  case 'student':
605
- $orderby = "uu.user_login {$_GET['order']}";
606
  break;
607
  case 'date':
608
- $orderby = "{$wpdb->posts}.post_date {$_GET['order']}";
609
  break;
610
  case 'order_total':
611
- $orderby = " pm2.meta_value {$_GET['order']}";
612
  break;
613
  }
614
 
@@ -623,9 +527,7 @@ if ( ! class_exists( 'LP_Order_Post_Type' ) ) {
623
  $join .= " INNER JOIN {$wpdb->postmeta} pm1 ON {$wpdb->posts}.ID = pm1.post_id AND pm1.meta_key = '_user_id'";
624
  $join .= " INNER JOIN {$wpdb->postmeta} pm2 ON {$wpdb->posts}.ID = pm2.post_id AND pm2.meta_key = '_order_total'";
625
  $join .= " LEFT JOIN {$wpdb->users} uu ON pm1.meta_value = uu.ID";
626
- // $join .= " INNER JOIN {$wpdb->learnpress_order_items} AS orderItem ON orderItem.order_id = {$wpdb->posts}.ID";
627
- // $join .= " INNER JOIN {$wpdb->learnpress_order_itemmeta} AS orderItemmeta ON orderItem.order_item_id = orderItemmeta.learnpress_order_item_id AND orderItemmeta.meta_key LIKE '_total'";
628
- // var_dump($join);
629
  return $join;
630
  }
631
 
@@ -638,8 +540,8 @@ if ( ! class_exists( 'LP_Order_Post_Type' ) ) {
638
  */
639
  public function sortable_columns( $columns ) {
640
  $columns['order_student'] = 'student';
641
- $columns['order_date'] = 'date';
642
- $columns['order_total'] = 'order_total';
643
 
644
  return $columns;
645
  }
7
  if ( ! class_exists( 'LP_Order_Post_Type' ) ) {
8
 
9
  // class LP_Order_Post_Type
10
+ final class LP_Order_Post_Type extends LP_Abstract_Post_Type_Core {
11
 
12
  /**
13
  * @var null
29
  add_action( 'transition_post_status', array( $this, 'restore_order' ), 10, 3 );
30
 
31
  add_filter( 'admin_footer', array( $this, 'admin_footer' ) );
 
32
 
33
  $this
34
  ->add_map_method( 'before_delete', 'delete_order_data' )
61
  if ( LP_ORDER_CPT === $type ) {
62
  $cache_key = 'lp-' . _count_posts_cache_key( $type, $perm );
63
 
64
+ $counts = LP_Object_Cache::get( $cache_key, 'counts' );
65
 
66
  if ( false !== $counts ) {
67
  return $counts;
93
  }
94
 
95
  $counts = (object) $counts;
96
+ LP_Object_Cache::set( $cache_key, $counts, 'counts' );
97
  }
98
 
99
  return $counts;
129
  return $where;
130
  }
131
 
132
+ if ( $parent = LP_Request::get_int( 'parent' ) ) {
133
+ $where .= sprintf( " AND post_parent = %d ", $parent );
134
  } else {
135
  $where .= " AND post_parent = 0 ";
136
  }
138
  return $where;
139
  }
140
 
 
 
 
 
 
 
 
141
  public function enqueue_scripts() {
142
  if ( get_post_type() != 'lp_order' ) {
143
  return;
171
  }
172
  }
173
 
 
 
174
  $user_curd = new LP_User_CURD();
175
  $order_data = array();
176
  foreach ( $users as $user_id ) {
263
  continue;
264
  }
265
  $order_status = $order->get_order_status();
266
+ $last_status = ( $order_status != '' && $order_status != 'completed' ) ? 'pending' : 'enrolled';
267
  $user_curd->update_user_item_status( $user_item_id, $last_status );
268
  // Restore data
269
  $user_curd->update_user_item_by_id(
298
  return false;
299
  }
300
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
301
  /**
302
  * @param LP_Order $order
303
  * @param array $user_ids
327
  }
328
 
329
  $old_status = get_post_status( $new_order->get_id() );
330
+ $new_order->set_order_date( $order->get_order_date( 'edit' ) );
331
  $new_order->set_parent_id( $order->get_id() );
332
  $new_order->set_user_id( $uid );
333
  $new_order->set_total( $order->get_total() );
338
  $new_status = get_post_status( $new_order->get_id() );
339
 
340
  if ( ( $new_status !== $old_status ) || $trigger_action ) {
341
+ $status = str_replace( 'lp-', '', $new_status );
342
  $old_status = str_replace( 'lp-', '', $new_status );
343
  do_action( 'learn-press/order/status-' . $status, $new_order->get_id(), $status );
344
  do_action( 'learn-press/order/status-' . $old_status . '-to-' . $status, $new_order->get_id() );
430
 
431
  # filter by user id
432
  preg_match( "#{$wpdb->posts}\.post_author IN\s*\((\d+)\)#", $where, $matches );
433
+ if ( ! empty( $matches ) && isset( $matches[1] ) ) {
434
 
435
+ $author_id = intval( $matches[1] );
436
+ $sql = " {$wpdb->posts}.ID IN ( SELECT
437
  IF( p.post_parent >0, p.post_parent, p.ID)
438
  FROM
439
  {$wpdb->posts} AS p
446
  p.post_type = 'lp_order'
447
  AND u.ID = %d ) ";
448
 
449
+ $sql = $wpdb->prepare( $sql, array( LP_ORDER_CPT, '_user_id', $author_id ) );
450
  $where = str_replace( $matches[0], $sql, $where );
451
  }
452
+
453
  $s = $wp_query->get( 's' );
454
 
455
  if ( $s ) {
456
+ $s = '%' . $wpdb->esc_like( $s ) . '%';
457
  preg_match( "#{$wpdb->posts}\.post_title LIKE#", $where, $matches2 );
458
  $sql = " {$wpdb->posts}.ID IN (
459
  SELECT
472
  OR u.display_name LIKE %s
473
  OR {$wpdb->posts}.ID LIKE %s
474
  ) ";
475
+ $sql = $wpdb->prepare( $sql, array( LP_ORDER_CPT, '_user_id', $s, $s, $s, $s, $s ) );
476
+ if ( ! empty( $matches2 ) && isset( $matches2[0] ) ) {
477
+ $where = str_replace( $matches2[0], $sql . ' OR ' . $matches2[0], $where );
478
  } else {
479
+ $where .= " AND " . $sql;
480
  }
481
  }
482
 
493
  }
494
 
495
  public function posts_orderby( $orderby ) {
496
+ global $wpdb;
497
+
498
  if ( ! $this->_is_archive() ) {
499
  return $orderby;
500
  }
501
+
502
+ $order = $this->_get_order();
503
+
504
  switch ( $this->_get_orderby() ) {
505
  case 'title':
506
+ $orderby = "{$wpdb->posts}.ID {$order}";
507
  break;
508
  case 'student':
509
+ $orderby = "uu.user_login {$order}";
510
  break;
511
  case 'date':
512
+ $orderby = "{$wpdb->posts}.post_date {$order}";
513
  break;
514
  case 'order_total':
515
+ $orderby = " pm2.meta_value {$order}";
516
  break;
517
  }
518
 
527
  $join .= " INNER JOIN {$wpdb->postmeta} pm1 ON {$wpdb->posts}.ID = pm1.post_id AND pm1.meta_key = '_user_id'";
528
  $join .= " INNER JOIN {$wpdb->postmeta} pm2 ON {$wpdb->posts}.ID = pm2.post_id AND pm2.meta_key = '_order_total'";
529
  $join .= " LEFT JOIN {$wpdb->users} uu ON pm1.meta_value = uu.ID";
530
+
 
 
531
  return $join;
532
  }
533
 
540
  */
541
  public function sortable_columns( $columns ) {
542
  $columns['order_student'] = 'student';
543
+ $columns['order_date'] = 'date';
544
+ $columns['order_total'] = 'order_total';
545
 
546
  return $columns;
547
  }
inc/custom-post-types/question.php CHANGED
@@ -18,7 +18,7 @@ if ( ! class_exists( 'LP_Question_Post_Type' ) ) {
18
  /**
19
  * Class LP_Question_Post_Type
20
  */
21
- class LP_Question_Post_Type extends LP_Abstract_Post_Type {
22
  /**
23
  * @var null
24
  */
@@ -62,6 +62,7 @@ if ( ! class_exists( 'LP_Question_Post_Type' ) ) {
62
  public function views_pages( $views ) {
63
  $unassigned_items = learn_press_get_unassigned_questions();
64
  $text = sprintf( __( 'Unassigned %s', 'learnpress' ), '<span class="count">(' . sizeof( $unassigned_items ) . ')</span>' );
 
65
  if ( 'yes' === LP_Request::get( 'unassigned' ) ) {
66
  $views['unassigned'] = sprintf(
67
  '<a href="%s" class="current">%s</a>',
@@ -395,7 +396,9 @@ if ( ! class_exists( 'LP_Question_Post_Type' ) ) {
395
  if ( ! $this->_is_archive() ) {
396
  return $join;
397
  }
 
398
  global $wpdb;
 
399
  if ( $quiz_id = $this->_filter_quiz() || ( $this->_get_orderby() == 'quiz-name' ) ) {
400
  $join .= " LEFT JOIN {$wpdb->prefix}learnpress_quiz_questions qq ON {$wpdb->posts}.ID = qq.question_id";
401
  $join .= " LEFT JOIN {$wpdb->posts} q ON q.ID = qq.quiz_id";
@@ -445,13 +448,15 @@ if ( ! class_exists( 'LP_Question_Post_Type' ) ) {
445
  * @return string
446
  */
447
  public function posts_orderby( $order_by_statement ) {
 
448
  if ( ! $this->_is_archive() ) {
449
  return $order_by_statement;
450
  }
451
- if ( isset ( $_GET['orderby'] ) && isset ( $_GET['order'] ) ) {
452
- switch ( $_GET['orderby'] ) {
 
453
  case 'quiz-name':
454
- $order_by_statement = "q.post_title {$_GET['order']}";
455
  break;
456
  }
457
  }
@@ -487,14 +492,7 @@ if ( ! class_exists( 'LP_Question_Post_Type' ) ) {
487
  * @return bool|int
488
  */
489
  private function _filter_quiz() {
490
- return ! empty( $_REQUEST['filter_quiz'] ) ? absint( $_REQUEST['filter_quiz'] ) : false;
491
- }
492
-
493
- /**
494
- * @return string
495
- */
496
- private function _get_orderby() {
497
- return isset( $_REQUEST['orderby'] ) ? $_REQUEST['orderby'] : '';
498
  }
499
 
500
  /**
18
  /**
19
  * Class LP_Question_Post_Type
20
  */
21
+ class LP_Question_Post_Type extends LP_Abstract_Post_Type_Core {
22
  /**
23
  * @var null
24
  */
62
  public function views_pages( $views ) {
63
  $unassigned_items = learn_press_get_unassigned_questions();
64
  $text = sprintf( __( 'Unassigned %s', 'learnpress' ), '<span class="count">(' . sizeof( $unassigned_items ) . ')</span>' );
65
+
66
  if ( 'yes' === LP_Request::get( 'unassigned' ) ) {
67
  $views['unassigned'] = sprintf(
68
  '<a href="%s" class="current">%s</a>',
396
  if ( ! $this->_is_archive() ) {
397
  return $join;
398
  }
399
+
400
  global $wpdb;
401
+
402
  if ( $quiz_id = $this->_filter_quiz() || ( $this->_get_orderby() == 'quiz-name' ) ) {
403
  $join .= " LEFT JOIN {$wpdb->prefix}learnpress_quiz_questions qq ON {$wpdb->posts}.ID = qq.question_id";
404
  $join .= " LEFT JOIN {$wpdb->posts} q ON q.ID = qq.quiz_id";
448
  * @return string
449
  */
450
  public function posts_orderby( $order_by_statement ) {
451
+
452
  if ( ! $this->_is_archive() ) {
453
  return $order_by_statement;
454
  }
455
+
456
+ if ( $orderby = $this->_get_orderby() && $order = $this->_get_order() ) {
457
+ switch ( $orderby ) {
458
  case 'quiz-name':
459
+ $order_by_statement = "q.post_title {$order}";
460
  break;
461
  }
462
  }
492
  * @return bool|int
493
  */
494
  private function _filter_quiz() {
495
+ return LP_Request::get_int( 'filter_quiz' );
 
 
 
 
 
 
 
496
  }
497
 
498
  /**
inc/custom-post-types/quiz.php CHANGED
@@ -17,7 +17,7 @@ if ( ! class_exists( 'LP_Quiz_Post_Type' ) ) {
17
  /**
18
  * Class LP_Quiz_Post_Type
19
  */
20
- final class LP_Quiz_Post_Type extends LP_Abstract_Post_Type {
21
 
22
  /**
23
  * @var null
@@ -397,7 +397,7 @@ if ( ! class_exists( 'LP_Quiz_Post_Type' ) ) {
397
  * Display content for custom column
398
  *
399
  * @param string $name
400
- * @param int $post_id
401
  */
402
  public function columns_content( $name, $post_id = 0 ) {
403
  global $post;
@@ -471,12 +471,6 @@ if ( ! class_exists( 'LP_Quiz_Post_Type' ) ) {
471
  if ( ! $this->_is_archive() ) {
472
  return $join;
473
  }
474
- global $wpdb;
475
- // if ( $this->_filter_course() || ( $this->_get_orderby() == 'course-name' ) || $this->_get_search() ) {
476
- // $join .= " LEFT JOIN {$wpdb->prefix}learnpress_section_items si ON {$wpdb->posts}.ID = si.item_id";
477
- // $join .= " LEFT JOIN {$wpdb->prefix}learnpress_sections s ON s.section_id = si.section_id";
478
- // $join .= " LEFT JOIN {$wpdb->posts} c ON c.ID = s.section_course_id";
479
- // }
480
 
481
  return $join;
482
  }
@@ -494,18 +488,6 @@ if ( ! class_exists( 'LP_Quiz_Post_Type' ) ) {
494
 
495
  global $wpdb;
496
 
497
- // if ( $course_id = $this->_filter_course() ) {
498
- // $where .= $wpdb->prepare( " AND (c.ID = %d)", $course_id );
499
- // }
500
-
501
- // if ( isset( $_GET['s'] ) ) {
502
- // $s = $_GET['s'];
503
- // $where = preg_replace(
504
- // "/\.post_content\s+LIKE\s*(\'[^\']+\')\s*\)/",
505
- // " .post_content LIKE '%$s%' ) OR (c.post_title LIKE '%$s%' )", $where
506
- // );
507
- // }
508
-
509
  if ( 'yes' === LP_Request::get( 'unassigned' ) ) {
510
  $where .= $wpdb->prepare( "
511
  AND {$wpdb->posts}.ID NOT IN(
@@ -527,20 +509,22 @@ if ( ! class_exists( 'LP_Quiz_Post_Type' ) ) {
527
  * @return string
528
  */
529
  public function posts_orderby( $order_by_statement ) {
 
 
530
  if ( ! $this->_is_archive() ) {
531
  return $order_by_statement;
532
  }
533
- global $wpdb;
534
- if ( isset ( $_GET['orderby'] ) && isset ( $_GET['order'] ) ) {
535
- switch ( $_GET['orderby'] ) {
536
  case 'course-name':
537
- $order_by_statement = "c.post_title {$_GET['order']}";
538
  break;
539
  case 'question-count':
540
- $order_by_statement = "question_count {$_GET['order']}";
541
  break;
542
  default:
543
- $order_by_statement = "{$wpdb->posts}.post_title {$_GET['order']}";
544
  }
545
  }
546
 
@@ -572,27 +556,6 @@ if ( ! class_exists( 'LP_Quiz_Post_Type' ) ) {
572
  return true;
573
  }
574
 
575
- /**
576
- * @return bool|int
577
- */
578
- private function _filter_course() {
579
- return ! empty( $_REQUEST['course'] ) ? absint( $_REQUEST['course'] ) : false;
580
- }
581
-
582
- /**
583
- * @return string
584
- */
585
- private function _get_orderby() {
586
- return isset( $_REQUEST['orderby'] ) ? $_REQUEST['orderby'] : '';
587
- }
588
-
589
- /**
590
- * @return bool
591
- */
592
- private function _get_search() {
593
- return isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : false;
594
- }
595
-
596
  /**
597
  * Hide View Quiz link if not assigned to Course.
598
  */
17
  /**
18
  * Class LP_Quiz_Post_Type
19
  */
20
+ final class LP_Quiz_Post_Type extends LP_Abstract_Post_Type_Core {
21
 
22
  /**
23
  * @var null
397
  * Display content for custom column
398
  *
399
  * @param string $name
400
+ * @param int $post_id
401
  */
402
  public function columns_content( $name, $post_id = 0 ) {
403
  global $post;
471
  if ( ! $this->_is_archive() ) {
472
  return $join;
473
  }
 
 
 
 
 
 
474
 
475
  return $join;
476
  }
488
 
489
  global $wpdb;
490
 
 
 
 
 
 
 
 
 
 
 
 
 
491
  if ( 'yes' === LP_Request::get( 'unassigned' ) ) {
492
  $where .= $wpdb->prepare( "
493
  AND {$wpdb->posts}.ID NOT IN(
509
  * @return string
510
  */
511
  public function posts_orderby( $order_by_statement ) {
512
+ global $wpdb;
513
+
514
  if ( ! $this->_is_archive() ) {
515
  return $order_by_statement;
516
  }
517
+
518
+ if ( $orderby = $this->_get_orderby() && $order = $this->_get_order() ) {
519
+ switch ( $orderby ) {
520
  case 'course-name':
521
+ $order_by_statement = "c.post_title {$order}";
522
  break;
523
  case 'question-count':
524
+ $order_by_statement = "question_count {$order}";
525
  break;
526
  default:
527
+ $order_by_statement = "{$wpdb->posts}.post_title {$order}";
528
  }
529
  }
530
 
556
  return true;
557
  }
558
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
559
  /**
560
  * Hide View Quiz link if not assigned to Course.
561
  */
inc/interfaces/interface-curd.php CHANGED
@@ -154,7 +154,7 @@ class LP_Object_Data_CURD {
154
  ", $object->get_id() );
155
  $meta_data = $wpdb->get_results( $query );
156
 
157
- wp_cache_set( $object->get_id(), $meta_data, 'object-meta' );
158
  }
159
 
160
  return $meta_data;
154
  ", $object->get_id() );
155
  $meta_data = $wpdb->get_results( $query );
156
 
157
+ LP_Object_Cache::set( $object->get_id(), $meta_data, 'object-meta' );
158
  }
159
 
160
  return $meta_data;
inc/lp-constants.php CHANGED
@@ -4,7 +4,7 @@
4
  */
5
  $upload_dir = wp_upload_dir();
6
  // version
7
- define( 'LEARNPRESS_VERSION', '3.0.12.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.1.0' );
8
 
9
  define( 'LP_WP_CONTENT', basename( WP_CONTENT_DIR ) );
10
 
inc/lp-core-functions.php CHANGED
@@ -499,7 +499,7 @@ function learn_press_get_post_by_name( $name, $type, $single = true ) {
499
  // Ensure that post name has to be sanitized. Fixed in 2.1.6
500
  $post_name = sanitize_title( $name );
501
 
502
- if ( false === ( $id = wp_cache_get( $type . '-' . $post_name, 'lp-post-names' ) ) ) {
503
 
504
  foreach ( array( $name, urldecode( $name ) ) as $_name ) {
505
  $args = array( 'name' => $_name, 'post_type' => array( $type ) );
@@ -508,7 +508,7 @@ function learn_press_get_post_by_name( $name, $type, $single = true ) {
508
  $post = $posts[0];
509
  $id = $post->ID;
510
  wp_cache_set( $id, $post, 'posts' );
511
- wp_cache_set( $type . '-' . $name, $id, 'lp-post-names' );
512
  break;
513
  }
514
  }
@@ -2879,7 +2879,7 @@ function learn_press_timezone_offset() {
2879
  */
2880
  function learn_press_static_page_ids() {
2881
 
2882
- if ( false === ( $pages = wp_cache_get( 'static-page-ids', 'learnpress' ) ) ) {
2883
  $pages = array(
2884
  'checkout' => learn_press_get_page_id( 'checkout' ),
2885
  'courses' => learn_press_get_page_id( 'courses' ),
@@ -2893,7 +2893,7 @@ function learn_press_static_page_ids() {
2893
  }
2894
  }
2895
 
2896
- wp_cache_set( 'static-page-ids', $pages, 'learnpress' );
2897
  }
2898
 
2899
  return apply_filters( 'learn-press/static-page-ids', $pages );
@@ -3038,7 +3038,7 @@ function learn_press_get_unassigned_items( $type = '' ) {
3038
  settype( $type, 'array' );
3039
  $key = 'items-' . md5( serialize( $type ) );
3040
 
3041
- if ( false === ( $items = wp_cache_get( $key, 'lp-unassigned' ) ) ) {
3042
  $format = array_fill( 0, sizeof( $type ), '%s' );
3043
 
3044
  $query = $wpdb->prepare( "
@@ -3055,7 +3055,7 @@ function learn_press_get_unassigned_items( $type = '' ) {
3055
  ", array_merge( $type, $type, array( 'auto-draft', 'trash' ) ) );
3056
 
3057
  $items = $wpdb->get_col( $query );
3058
- wp_cache_set( $key, $items, 'lp-unassigned' );
3059
  }
3060
 
3061
  return $items;
@@ -3071,7 +3071,7 @@ function learn_press_get_unassigned_items( $type = '' ) {
3071
  function learn_press_get_unassigned_questions() {
3072
  global $wpdb;
3073
 
3074
- if ( false === ( $questions = wp_cache_get( 'questions', 'lp-unassigned' ) ) ) {
3075
  $query = $wpdb->prepare( "
3076
  SELECT p.ID
3077
  FROM {$wpdb->posts} p
@@ -3086,7 +3086,7 @@ function learn_press_get_unassigned_questions() {
3086
  ", LP_QUESTION_CPT, LP_QUESTION_CPT, 'auto-draft', 'trash' );
3087
 
3088
  $questions = $wpdb->get_col( $query );
3089
- wp_cache_set( 'questions', $questions, 'lp-unassigned' );
3090
  }
3091
 
3092
  return $questions;
499
  // Ensure that post name has to be sanitized. Fixed in 2.1.6
500
  $post_name = sanitize_title( $name );
501
 
502
+ if ( false === ( $id = LP_Object_Cache::get( $type . '-' . $post_name, 'lp-post-names' ) ) ) {
503
 
504
  foreach ( array( $name, urldecode( $name ) ) as $_name ) {
505
  $args = array( 'name' => $_name, 'post_type' => array( $type ) );
508
  $post = $posts[0];
509
  $id = $post->ID;
510
  wp_cache_set( $id, $post, 'posts' );
511
+ LP_Object_Cache::set( $type . '-' . $name, $id, 'lp-post-names' );
512
  break;
513
  }
514
  }
2879
  */
2880
  function learn_press_static_page_ids() {
2881
 
2882
+ if ( false === ( $pages = LP_Object_Cache::get( 'static-page-ids', 'learnpress' ) ) ) {
2883
  $pages = array(
2884
  'checkout' => learn_press_get_page_id( 'checkout' ),
2885
  'courses' => learn_press_get_page_id( 'courses' ),
2893
  }
2894
  }
2895
 
2896
+ LP_Object_Cache::set( 'static-page-ids', $pages, 'learnpress' );
2897
  }
2898
 
2899
  return apply_filters( 'learn-press/static-page-ids', $pages );
3038
  settype( $type, 'array' );
3039
  $key = 'items-' . md5( serialize( $type ) );
3040
 
3041
+ if ( false === ( $items = LP_Object_Cache::get( $key, 'lp-unassigned' ) ) ) {
3042
  $format = array_fill( 0, sizeof( $type ), '%s' );
3043
 
3044
  $query = $wpdb->prepare( "
3055
  ", array_merge( $type, $type, array( 'auto-draft', 'trash' ) ) );
3056
 
3057
  $items = $wpdb->get_col( $query );
3058
+ LP_Object_Cache::set( $key, $items, 'lp-unassigned' );
3059
  }
3060
 
3061
  return $items;
3071
  function learn_press_get_unassigned_questions() {
3072
  global $wpdb;
3073
 
3074
+ if ( false === ( $questions = LP_Object_Cache::get( 'questions', 'lp-unassigned' ) ) ) {
3075
  $query = $wpdb->prepare( "
3076
  SELECT p.ID
3077
  FROM {$wpdb->posts} p
3086
  ", LP_QUESTION_CPT, LP_QUESTION_CPT, 'auto-draft', 'trash' );
3087
 
3088
  $questions = $wpdb->get_col( $query );
3089
+ LP_Object_Cache::set( 'questions', $questions, 'lp-unassigned' );
3090
  }
3091
 
3092
  return $questions;
inc/order/class-lp-order.php CHANGED
@@ -522,7 +522,7 @@ if ( ! class_exists( 'LP_Order' ) ) {
522
  * @return mixed
523
  */
524
  public function get_items() {
525
- return apply_filters( 'learn-press/order-items', wp_cache_get( 'order-' . $this->get_id(), 'lp-order-items' ) );
526
  }
527
 
528
  public function is_child() {
522
  * @return mixed
523
  */
524
  public function get_items() {
525
+ return apply_filters( 'learn-press/order-items', LP_Object_Cache::get( 'order-' . $this->get_id(), 'lp-order-items' ) );
526
  }
527
 
528
  public function is_child() {
inc/question/class-lp-question.php CHANGED
@@ -609,7 +609,7 @@ if ( ! class_exists( 'LP_Question' ) ) {
609
  */
610
  public function get_answers( $field = null, $exclude = null ) {
611
  $answers = array();
612
- if ( false === ( $data_answers = wp_cache_get( 'answer-options-' . $this->get_id(), 'lp-questions' ) ) ) {
613
  $data_answers = $this->get_default_answers();
614
  };
615
 
@@ -1022,13 +1022,13 @@ if ( ! class_exists( 'LP_Question' ) ) {
1022
  protected function _get_checked( $user_answer = null ) {
1023
  $key = $user_answer ? md5( serialize( $user_answer ) ) : - 1;
1024
 
1025
- return wp_cache_get( 'question-' . $this->get_id() . '/' . $key, 'lp-answer-checked' );
1026
  }
1027
 
1028
  protected function _set_checked( $checked, $user_answer ) {
1029
  $key = $user_answer ? md5( serialize( $user_answer ) ) : - 1;
1030
 
1031
- return wp_cache_set( 'question-' . $this->get_id() . '/' . $key, $checked, 'lp-answer-checked' );
1032
  }
1033
  }
1034
 
609
  */
610
  public function get_answers( $field = null, $exclude = null ) {
611
  $answers = array();
612
+ if ( false === ( $data_answers = LP_Object_Cache::get( 'answer-options-' . $this->get_id(), 'lp-questions' ) ) ) {
613
  $data_answers = $this->get_default_answers();
614
  };
615
 
1022
  protected function _get_checked( $user_answer = null ) {
1023
  $key = $user_answer ? md5( serialize( $user_answer ) ) : - 1;
1024
 
1025
+ return LP_Object_Cache::get( 'question-' . $this->get_id() . '/' . $key, 'lp-answer-checked' );
1026
  }
1027
 
1028
  protected function _set_checked( $checked, $user_answer ) {
1029
  $key = $user_answer ? md5( serialize( $user_answer ) ) : - 1;
1030
 
1031
+ return LP_Object_Cache::set( 'question-' . $this->get_id() . '/' . $key, $checked, 'lp-answer-checked' );
1032
  }
1033
  }
1034
 
inc/quiz/class-lp-quiz-factory.php CHANGED
@@ -105,9 +105,9 @@ if ( ! class_exists( 'LP_Quiz_Factory' ) ) {
105
 
106
  /**
107
  * @param bool $true
108
- * @param int $quiz_id
109
- * @param int $course_id
110
- * @param int $user_id
111
  *
112
  * @return bool
113
  */
@@ -160,7 +160,8 @@ if ( ! class_exists( 'LP_Quiz_Factory' ) ) {
160
  $result['result'] = 'success';
161
  $result['redirect'] = apply_filters( 'learn-press/quiz/started-redirect', $redirect, $quiz_id, $course_id, $user->get_id() );
162
  }
163
- } catch ( Exception $ex ) {
 
164
  $result['message'] = $ex->getMessage();
165
  $result['result'] = 'failure';
166
  $result['redirect'] = apply_filters( 'learn-press/quiz/start-quiz-failure-redirect', learn_press_get_current_url(), $quiz_id, $course_id, $user->get_id() );
@@ -226,7 +227,8 @@ if ( ! class_exists( 'LP_Quiz_Factory' ) ) {
226
  $result['html'] = learn_press_get_template_content( 'content-question/content.php' );// $question->get_html( $quiz_data->get_question_answer( $question_id ) );
227
  }
228
  }
229
- } catch ( Exception $ex ) {
 
230
  $result['message'] = $ex->getMessage();
231
  $result['code'] = $ex->getCode();
232
  }
@@ -284,7 +286,8 @@ if ( ! class_exists( 'LP_Quiz_Factory' ) ) {
284
 
285
  }
286
  }
287
- } catch ( Exception $ex ) {
 
288
  $result['message'] = $ex->getMessage();
289
  $result['code'] = $ex->getCode();
290
  }
@@ -341,7 +344,8 @@ if ( ! class_exists( 'LP_Quiz_Factory' ) ) {
341
  $result['data'] = $data;
342
  }
343
  }
344
- } catch ( Exception $ex ) {
 
345
  $result['message'] = $ex->getMessage();
346
  $result['code'] = $ex->getCode();
347
  }
@@ -397,7 +401,8 @@ if ( ! class_exists( 'LP_Quiz_Factory' ) ) {
397
  $result['redirect'] = apply_filters( 'learn-press/quiz/retaken-redirect', $redirect, $quiz_id, $course_id, $user->get_id() );
398
  $result['data'] = $data;
399
  }
400
- } catch ( Exception $ex ) {
 
401
  $result['message'] = $ex->getMessage();
402
  $result['code'] = $ex->getCode();
403
  $result['result'] = 'failure';
@@ -487,6 +492,10 @@ if ( ! class_exists( 'LP_Quiz_Factory' ) ) {
487
  $course_data = $user->get_course_data( $course->get_id() );
488
  $quiz_data = $course_data->get_item_quiz( $quiz->get_id() );
489
 
 
 
 
 
490
  // If user click 'Skip' button
491
  if ( $nav_type === 'skip-question' ) {
492
  if ( $quiz_data->get_question_answer( $question_id ) == '' ) {
@@ -503,7 +512,8 @@ if ( ! class_exists( 'LP_Quiz_Factory' ) ) {
503
  $quiz_data->add_question_answer( $questions );
504
  $quiz_data->update();
505
 
506
- } catch ( Exception $ex ) {
 
507
  return $ex;
508
  }
509
 
@@ -556,7 +566,8 @@ if ( ! class_exists( 'LP_Quiz_Factory' ) ) {
556
 
557
  $questions = self::_get_answer( $data );
558
  }
559
- } catch ( Exception $ex ) {
 
560
  }
561
 
562
  return $question_id ? ( array_key_exists( $question_id, $questions ) ? $questions[ $question_id ] : false ) : $questions;
105
 
106
  /**
107
  * @param bool $true
108
+ * @param int $quiz_id
109
+ * @param int $course_id
110
+ * @param int $user_id
111
  *
112
  * @return bool
113
  */
160
  $result['result'] = 'success';
161
  $result['redirect'] = apply_filters( 'learn-press/quiz/started-redirect', $redirect, $quiz_id, $course_id, $user->get_id() );
162
  }
163
+ }
164
+ catch ( Exception $ex ) {
165
  $result['message'] = $ex->getMessage();
166
  $result['result'] = 'failure';
167
  $result['redirect'] = apply_filters( 'learn-press/quiz/start-quiz-failure-redirect', learn_press_get_current_url(), $quiz_id, $course_id, $user->get_id() );
227
  $result['html'] = learn_press_get_template_content( 'content-question/content.php' );// $question->get_html( $quiz_data->get_question_answer( $question_id ) );
228
  }
229
  }
230
+ }
231
+ catch ( Exception $ex ) {
232
  $result['message'] = $ex->getMessage();
233
  $result['code'] = $ex->getCode();
234
  }
286
 
287
  }
288
  }
289
+ }
290
+ catch ( Exception $ex ) {
291
  $result['message'] = $ex->getMessage();
292
  $result['code'] = $ex->getCode();
293
  }
344
  $result['data'] = $data;
345
  }
346
  }
347
+ }
348
+ catch ( Exception $ex ) {
349
  $result['message'] = $ex->getMessage();
350
  $result['code'] = $ex->getCode();
351
  }
401
  $result['redirect'] = apply_filters( 'learn-press/quiz/retaken-redirect', $redirect, $quiz_id, $course_id, $user->get_id() );
402
  $result['data'] = $data;
403
  }
404
+ }
405
+ catch ( Exception $ex ) {
406
  $result['message'] = $ex->getMessage();
407
  $result['code'] = $ex->getCode();
408
  $result['result'] = 'failure';
492
  $course_data = $user->get_course_data( $course->get_id() );
493
  $quiz_data = $course_data->get_item_quiz( $quiz->get_id() );
494
 
495
+ if ( $course_data->is_finished() || $quiz_data->is_completed() ) {
496
+ return true;
497
+ }
498
+
499
  // If user click 'Skip' button
500
  if ( $nav_type === 'skip-question' ) {
501
  if ( $quiz_data->get_question_answer( $question_id ) == '' ) {
512
  $quiz_data->add_question_answer( $questions );
513
  $quiz_data->update();
514
 
515
+ }
516
+ catch ( Exception $ex ) {
517
  return $ex;
518
  }
519
 
566
 
567
  $questions = self::_get_answer( $data );
568
  }
569
+ }
570
+ catch ( Exception $ex ) {
571
  }
572
 
573
  return $question_id ? ( array_key_exists( $question_id, $questions ) ? $questions[ $question_id ] : false ) : $questions;
inc/user-item/class-lp-user-item-course.php CHANGED
@@ -72,7 +72,7 @@ class LP_User_Item_Course extends LP_User_Item implements ArrayAccess {
72
  foreach ( $course_items as $item_id ) {
73
 
74
  $cache_name = sprintf( 'course-item-%s-%s-%s', $this->get_user_id(), $this->get_id(), $item_id );
75
- if ( false !== ( $data = wp_cache_get( $cache_name, 'lp-user-course-items' ) ) ) {
76
  $data = reset( $data );
77
  } else {
78
  $data = wp_parse_args(
@@ -274,7 +274,7 @@ class LP_User_Item_Course extends LP_User_Item implements ArrayAccess {
274
  }
275
  }
276
 
277
- ///$result = wp_cache_get( 'user-course-' . $this->get_user_id() . '-' . $this->get_id(), 'lp-user-course-results' );
278
 
279
  return $prop && $results && array_key_exists( $prop, $results ) ? $results[ $prop ] : $results;
280
  }
@@ -315,7 +315,7 @@ class LP_User_Item_Course extends LP_User_Item implements ArrayAccess {
315
 
316
  $cache_key = 'user-course-' . $this->get_user_id() . '-' . $this->get_id();
317
 
318
- if ( false === ( $cached_data = wp_cache_get( $cache_key, 'course-results' ) ) || ! array_key_exists( 'lessons', $cached_data ) ) {
319
  $completing = $this->get_completed_items( LP_LESSON_CPT, true );
320
  if ( $completing[1] ) {
321
  $result = $completing[0] / $completing[1];
@@ -332,7 +332,7 @@ class LP_User_Item_Course extends LP_User_Item implements ArrayAccess {
332
  settype( $cached_data, 'array' );
333
  $cached_data['lessons'] = $data;
334
 
335
- wp_cache_set( $cache_key, $cached_data, 'course-results' );
336
  }
337
 
338
  return isset( $cached_data['lessons'] ) ? $cached_data['lessons'] : array();
@@ -359,7 +359,7 @@ class LP_User_Item_Course extends LP_User_Item implements ArrayAccess {
359
 
360
  $cache_key = 'user-course-' . $this->get_user_id() . '-' . $this->get_id();
361
 
362
- if ( false === ( $cached_data = wp_cache_get( $cache_key, 'course-results' ) ) || ! array_key_exists( 'final-quiz', $cached_data ) ) {
363
  $course = $this->get_course();
364
  $final_quiz = $course->get_final_quiz();
365
  $result = false;
@@ -376,7 +376,7 @@ class LP_User_Item_Course extends LP_User_Item implements ArrayAccess {
376
  settype( $cached_data, 'array' );
377
  $cached_data['final-quiz'] = $data;
378
 
379
- wp_cache_set( $cache_key, $cached_data, 'course-results' );
380
  }
381
 
382
  return isset( $cached_data['final-quiz'] ) ? $cached_data['final-quiz'] : array();
@@ -391,7 +391,7 @@ class LP_User_Item_Course extends LP_User_Item implements ArrayAccess {
391
 
392
  $cache_key = 'user-course-' . $this->get_user_id() . '-' . $this->get_id();
393
 
394
- if ( ( false === ( $cached_data = wp_cache_get( $cache_key, 'course-results' ) ) ) || ! array_key_exists( 'quizzes', $cached_data ) ) {
395
 
396
  $data = array( 'result' => 0, 'grade' => '', 'status' => $this->get_status() );
397
  $result = 0;
@@ -417,7 +417,7 @@ class LP_User_Item_Course extends LP_User_Item implements ArrayAccess {
417
  settype( $cached_data, 'array' );
418
  $cached_data['quizzes'] = $data;
419
 
420
- wp_cache_set( $cache_key, $cached_data, 'course-results' );
421
  }
422
 
423
  return isset( $cached_data['quizzes'] ) ? $cached_data['quizzes'] : array();
@@ -432,7 +432,7 @@ class LP_User_Item_Course extends LP_User_Item implements ArrayAccess {
432
 
433
  $cache_key = 'user-course-' . $this->get_user_id() . '-' . $this->get_id();
434
 
435
- if ( false === ( $cached_data = wp_cache_get( $cache_key, 'course-results' ) ) || ! array_key_exists( 'passed-quizzes', $cached_data ) ) {
436
 
437
  $data = array( 'result' => 0, 'grade' => '', 'status' => $this->get_status() );
438
  $result = 0;
@@ -458,7 +458,7 @@ class LP_User_Item_Course extends LP_User_Item implements ArrayAccess {
458
  settype( $cached_data, 'array' );
459
  $cached_data['passed-quizzes'] = $data;
460
 
461
- wp_cache_set( $cache_key, $cached_data, 'course-results' );
462
  }
463
 
464
  return isset( $cached_data['passed-quizzes'] ) ? $cached_data['passed-quizzes'] : array();
@@ -472,7 +472,7 @@ class LP_User_Item_Course extends LP_User_Item implements ArrayAccess {
472
  protected function _evaluate_course_by_completed_quizzes() {
473
  $cache_key = 'user-course-' . $this->get_user_id() . '-' . $this->get_id();
474
 
475
- if ( false === ( $cached_data = wp_cache_get( $cache_key, 'course-results' ) ) || ! array_key_exists( 'completed-quizzes', $cached_data ) ) {
476
  $course = $this->get_course();
477
 
478
  $data = array( 'result' => 0, 'grade' => '', 'status' => $this->get_status() );
@@ -499,7 +499,7 @@ class LP_User_Item_Course extends LP_User_Item implements ArrayAccess {
499
  settype( $cached_data, 'array' );
500
  $cached_data['completed-quizzes'] = $data;
501
 
502
- wp_cache_set( $cache_key, $cached_data, 'course-results' );
503
  }
504
 
505
  return isset( $cached_data['completed-quizzes'] ) ? $cached_data['completed-quizzes'] : array();
@@ -523,7 +523,7 @@ class LP_User_Item_Course extends LP_User_Item implements ArrayAccess {
523
  public function get_completed_items( $type = '', $with_total = false, $section_id = 0 ) {
524
  $key = sprintf( '%d-%d-%s', $this->get_user_id(), $this->_course->get_id(), md5( build_query( func_get_args() ) ) );
525
 
526
- if ( false === ( $completed_items = wp_cache_get( $key, 'lp-user-completed-items' ) ) ) {
527
  $completed = 0;
528
  $total = 0;
529
  $section_items = array();
@@ -561,7 +561,7 @@ class LP_User_Item_Course extends LP_User_Item implements ArrayAccess {
561
  }
562
  }
563
  $completed_items = array( $completed, $total );
564
- wp_cache_set( $key, $completed_items, 'lp-user-completed-items' );
565
  }
566
 
567
  return $with_total ? $completed_items : $completed_items[0];
72
  foreach ( $course_items as $item_id ) {
73
 
74
  $cache_name = sprintf( 'course-item-%s-%s-%s', $this->get_user_id(), $this->get_id(), $item_id );
75
+ if ( false !== ( $data = LP_Object_Cache::get( $cache_name, 'lp-user-course-items' ) ) ) {
76
  $data = reset( $data );
77
  } else {
78
  $data = wp_parse_args(
274
  }
275
  }
276
 
277
+ ///$result = LP_Object_Cache::get( 'user-course-' . $this->get_user_id() . '-' . $this->get_id(), 'lp-user-course-results' );
278
 
279
  return $prop && $results && array_key_exists( $prop, $results ) ? $results[ $prop ] : $results;
280
  }
315
 
316
  $cache_key = 'user-course-' . $this->get_user_id() . '-' . $this->get_id();
317
 
318
+ if ( false === ( $cached_data = LP_Object_Cache::get( $cache_key, 'course-results' ) ) || ! array_key_exists( 'lessons', $cached_data ) ) {
319
  $completing = $this->get_completed_items( LP_LESSON_CPT, true );
320
  if ( $completing[1] ) {
321
  $result = $completing[0] / $completing[1];
332
  settype( $cached_data, 'array' );
333
  $cached_data['lessons'] = $data;
334
 
335
+ LP_Object_Cache::set( $cache_key, $cached_data, 'course-results' );
336
  }
337
 
338
  return isset( $cached_data['lessons'] ) ? $cached_data['lessons'] : array();
359
 
360
  $cache_key = 'user-course-' . $this->get_user_id() . '-' . $this->get_id();
361
 
362
+ if ( false === ( $cached_data = LP_Object_Cache::get( $cache_key, 'course-results' ) ) || ! array_key_exists( 'final-quiz', $cached_data ) ) {
363
  $course = $this->get_course();
364
  $final_quiz = $course->get_final_quiz();
365
  $result = false;
376
  settype( $cached_data, 'array' );
377
  $cached_data['final-quiz'] = $data;
378
 
379
+ LP_Object_Cache::set( $cache_key, $cached_data, 'course-results' );
380
  }
381
 
382
  return isset( $cached_data['final-quiz'] ) ? $cached_data['final-quiz'] : array();
391
 
392
  $cache_key = 'user-course-' . $this->get_user_id() . '-' . $this->get_id();
393
 
394
+ if ( ( false === ( $cached_data = LP_Object_Cache::get( $cache_key, 'course-results' ) ) ) || ! array_key_exists( 'quizzes', $cached_data ) ) {
395
 
396
  $data = array( 'result' => 0, 'grade' => '', 'status' => $this->get_status() );
397
  $result = 0;
417
  settype( $cached_data, 'array' );
418
  $cached_data['quizzes'] = $data;
419
 
420
+ LP_Object_Cache::set( $cache_key, $cached_data, 'course-results' );
421
  }
422
 
423
  return isset( $cached_data['quizzes'] ) ? $cached_data['quizzes'] : array();
432
 
433
  $cache_key = 'user-course-' . $this->get_user_id() . '-' . $this->get_id();
434
 
435
+ if ( false === ( $cached_data = LP_Object_Cache::get( $cache_key, 'course-results' ) ) || ! array_key_exists( 'passed-quizzes', $cached_data ) ) {
436
 
437
  $data = array( 'result' => 0, 'grade' => '', 'status' => $this->get_status() );
438
  $result = 0;
458
  settype( $cached_data, 'array' );
459
  $cached_data['passed-quizzes'] = $data;
460
 
461
+ LP_Object_Cache::set( $cache_key, $cached_data, 'course-results' );
462
  }
463
 
464
  return isset( $cached_data['passed-quizzes'] ) ? $cached_data['passed-quizzes'] : array();
472
  protected function _evaluate_course_by_completed_quizzes() {
473
  $cache_key = 'user-course-' . $this->get_user_id() . '-' . $this->get_id();
474
 
475
+ if ( false === ( $cached_data = LP_Object_Cache::get( $cache_key, 'course-results' ) ) || ! array_key_exists( 'completed-quizzes', $cached_data ) ) {
476
  $course = $this->get_course();
477
 
478
  $data = array( 'result' => 0, 'grade' => '', 'status' => $this->get_status() );
499
  settype( $cached_data, 'array' );
500
  $cached_data['completed-quizzes'] = $data;
501
 
502
+ LP_Object_Cache::set( $cache_key, $cached_data, 'course-results' );
503
  }
504
 
505
  return isset( $cached_data['completed-quizzes'] ) ? $cached_data['completed-quizzes'] : array();
523
  public function get_completed_items( $type = '', $with_total = false, $section_id = 0 ) {
524
  $key = sprintf( '%d-%d-%s', $this->get_user_id(), $this->_course->get_id(), md5( build_query( func_get_args() ) ) );
525
 
526
+ if ( false === ( $completed_items = LP_Object_Cache::get( $key, 'lp-user-completed-items' ) ) ) {
527
  $completed = 0;
528
  $total = 0;
529
  $section_items = array();
561
  }
562
  }
563
  $completed_items = array( $completed, $total );
564
+ LP_Object_Cache::set( $key, $completed_items, 'lp-user-completed-items' );
565
  }
566
 
567
  return $with_total ? $completed_items : $completed_items[0];
inc/user-item/class-lp-user-item-quiz.php CHANGED
@@ -121,7 +121,7 @@ class LP_User_Item_Quiz extends LP_User_Item {
121
  public function get_results( $prop = 'result', $force = false ) {
122
  $quiz = learn_press_get_quiz( $this->get_item_id() );
123
  $cache_key = sprintf( 'quiz-%d-%d-%d', $this->get_user_id(), $this->get_course_id(), $this->get_item_id() );
124
- if ( false === ( $result = wp_cache_get( $cache_key, 'lp-quiz-result' ) ) || $force ) {
125
  $result = array(
126
  'questions' => array(),
127
  'mark' => $quiz->get_mark(),
@@ -183,7 +183,7 @@ class LP_User_Item_Quiz extends LP_User_Item {
183
  learn_press_update_user_item_meta( $this->get_user_item_id(), 'grade', $result['grade'] );
184
  }
185
  }
186
- wp_cache_set( $cache_key, $result, 'lp-quiz-result' );
187
  }
188
 
189
  return $prop && $result && array_key_exists( $prop, $result ) ? $result[ $prop ] : $result;
121
  public function get_results( $prop = 'result', $force = false ) {
122
  $quiz = learn_press_get_quiz( $this->get_item_id() );
123
  $cache_key = sprintf( 'quiz-%d-%d-%d', $this->get_user_id(), $this->get_course_id(), $this->get_item_id() );
124
+ if ( false === ( $result = LP_Object_Cache::get( $cache_key, 'lp-quiz-result' ) ) || $force ) {
125
  $result = array(
126
  'questions' => array(),
127
  'mark' => $quiz->get_mark(),
183
  learn_press_update_user_item_meta( $this->get_user_item_id(), 'grade', $result['grade'] );
184
  }
185
  }
186
+ LP_Object_Cache::set( $cache_key, $result, 'lp-quiz-result' );
187
  }
188
 
189
  return $prop && $result && array_key_exists( $prop, $result ) ? $result[ $prop ] : $result;
inc/user-item/class-lp-user-item.php CHANGED
@@ -356,7 +356,7 @@ class LP_User_Item extends LP_Abstract_Object_Data {
356
  }
357
 
358
  public function get_history() {
359
- return wp_cache_get( sprintf( 'course-item-%s-%s-%s', $this->get_user_id(), $this->get_course( 'id' ), $this->get_id() ), 'lp-user-course-items' );
360
  }
361
 
362
  public function count_history() {
356
  }
357
 
358
  public function get_history() {
359
+ return LP_Object_Cache::get( sprintf( 'course-item-%s-%s-%s', $this->get_user_id(), $this->get_course( 'id' ), $this->get_id() ), 'lp-user-course-items' );
360
  }
361
 
362
  public function count_history() {
inc/user/abstract-lp-user.php CHANGED
@@ -164,15 +164,15 @@ if ( ! class_exists( 'LP_Abstract_User' ) ) {
164
  * @BUG: Cache enable => Not store all user answer of quiz, only store the last use answer for question
165
  * @TODO: need improve this proccess
166
  */
167
- if ( false === ( $object_course_data = wp_cache_get( 'course-' . $this->get_id() . '-' . $course_id, 'lp-user-course-data' ) ) ) {
168
  $this->_curd->read_course( $this->get_id(), $course_id );
169
- if ( false !== ( $course_item = wp_cache_get( 'course-' . $this->get_id() . '-' . $course_id, 'lp-user-courses' ) ) ) {
170
  $object_course_data = new LP_User_Item_Course( $course_item );
171
  } else {
172
  $object_course_data = new LP_User_Item_Course( $course_id );
173
  }
174
 
175
- wp_cache_set( 'course-' . $this->get_id() . '-' . $course_id, $object_course_data, 'lp-user-course-data' );
176
  }
177
 
178
  if ( $object_course_data ) {
@@ -334,7 +334,7 @@ if ( ! class_exists( 'LP_Abstract_User' ) ) {
334
  * @return bool|mixed
335
  */
336
  public function get_item_archive( $item_id, $course_id = 0, $return_last = false ) {
337
- $records = wp_cache_get( 'course-item-' . $this->get_id() . '-' . $course_id . '-' . $item_id, 'lp-user-course-items' );
338
 
339
  if ( $records ) {
340
  ///$records = array_filter( $records );
@@ -688,7 +688,7 @@ if ( ! class_exists( 'LP_Abstract_User' ) ) {
688
  $course_id = get_the_ID();
689
  }
690
  $item = false;
691
- if ( false !== ( $items = wp_cache_get( 'course-item-' . $this->get_id() . '-' . $course_id . '-' . $item_id, 'lp-user-course-items' ) ) ) {
692
  // Only get status of a newest record.
693
  if ( $last ) {
694
  $item = reset( $items );
@@ -832,7 +832,7 @@ if ( ! class_exists( 'LP_Abstract_User' ) ) {
832
 
833
  $cache_name = sprintf( 'course-item-%d-%d-%d', $this->get_id(), $course_id, $item_id );
834
 
835
- wp_cache_set( $cache_name, $items, 'lp-user-course-items' );
836
 
837
  do_action( 'learn-press/set-viewing-item', $item_id, $course_id, $items[ $user_item_id ] );
838
 
@@ -1168,7 +1168,7 @@ if ( ! class_exists( 'LP_Abstract_User' ) ) {
1168
  $key = $this->get_id() . '-' . $course_id . '-' . $quiz_id;
1169
 
1170
 
1171
- $cached = LP_Cache::get_quiz_history( false, array() );// wp_cache_get( 'user-quiz-history', 'learnpress' );
1172
 
1173
  if ( ( ! array_key_exists( $key, $cached ) || $force ) && $quizzes && in_array( $quiz_id, $quizzes ) ) {
1174
  global $wpdb;
@@ -1847,7 +1847,7 @@ if ( ! class_exists( 'LP_Abstract_User' ) ) {
1847
  public function get_orders( $last_order = true ) {
1848
 
1849
  if ( $last_order ) {
1850
- if ( false !== ( $cached_last_order = wp_cache_get( 'user-' . $this->get_id(), 'lp-user-last-order' ) ) ) {
1851
  return $cached_last_order;
1852
  }
1853
  }
@@ -1859,7 +1859,7 @@ if ( ! class_exists( 'LP_Abstract_User' ) ) {
1859
  foreach ( $my_orders as $course_id => $orders ) {
1860
  $last_orders[ $course_id ] = reset( $orders );
1861
  }
1862
- wp_cache_set( 'user-' . $this->get_id(), $last_orders, 'lp-user-last-order' );
1863
  } else {
1864
  $last_orders = $my_orders;
1865
  }
@@ -1880,7 +1880,7 @@ if ( ! class_exists( 'LP_Abstract_User' ) ) {
1880
  $enrolled = 'no';
1881
  $cache_key = 'course-' . $this->get_id() . '-' . $course_id;
1882
 
1883
- if ( false === ( $enrolled = wp_cache_get( $cache_key, 'enrolled-courses' ) ) ) {
1884
  // No new order is pending and has already enrolled or finished course
1885
  if ( 'lp-pending' !== $this->get_order_status( $course_id ) ) {
1886
  $enrolled = $this->has_course_status( $course_id, array(
@@ -1888,7 +1888,7 @@ if ( ! class_exists( 'LP_Abstract_User' ) ) {
1888
  'finished'
1889
  ) ) ? 'yes' : 'no';
1890
  }
1891
- wp_cache_set( $cache_key, $enrolled, 'enrolled-courses' );
1892
  }
1893
 
1894
  $enrolled = $enrolled === 'yes' ? true : false;
@@ -1993,7 +1993,7 @@ if ( ! class_exists( 'LP_Abstract_User' ) ) {
1993
 
1994
  global $wpdb;
1995
  //$key_format = '%d-%d';
1996
- $cached = (array) wp_cache_get( 'user-quiz-statuses', 'learnpress' );
1997
  if ( ! array_key_exists( $this->get_id() . '-' . $course_id . '-' . $quiz_id, $cached ) || $force ) {
1998
  $query = $wpdb->prepare( "
1999
  SELECT uq.item_id as id, uqm.meta_value as `status`
@@ -2293,7 +2293,7 @@ if ( ! class_exists( 'LP_Abstract_User' ) ) {
2293
  public function get_course_status( $course_id ) {
2294
 
2295
  $status = false;
2296
- if ( false !== ( $data = wp_cache_get( 'course-' . $this->get_id() . '-' . $course_id, 'lp-user-courses' ) ) ) {
2297
  $status = $data['status'];
2298
  } else {
2299
  $course_data = $this->get_course_data( $course_id );
164
  * @BUG: Cache enable => Not store all user answer of quiz, only store the last use answer for question
165
  * @TODO: need improve this proccess
166
  */
167
+ if ( false === ( $object_course_data = LP_Object_Cache::get( 'course-' . $this->get_id() . '-' . $course_id, 'lp-user-course-data' ) ) ) {
168
  $this->_curd->read_course( $this->get_id(), $course_id );
169
+ if ( false !== ( $course_item = LP_Object_Cache::get( 'course-' . $this->get_id() . '-' . $course_id, 'lp-user-courses' ) ) ) {
170
  $object_course_data = new LP_User_Item_Course( $course_item );
171
  } else {
172
  $object_course_data = new LP_User_Item_Course( $course_id );
173
  }
174
 
175
+ LP_Object_Cache::set( 'course-' . $this->get_id() . '-' . $course_id, $object_course_data, 'lp-user-course-data' );
176
  }
177
 
178
  if ( $object_course_data ) {
334
  * @return bool|mixed
335
  */
336
  public function get_item_archive( $item_id, $course_id = 0, $return_last = false ) {
337
+ $records = LP_Object_Cache::get( 'course-item-' . $this->get_id() . '-' . $course_id . '-' . $item_id, 'lp-user-course-items' );
338
 
339
  if ( $records ) {
340
  ///$records = array_filter( $records );
688
  $course_id = get_the_ID();
689
  }
690
  $item = false;
691
+ if ( false !== ( $items = LP_Object_Cache::get( 'course-item-' . $this->get_id() . '-' . $course_id . '-' . $item_id, 'lp-user-course-items' ) ) ) {
692
  // Only get status of a newest record.
693
  if ( $last ) {
694
  $item = reset( $items );
832
 
833
  $cache_name = sprintf( 'course-item-%d-%d-%d', $this->get_id(), $course_id, $item_id );
834
 
835
+ LP_Object_Cache::set( $cache_name, $items, 'lp-user-course-items' );
836
 
837
  do_action( 'learn-press/set-viewing-item', $item_id, $course_id, $items[ $user_item_id ] );
838
 
1168
  $key = $this->get_id() . '-' . $course_id . '-' . $quiz_id;
1169
 
1170
 
1171
+ $cached = LP_Cache::get_quiz_history( false, array() );// LP_Object_Cache::get( 'user-quiz-history', 'learnpress' );
1172
 
1173
  if ( ( ! array_key_exists( $key, $cached ) || $force ) && $quizzes && in_array( $quiz_id, $quizzes ) ) {
1174
  global $wpdb;
1847
  public function get_orders( $last_order = true ) {
1848
 
1849
  if ( $last_order ) {
1850
+ if ( false !== ( $cached_last_order = LP_Object_Cache::get( 'user-' . $this->get_id(), 'lp-user-last-order' ) ) ) {
1851
  return $cached_last_order;
1852
  }
1853
  }
1859
  foreach ( $my_orders as $course_id => $orders ) {
1860
  $last_orders[ $course_id ] = reset( $orders );
1861
  }
1862
+ LP_Object_Cache::set( 'user-' . $this->get_id(), $last_orders, 'lp-user-last-order' );
1863
  } else {
1864
  $last_orders = $my_orders;
1865
  }
1880
  $enrolled = 'no';
1881
  $cache_key = 'course-' . $this->get_id() . '-' . $course_id;
1882
 
1883
+ if ( false === ( $enrolled = LP_Object_Cache::get( $cache_key, 'enrolled-courses' ) ) ) {
1884
  // No new order is pending and has already enrolled or finished course
1885
  if ( 'lp-pending' !== $this->get_order_status( $course_id ) ) {
1886
  $enrolled = $this->has_course_status( $course_id, array(
1888
  'finished'
1889
  ) ) ? 'yes' : 'no';
1890
  }
1891
+ LP_Object_Cache::set( $cache_key, $enrolled, 'enrolled-courses' );
1892
  }
1893
 
1894
  $enrolled = $enrolled === 'yes' ? true : false;
1993
 
1994
  global $wpdb;
1995
  //$key_format = '%d-%d';
1996
+ $cached = (array) LP_Object_Cache::get( 'user-quiz-statuses', 'learnpress' );
1997
  if ( ! array_key_exists( $this->get_id() . '-' . $course_id . '-' . $quiz_id, $cached ) || $force ) {
1998
  $query = $wpdb->prepare( "
1999
  SELECT uq.item_id as id, uqm.meta_value as `status`
2293
  public function get_course_status( $course_id ) {
2294
 
2295
  $status = false;
2296
+ if ( false !== ( $data = LP_Object_Cache::get( 'course-' . $this->get_id() . '-' . $course_id, 'lp-user-courses' ) ) ) {
2297
  $status = $data['status'];
2298
  } else {
2299
  $course_data = $this->get_course_data( $course_id );
inc/user/class-lp-user-factory.php CHANGED
@@ -245,7 +245,7 @@ class LP_User_Factory {
245
  }
246
 
247
  public static function get_pending_requests() {
248
- if ( false === ( $pending_requests = wp_cache_get( 'pending-requests', 'lp-users' ) ) ) {
249
  global $wpdb;
250
  $query = $wpdb->prepare( "
251
  SELECT ID
@@ -255,7 +255,7 @@ class LP_User_Factory {
255
  ", '_requested_become_teacher', 'yes' );
256
 
257
  $pending_requests = $wpdb->get_col( $query );
258
- wp_cache_set( 'pending-requests', $pending_requests, 'lp-users' );
259
  }
260
 
261
  return $pending_requests;
245
  }
246
 
247
  public static function get_pending_requests() {
248
+ if ( false === ( $pending_requests = LP_Object_Cache::get( 'pending-requests', 'lp-users' ) ) ) {
249
  global $wpdb;
250
  $query = $wpdb->prepare( "
251
  SELECT ID
255
  ", '_requested_become_teacher', 'yes' );
256
 
257
  $pending_requests = $wpdb->get_col( $query );
258
+ LP_Object_Cache::set( 'pending-requests', $pending_requests, 'lp-users' );
259
  }
260
 
261
  return $pending_requests;
inc/user/lp-user-functions.php CHANGED
@@ -61,13 +61,13 @@ function learn_press_get_user_item_id( $user_id, $item_id, $course_id = 0 /* add
61
 
62
  // If $course_id is not passed consider $item_id is ID of a course
63
  if ( ! $course_id ) {
64
- if ( $item = wp_cache_get( 'course-' . $user_id . '-' . $item_id, 'lp-user-courses' ) ) {
65
  return $item['user_item_id'];
66
  }
67
  } else {
68
 
69
  // Otherwise, get item of the course
70
- if ( $items = wp_cache_get( 'course-item-' . $user_id . '-' . $course_id . '-' . $item_id, 'lp-user-course-items' ) ) {
71
  $item = reset( $items );
72
 
73
  return $item['user_item_id'];
@@ -709,7 +709,7 @@ function learn_press_filter_temp_users( $q ) {
709
  */
710
  function learn_press_get_temp_users() {
711
  return false;
712
- if ( false === ( $temp_users = wp_cache_get( 'learn-press/temp-users' ) ) ) {
713
  global $wpdb;
714
  $query = $wpdb->prepare( "
715
  SELECT ID
@@ -720,7 +720,7 @@ function learn_press_get_temp_users() {
720
 
721
  $temp_users = $wpdb->get_col( $query );
722
 
723
- wp_cache_set( 'learn-press/temp-users', $temp_users );
724
  }
725
 
726
  return $temp_users;
61
 
62
  // If $course_id is not passed consider $item_id is ID of a course
63
  if ( ! $course_id ) {
64
+ if ( $item = LP_Object_Cache::get( 'course-' . $user_id . '-' . $item_id, 'lp-user-courses' ) ) {
65
  return $item['user_item_id'];
66
  }
67
  } else {
68
 
69
  // Otherwise, get item of the course
70
+ if ( $items = LP_Object_Cache::get( 'course-item-' . $user_id . '-' . $course_id . '-' . $item_id, 'lp-user-course-items' ) ) {
71
  $item = reset( $items );
72
 
73
  return $item['user_item_id'];
709
  */
710
  function learn_press_get_temp_users() {
711
  return false;
712
+ if ( false === ( $temp_users = LP_Object_Cache::get( 'learn-press/temp-users' ) ) ) {
713
  global $wpdb;
714
  $query = $wpdb->prepare( "
715
  SELECT ID
720
 
721
  $temp_users = $wpdb->get_col( $query );
722
 
723
+ LP_Object_Cache::set( 'learn-press/temp-users', $temp_users );
724
  }
725
 
726
  return $temp_users;
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.12.1
8
  Author URI: http://thimpress.com
9
  Requires at least: 3.8
10
  Tested up to: 4.9.6
@@ -228,6 +228,7 @@ if ( ! class_exists( 'LearnPress' ) ) {
228
  require_once 'inc/class-lp-query-course.php';
229
  require_once 'inc/abstracts/abstract-addon.php';
230
  require_once 'inc/class-lp-settings.php';
 
231
 
232
  // Background processes
233
  require_once 'inc/abstracts/abstract-background-process.php';
@@ -262,7 +263,9 @@ if ( ! class_exists( 'LearnPress' ) ) {
262
  require_once 'inc/class-lp-install.php';
263
  require_once 'inc/lp-webhooks.php';
264
  require_once 'inc/class-lp-request-handler.php';
265
- require_once( 'inc/abstract-settings.php' );
 
 
266
  //require_once( 'inc/class-lp-market-products.php' );
267
 
268
  if ( is_admin() ) {
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.1.0
8
  Author URI: http://thimpress.com
9
  Requires at least: 3.8
10
  Tested up to: 4.9.6
228
  require_once 'inc/class-lp-query-course.php';
229
  require_once 'inc/abstracts/abstract-addon.php';
230
  require_once 'inc/class-lp-settings.php';
231
+ require_once 'inc/cache.php';
232
 
233
  // Background processes
234
  require_once 'inc/abstracts/abstract-background-process.php';
263
  require_once 'inc/class-lp-install.php';
264
  require_once 'inc/lp-webhooks.php';
265
  require_once 'inc/class-lp-request-handler.php';
266
+ require_once 'inc/abstract-settings.php';
267
+ require_once 'inc/admin/helpers/class-lp-plugins-helper.php';
268
+
269
  //require_once( 'inc/class-lp-market-products.php' );
270
 
271
  if ( is_admin() ) {
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.0.12.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.0.12 =
203
  ~ Fixed minor bug in gradebook list in admin
204
  ~ Made hook learn-press/course-tabs work
@@ -238,143 +244,8 @@ https://www.transifex.com/projects/p/learnpress/
238
  ~ Fixed breadcrumb not show page name when viewing archive course
239
  ~ Fixed archive course show header is title of first course
240
 
241
- = 3.0.9 =
242
- + GDPR compliance
243
- ~ Improved Start quiz button
244
- ~ Load js for comment-reply if it does not load by default
245
- ~ Fixed missing param when sending email for user who finished course
246
-
247
- = 3.0.8 =
248
- ~ Improved: get css class name for items for performance
249
- ~ Improved: check item is blocked for performance
250
- ~ Improved: upgrade database feature
251
- ~ Fixed: warning message when searching posts in frontend
252
- ~ Fixed: show 2 comments form in lesson page
253
- ~ Fixed: content of lesson does not show if set post-format to video
254
- ~ Fixed: some warning when getting question class with an array of post-type
255
- ~ Fixed: mysql error when updating item's grade with value is null
256
-
257
- = 3.0.7 =
258
- ~ Improved: ui/ux when adding/removing course items
259
- ~ Improved: ui/ux when adding/removing questions of a quiz
260
- ~ Improved: auto focus mouse to input when changing type of new course item
261
- ~ Improved: show confirm message before removing course item to trash
262
- ~ Improved: move item to trash when delete instead of delete it permanently
263
- ~ Improved: changed icon to turn on/off an item is preview and add tooltip
264
- ~ Improved: removed green effect when updating via ajax
265
- ~ Improved: focus mouse on search input when searching items
266
- ~ Improved: show button for closing popup
267
- ~ Improved: flush Hard Cache when updating post
268
- ~ Improved: updated metabox to latest version and changed textdomain
269
- ~ Fixed: pending course does not show for instructor
270
- ~ Fixed: filter lessons/quizzes by course does not work properly
271
- ~ Fixed: wrong currency symbol for Turkish lira
272
- ~ Fixed: division by zero when calculating course results
273
- ~ Fixed: get default thumbnail image for archive course if it option is turn of
274
- ~ Removed: option thumbnail size for single course
275
- ~ Improved somethings...
276
-
277
- = 3.0.6 =
278
- ~ Fixed: missing 'Instructors Registration' option
279
- ~ Fixed: cannot start quiz or complete lesson
280
- ~ Fixed: can view a quiz/lesson although it does not assign to a course
281
- ~ Fixed: wrong count number in courses manage
282
- ~ Fixed: cannot save some settings options
283
- ~ Fixed: missing hook
284
- ~ Fixed: user can view lesson with single post type link
285
- ~ Fixed: issue with 'Buy This Course' button
286
- ~ Fixed: cannot change course author
287
- ~ Fixed: issue with Become a Teacher form
288
- ~ Fixed: instructor cannot add iframe into course/lesson/quiz content
289
- ~ Improved: auto detect video in lesson content and move it to the top (move to option)
290
- ~ Improved something...
291
-
292
- = 3.0.5 =
293
- + Added: missing single course permalink options
294
- ~ Fixed: error notice when saving user profile
295
- ~ Fixed: date translation
296
- ~ Fixed: notice when viewing courses with Yoast SEO
297
- ~ Fixed: can't change author of the course
298
- ~ Fixed: preview lesson will redirect back to course
299
- ~ Fixed: some other bugs...
300
-
301
- = 3.0.4 =
302
- ~ Improved: action when clicking to close upgrade notice
303
- ~ Fixed: can not add course from other users to order
304
- ~ Fixed: lost quiz data after upgrading
305
- ~ Fixed: user can view lesson/quiz with single permalink
306
- ~ Fixed: can not view lesson
307
- ~ Fixed: notices in admin orders
308
- ~ Fixed: external buy this course redirect to home page
309
- ~ Fixed: remaining time message with course duration is zero
310
- ~ Fixed: hidden sections action ajax admin course editor
311
- ~ Fixed: admin can not add course to order from other users
312
- ~ More...
313
-
314
- = 3.0.3 =
315
- ~ Fixed quiz auto finish with duration is zero
316
- ~ Fixed pagination with quizzes in user profile
317
- ~ Fixed warning notice when getting current tab in profile
318
- ~ Fixed some issue in addons
319
-
320
-
321
- = 3.0.2 =
322
- ~ Fixed PHP non-numeric cast type
323
- ~ Improved admin ajax for course/quiz/question editor
324
- ~ Fixed error when extending method from parent
325
- ~ Fixed invalid course progress label
326
- ~ Fixed invalid filter to course passing grade
327
- ~ Fixed empty course item class for other post types
328
-
329
- = 3.0.1 =
330
- ~ Improved 'External link' button if user has enrolled course
331
- ~ Fixed category does not display courses (SO)
332
- ~ Fixed callback issue when sorting array|object
333
- ~ Fixed course auto finish if duration is 0
334
- ~ Fixed warning message when counting enrolled users
335
- ~ Fixed error when calling a method from object
336
- + Added position counter to course section
337
- + Update some default settings
338
- + Fixed some bugs...
339
-
340
- = 3.0.0 =
341
- + Reset courses data for an user has enrolled course
342
- + Reset course data for users has enrolled course
343
- + Reset data of a quiz or lesson for an user
344
- + Enable a Guest user can buy and checkout
345
- + Option to show/hide login form in user profile
346
- + Option to show/hide register form in user profile
347
- + Option to show/hide login form in checkout page
348
- + Option to show/hide register form in Checkout page
349
- + Enable sort the payment gateways to show in frontend
350
- + Quick turn a payment gateway on/of in a list
351
- + Support plugins Mathjax
352
- + Widget to display course info
353
- + Widget to display current progress of a course
354
- + Custom frontend colors
355
- + Group emails to related action
356
- + Run action to send the emails in background
357
- + Quick edit question settings in it's quiz
358
- + Preview mode for course/lesson/quiz
359
- + Option to show list of questions as numbers below quiz while doing or reviewing
360
- + Display duration of lesson or quiz in curriculum
361
- + Display number questions of quiz
362
- ~ Improves popup for searching courses to add to an order
363
- ~ Improves Emails system
364
- ~ Improves Multi users order
365
- ~ Admin settings pages
366
- ~ No distraction mode
367
- ~ New course editor
368
- ~ New quiz editor
369
- ~ User profile
370
- ~ Improve cache for speed
371
- ~ Improve UI/Ux for both backend and frontend
372
-
373
  == Upgrade Notice ==
374
 
375
- = 0.9.19 =
376
- In this version, we have changed a little bit about LearnPress Plugin directory structure and moved all add-ons to become independence plugins. If you face any problems relate to add-ons, please completely remove old version and re-install LearnPress. It does not affect your current data. Thank you.
377
-
378
  == Other note ==
379
  <a href="http://docs.thimpress.com/learnpress" target="_blank">Documentation</a> is available in ThimPress site.
380
- <a href="https://github.com/LearnPress/LearnPress/" target="_blank">LearnPress github repo.</a>
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.1.0
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.1.0 =
203
+ ~ Fixed issue vulnerabilities.
204
+ ~ Fixed issue related to object cache when doing quiz.
205
+ ~ Fixed lesson 404 with Polylang.
206
+ ~ Fixed PHP Fatal error class ‘LP_Plugins_Helper’ not found
207
+
208
  = 3.0.12 =
209
  ~ Fixed minor bug in gradebook list in admin
210
  ~ Made hook learn-press/course-tabs work
244
  ~ Fixed breadcrumb not show page name when viewing archive course
245
  ~ Fixed archive course show header is title of first course
246
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
247
  == Upgrade Notice ==
248
 
 
 
 
249
  == Other note ==
250
  <a href="http://docs.thimpress.com/learnpress" target="_blank">Documentation</a> is available in ThimPress site.
251
+ <a href="https://github.com/LearnPress/LearnPress/" target="_blank">LearnPress github repo.</a>