| 1 |
<?php |
| 2 |
/** |
| 3 |
* Helper class for interacting with the user |
| 4 |
*/ |
| 5 |
|
| 6 |
namespace Extendify\Library; |
| 7 |
|
| 8 |
/** |
| 9 |
* Helper class for interacting with the user |
| 10 |
*/ |
| 11 |
class SiteSettings |
| 12 |
{ |
| 13 |
|
| 14 |
/** |
| 15 |
* SiteSettings option_name - For historical reasons do not change. |
| 16 |
* |
| 17 |
* @var string |
| 18 |
*/ |
| 19 |
protected $key = 'extendifysdk_sitesettings'; |
| 20 |
|
| 21 |
/** |
| 22 |
* SiteSettings default value |
| 23 |
* |
| 24 |
* @var Json |
| 25 |
*/ |
| 26 |
protected $default = '{"state":{"enabled":true}}'; |
| 27 |
|
| 28 |
/** |
| 29 |
* The class instance. |
| 30 |
* |
| 31 |
* @var $instance |
| 32 |
*/ |
| 33 |
protected static $instance = null; |
| 34 |
|
| 35 |
/** |
| 36 |
* Returns Setting |
| 37 |
* Use it like Setting::data() |
| 38 |
* |
| 39 |
* @return mixed - Setting Data |
| 40 |
*/ |
| 41 |
private function dataHandler() |
| 42 |
{ |
| 43 |
return \get_option($this->key, $this->default); |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Returns Setting Key |
| 48 |
* Use it like Setting::key() |
| 49 |
* |
| 50 |
* @return string - Setting key |
| 51 |
*/ |
| 52 |
private function keyHandler() |
| 53 |
{ |
| 54 |
return $this->key; |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* Use it like Setting::method() e.g. Setting::data() |
| 59 |
* |
| 60 |
* @param string $name - The name of the method to call. |
| 61 |
* @param array $arguments - The arguments to pass in. |
| 62 |
* |
| 63 |
* @return mixed |
| 64 |
*/ |
| 65 |
public static function __callStatic($name, array $arguments) |
| 66 |
{ |
| 67 |
$name = "{$name}Handler"; |
| 68 |
self::$instance = new static(); |
| 69 |
$r = self::$instance; |
| 70 |
return $r->$name(...$arguments); |
| 71 |
} |
| 72 |
} |
| 73 |
|