PluginProbe
Simple Analytics / 1.108
Simple Analytics v1.108
1.109 1.108 1.107 1.106 1.73 1.74 1.75 1.76 1.77 1.78 1.79 1.8 1.80 1.81 1.82 1.83 1.84 1.85 1.86 1.87 1.88 1.89 1.9 1.90 1.91 All 98 releases
simpleanalytics / src / WordPressSettings.php

WordPressSettings.php in Simple Analytics 1.108, at src/WordPressSettings.php

55 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SimpleAnalytics;
4
5 class WordPressSettings
6 {
7 /** @return mixed */
8 public function get(string $key, $default = null)
9 {
10 $value = get_option($key);
11
12 if (empty($value)) {
13 return $default;
14 }
15
16 return $value;
17 }
18
19 public function register(string $key, $value = null, bool $autoload = true): void
20 {
21 // Serialise booleans for WordPress terms...
22 if (is_bool($value)) $value = $value ? '1' : '0';
23
24 add_option($key, $value, null, $autoload);
25 }
26
27 public function update(string $key, $value, ?bool $autoload = null)
28 {
29 update_option($key, $value, $autoload);
30 }
31
32 public function delete(string $key): void
33 {
34 delete_option($key);
35 }
36
37 public function boolean(string $key, ?bool $default = null): ?bool
38 {
39 $value = get_option($key, null);
40
41 if ($value === null || $value === '') {
42 return $default;
43 }
44
45 return (bool)$value;
46 }
47
48 public function array(string $key): array
49 {
50 $value = $this->get($key, []);
51
52 return is_array($value) ? $value : [$value];
53 }
54 }
55