PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.3
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.3
1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 trunk 1.2.0 1.2.1 All 46 releases
fluent-cart / api / ModuleSettings.php

ModuleSettings.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.6.3, at api/ModuleSettings.php

73 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCart\Api;
4
5 use FluentCart\Framework\Support\Arr;
6
7 class ModuleSettings
8 {
9
10 const MODULE_SETTINGS_OPTION = 'fluent_cart_modules_settings';
11
12 public static function isActive($moduleName = '')
13 {
14 $allSettings = self::getAllSettings();
15
16 return Arr::get($allSettings, $moduleName . '.active') === 'yes';
17 }
18
19 public static function fileds()
20 {
21 return apply_filters('fluent_cart/module_setting/fields', [], []);
22 }
23
24 public static function saveSettings(array $data)
25 {
26 return update_option(static::MODULE_SETTINGS_OPTION, $data, true);
27 }
28
29 public static function getAllSettings($cached = true)
30 {
31 static $settings;
32 if (isset($settings) && $cached) {
33 return $settings;
34 }
35
36 $savedSettings = get_option(static::MODULE_SETTINGS_OPTION, []);
37
38 if (!$savedSettings || !is_array($savedSettings)) {
39 $savedSettings = [];
40 }
41
42 $defaults = apply_filters('fluent_cart/module_setting/default_values', [], []);
43
44 foreach ($defaults as $key => $value) {
45 if (!isset($savedSettings[$key])) {
46 $savedSettings[$key] = $value;
47 } else {
48 $savedSettings[$key] = wp_parse_args(Arr::get($savedSettings, $key, []), $value);
49 }
50 }
51
52 $settings = $savedSettings;
53
54 return $settings;
55 }
56
57 public static function getSettings($key = null)
58 {
59 $settings = static::getAllSettings();
60 if ($key) {
61 return Arr::get($settings, $key);
62 }
63
64 return $settings;
65 }
66
67 public static function validKeys(): array
68 {
69 return array_keys(static::fileds());
70 }
71
72 }
73