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