1 | <?php |
||
16 | abstract class WordPressOption |
||
17 | { |
||
18 | const NOT_SET_YET = 'wordpress-option-value-not-yet-set'; |
||
19 | |||
20 | /** |
||
21 | * WordPress makes it difficult to determine if an option was successfully saved or not |
||
22 | * which is sometimes really important to know if the information you are saving is critical. |
||
23 | * The following options allow us to have a better chance of knowing when an update actually failed |
||
24 | * or when it just didn't update because the value hasn't changed, but everything is safe. |
||
25 | */ |
||
26 | const UPDATE_SUCCESS = 1; |
||
27 | |||
28 | const UPDATE_NONE = 0; |
||
29 | |||
30 | const UPDATE_ERROR = -1; |
||
31 | |||
32 | /** |
||
33 | * @var boolean |
||
34 | */ |
||
35 | private $autoload; |
||
36 | |||
37 | /** |
||
38 | * @var mixed |
||
39 | */ |
||
40 | private $default_value; |
||
41 | |||
42 | /** |
||
43 | * @var string |
||
44 | */ |
||
45 | private $option_name; |
||
46 | |||
47 | /** |
||
48 | * @var mixed |
||
49 | */ |
||
50 | private $value = WordPressOption::NOT_SET_YET; |
||
51 | |||
52 | |||
53 | /** |
||
54 | * WordPressOption constructor. |
||
55 | * |
||
56 | * @param bool $autoload |
||
57 | * @param mixed $default_value |
||
58 | * @param string $option_name |
||
59 | */ |
||
60 | public function __construct(string $option_name, $default_value, bool $autoload = false) |
||
66 | |||
67 | |||
68 | /** |
||
69 | * @param bool|string $autoload |
||
70 | */ |
||
71 | public function setAutoload($autoload): void |
||
75 | |||
76 | |||
77 | /** |
||
78 | * @param mixed $default_value |
||
79 | */ |
||
80 | public function setDefaultValue($default_value): void |
||
84 | |||
85 | |||
86 | /** |
||
87 | * @param string $option_name |
||
88 | */ |
||
89 | public function setOptionName(string $option_name): void |
||
93 | |||
94 | |||
95 | /** |
||
96 | * @return string |
||
97 | */ |
||
98 | public function getOptionName(): string |
||
102 | |||
103 | |||
104 | /** |
||
105 | * @return false|mixed|void |
||
106 | */ |
||
107 | public function loadOption() |
||
114 | |||
115 | |||
116 | /** |
||
117 | * @param $value |
||
118 | * @return int |
||
119 | */ |
||
120 | public function updateOption($value) : int |
||
139 | |||
140 | |||
141 | /** |
||
142 | * @return string |
||
143 | */ |
||
144 | private function autoload() : string |
||
148 | } |
||
149 |