1 | <?php |
||
8 | class Jetpack_Modules_Overrides { |
||
9 | /** |
||
10 | * Used to cache module overrides so that we minimize how many times we appy the |
||
11 | * option_jetpack_active_modules filter. |
||
12 | * |
||
13 | * @var null|array |
||
14 | */ |
||
15 | private $overrides = null; |
||
16 | |||
17 | /** |
||
18 | * Clears the $overrides member used for caching. |
||
19 | * |
||
20 | * Since get_overrides() can be passed a falsey value to skip caching, this is probably |
||
21 | * most useful for clearing cache between tests. |
||
22 | * |
||
23 | * @return void |
||
24 | */ |
||
25 | public function clear_cache() { |
||
28 | |||
29 | /** |
||
30 | * Returns true if there is a filter on the jetpack_active_modules option. |
||
31 | * |
||
32 | * @return bool Whether there is a filter on the jetpack_active_modules option. |
||
33 | */ |
||
34 | public function do_overrides_exist() { |
||
37 | |||
38 | /** |
||
39 | * Gets the override for a given module. |
||
40 | * |
||
41 | * @param string $module_slug The module's slug. |
||
42 | * @param boolean $use_cache Whether or not cached overrides should be used. |
||
43 | * |
||
44 | * @return bool|string False if no override for module. 'active' or 'inactive' if there is an override. |
||
45 | */ |
||
46 | public function get_module_override( $module_slug, $use_cache = true ) { |
||
55 | |||
56 | /** |
||
57 | * Returns an array of module overrides where the key is the module slug and the value |
||
58 | * is true if the module is forced on and false if the module is forced off. |
||
59 | * |
||
60 | * @param bool $use_cache Whether or not cached overrides should be used. |
||
61 | * |
||
62 | * @return array The array of module overrides. |
||
63 | */ |
||
64 | public function get_overrides( $use_cache = true ) { |
||
109 | |||
110 | /** |
||
111 | * A reference to an instance of this class. |
||
112 | * |
||
113 | * @var Jetpack_Modules_Overrides |
||
114 | */ |
||
115 | private static $instance = null; |
||
116 | |||
117 | /** |
||
118 | * Returns the singleton instance of Jetpack_Modules_Overrides |
||
119 | * |
||
120 | * @return Jetpack_Modules_Overrides |
||
121 | */ |
||
122 | public static function instance() { |
||
129 | |||
130 | /** |
||
131 | * Private construct to enforce singleton. |
||
132 | */ |
||
133 | private function __construct() { |
||
135 | } |
||
136 | |||
138 |