-
Notifications
You must be signed in to change notification settings - Fork 210
Expand file tree
/
Copy pathclass-progress-storage-settings.php
More file actions
136 lines (123 loc) · 3.02 KB
/
class-progress-storage-settings.php
File metadata and controls
136 lines (123 loc) · 3.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
/**
* File containing the Progress_Storage_Settings class.
*
* @package sensei
*/
namespace Sensei\Internal\Services;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Class Progress_Storage_Settings.
*
* @internal
*
* @since 4.20.0
*/
class Progress_Storage_Settings {
/**
* Comment-based storage.
*
* @var string
*/
public const COMMENTS_STORAGE = 'comments';
/**
* Table-based storage.
*
* @var string
*/
public const TABLES_STORAGE = 'custom_tables';
/**
* Get the storage repositories.
*
* @return array Returns an array of repositories where the key is the repository slug and the value is the description.
*/
public static function get_storage_repositories(): array {
return array(
self::COMMENTS_STORAGE => __( 'WordPress comments based storage', 'sensei-lms' ),
self::TABLES_STORAGE => __( 'High-Performance progress storage (experimental)', 'sensei-lms' ),
);
}
/**
* Returns true if the HPPS feature is enabled.
*
* @return bool
*/
public static function is_hpps_enabled(): bool {
return Sensei()->settings->settings['experimental_progress_storage'] ?? false;
}
/**
* Returns current storage repository.
*
* @return string
*/
public static function get_current_repository(): string {
return Sensei()->settings->settings['experimental_progress_storage_repository'] ?? self::COMMENTS_STORAGE;
}
/**
* Returns true if the comments repository is enabled.
*
* @return bool
*/
public static function is_comments_repository(): bool {
return self::COMMENTS_STORAGE === self::get_current_repository();
}
/**
* Returns true if the tables repository is enabled.
*
* @return bool
*/
public static function is_tables_repository(): bool {
return self::TABLES_STORAGE === self::get_current_repository();
}
/**
* Returns true if the HPPS synchronization is enabled.
*
* @return bool
*/
public static function is_sync_enabled(): bool {
return Sensei()->settings->settings['experimental_progress_storage_synchronization'] ?? false;
}
/**
* Memoized cache-enabled flag. Null means not yet computed.
*
* @var bool|null
*/
private static ?bool $cache_enabled = null;
/**
* Returns true if HPPS caching is enabled.
*
* Defaults to true when using tables-based storage. Filterable via `sensei_hpps_cache_enabled`.
*
* @since 4.24.0
*
* @return bool
*/
public static function is_cache_enabled(): bool {
if ( null === self::$cache_enabled ) {
/**
* Filter whether HPPS caching is enabled.
*
* @hook sensei_hpps_cache_enabled
*
* @since 4.24.0
*
* @param {bool} $enabled Whether caching is enabled.
* @return {bool} Whether caching should be enabled.
*/
self::$cache_enabled = (bool) apply_filters( 'sensei_hpps_cache_enabled', self::is_tables_repository() );
}
return self::$cache_enabled;
}
/**
* Reset the memoized cache-enabled flag. Useful for tests.
*
* @since 4.24.0
*
* @internal
*/
public static function reset_cache_enabled(): void {
self::$cache_enabled = null;
}
}