PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.8
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.8
4.4.8 4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 4.2.0 All 139 releases
← All changes | inc/cache/class-lp-user-items-cache.php +69 -69 4.3.94.4.8 View file →
@@ -1,69 +1,69 @@
1 -<?php
2 -
3 -/**
4 - * Class LP_Course_Cache
5 - *
6 - * @author tungnx
7 - * @since 4.0.9
8 - * @version 1.0.0
9 - */
10 -defined( 'ABSPATH' ) || exit();
11 -
12 -class LP_User_Items_Cache extends LP_Cache {
13 - protected $key_group_child = 'user-items';
14 -
15 - /**
16 - * @param $has_thim_cache bool
17 - */
18 - public function __construct( $has_thim_cache = false ) {
19 - parent::__construct( $has_thim_cache );
20 - }
21 -
22 - public function set_user_item( $keys = [], string $value = '' ) {
23 - $key = implode( '/', $keys );
24 - $this->set_cache( $key, $value );
25 - }
26 -
27 - public function get_user_item( $keys = [] ) {
28 - $key = implode( '/', $keys );
29 - $rs = LP_Cache::cache_load_first( 'get', $key );
30 - if ( false !== $rs ) {
31 - return $rs;
32 - }
33 -
34 - $rs = $this->get_cache( $key );
35 - LP_Cache::cache_load_first( 'set', $key, $rs );
36 -
37 - return $rs;
38 - }
39 -
40 - public function clean_user_item( $keys = [] ) {
41 - $key = implode( '/', $keys );
42 - $this->clear( $key );
43 - }
44 -
45 - /**
46 - * For cache clear all user items has course_id
47 - *
48 - * @param $course_id int
49 - *
50 - * @return bool|int|mysqli_result|resource|null
51 - * @throws Exception
52 - */
53 - public function clean_user_items_by_course( int $course_id = 0 ) {
54 - $thim_cache_db = Thim_Cache_DB::instance();
55 - $query = $thim_cache_db->wpdb->prepare(
56 - "DELETE FROM {$thim_cache_db->table_name}
57 - WHERE key_cache REGEXP %s",
58 - "learn_press/user-items/[0-9]*/{$course_id}/" . LP_COURSE_CPT
59 - );
60 -
61 - $rs = $thim_cache_db->wpdb->query( $query );
62 -
63 - if ( $thim_cache_db->wpdb->last_error ) {
64 - throw new Exception( $thim_cache_db->wpdb->last_error );
65 - }
66 -
67 - return $rs;
68 - }
69 -}
1 +<?php
2 +
3 +/**
4 + * Class LP_Course_Cache
5 + *
6 + * @author tungnx
7 + * @since 4.0.9
8 + * @version 1.0.0
9 + */
10 +defined( 'ABSPATH' ) || exit();
11 +
12 +class LP_User_Items_Cache extends LP_Cache {
13 + protected $key_group_child = 'user-items';
14 +
15 + /**
16 + * @param $has_thim_cache bool
17 + */
18 + public function __construct( $has_thim_cache = false ) {
19 + parent::__construct( $has_thim_cache );
20 + }
21 +
22 + public function set_user_item( $keys = [], string $value = '' ) {
23 + $key = implode( '/', $keys );
24 + $this->set_cache( $key, $value );
25 + }
26 +
27 + public function get_user_item( $keys = [] ) {
28 + $key = implode( '/', $keys );
29 + $rs = LP_Cache::cache_load_first( 'get', $key );
30 + if ( false !== $rs ) {
31 + return $rs;
32 + }
33 +
34 + $rs = $this->get_cache( $key );
35 + LP_Cache::cache_load_first( 'set', $key, $rs );
36 +
37 + return $rs;
38 + }
39 +
40 + public function clean_user_item( $keys = [] ) {
41 + $key = implode( '/', $keys );
42 + $this->clear( $key );
43 + }
44 +
45 + /**
46 + * For cache clear all user items has course_id
47 + *
48 + * @param $course_id int
49 + *
50 + * @return bool|int|mysqli_result|resource|null
51 + * @throws Exception
52 + */
53 + public function clean_user_items_by_course( int $course_id = 0 ) {
54 + $thim_cache_db = Thim_Cache_DB::instance();
55 + $query = $thim_cache_db->wpdb->prepare(
56 + "DELETE FROM {$thim_cache_db->table_name}
57 + WHERE key_cache REGEXP %s",
58 + "learn_press/user-items/[0-9]*/{$course_id}/" . LP_COURSE_CPT
59 + );
60 +
61 + $rs = $thim_cache_db->wpdb->query( $query );
62 +
63 + if ( $thim_cache_db->wpdb->last_error ) {
64 + throw new Exception( $thim_cache_db->wpdb->last_error );
65 + }
66 +
67 + return $rs;
68 + }
69 +}