| 1 |
<?php |
| 2 |
|
| 3 |
namespace SimpleAnalytics; |
| 4 |
|
| 5 |
class Setting |
| 6 |
{ |
| 7 |
/** |
| 8 |
* @return mixed |
| 9 |
*/ |
| 10 |
public static function get(string $key, $default = null) |
| 11 |
{ |
| 12 |
$value = get_option($key); |
| 13 |
|
| 14 |
if (empty($value)) { |
| 15 |
return $default; |
| 16 |
} |
| 17 |
|
| 18 |
return $value; |
| 19 |
} |
| 20 |
|
| 21 |
public static function boolean(string $key, ?bool $default = null): ?bool |
| 22 |
{ |
| 23 |
$value = get_option($key, null); |
| 24 |
|
| 25 |
if ($value === null || $value === '') { |
| 26 |
return $default; |
| 27 |
} |
| 28 |
|
| 29 |
return (bool)$value; |
| 30 |
} |
| 31 |
|
| 32 |
public static function array(string $key): array |
| 33 |
{ |
| 34 |
$value = self::get($key, []); |
| 35 |
|
| 36 |
return is_array($value) ? $value : [$value]; |
| 37 |
} |
| 38 |
} |
| 39 |
|