1 | <?php |
||
25 | class PersistentAdminNotice implements RequiresCapCheckInterface |
||
26 | { |
||
27 | |||
28 | /** |
||
29 | * @var string $name |
||
30 | */ |
||
31 | protected $name = ''; |
||
32 | |||
33 | /** |
||
34 | * @var string $message |
||
35 | */ |
||
36 | protected $message = ''; |
||
37 | |||
38 | /** |
||
39 | * @var boolean $force_update |
||
40 | */ |
||
41 | protected $force_update = false; |
||
42 | |||
43 | /** |
||
44 | * @var string $capability |
||
45 | */ |
||
46 | protected $capability = 'manage_options'; |
||
47 | |||
48 | /** |
||
49 | * @var string $cap_context |
||
50 | */ |
||
51 | protected $cap_context = 'view persistent admin notice'; |
||
52 | |||
53 | /** |
||
54 | * @var boolean $dismissed |
||
55 | */ |
||
56 | protected $dismissed = false; |
||
57 | |||
58 | /** |
||
59 | * @var CapCheckInterface $cap_check |
||
60 | */ |
||
61 | protected $cap_check; |
||
62 | |||
63 | /** |
||
64 | * if true, then this notice will be deleted from the database |
||
65 | * |
||
66 | * @var boolean $purge |
||
67 | */ |
||
68 | protected $purge = false; |
||
69 | |||
70 | /** |
||
71 | * gets set to true if notice is successfully registered with the PersistentAdminNoticeManager |
||
72 | * if false, and WP_DEBUG is on, then an exception will be thrown in the admin footer |
||
73 | * |
||
74 | * @var boolean $registered |
||
75 | */ |
||
76 | private $registered = false; |
||
77 | |||
78 | |||
79 | |||
80 | /** |
||
81 | * PersistentAdminNotice constructor |
||
82 | |||
83 | * |
||
84 | * @param string $name [required] the name, or key of the Persistent Admin Notice to be stored |
||
85 | * @param string $message [required] the message to be stored persistently until dismissed |
||
86 | * @param bool $force_update enforce the reappearance of a persistent message |
||
87 | * @param string $capability user capability required to view this notice |
||
88 | * @param string $cap_context description for why the cap check is being performed |
||
89 | * @param bool $dismissed whether or not the user has already dismissed/viewed this notice |
||
90 | * @throws InvalidDataTypeException |
||
91 | */ |
||
92 | public function __construct( |
||
112 | |||
113 | |||
114 | |||
115 | /** |
||
116 | * @return string |
||
117 | */ |
||
118 | public function getName() |
||
122 | |||
123 | |||
124 | |||
125 | /** |
||
126 | * @param string $name |
||
127 | * @throws InvalidDataTypeException |
||
128 | */ |
||
129 | private function setName($name) |
||
136 | |||
137 | |||
138 | |||
139 | /** |
||
140 | * @return string |
||
141 | */ |
||
142 | public function getMessage() |
||
146 | |||
147 | |||
148 | |||
149 | /** |
||
150 | * @param string $message |
||
151 | * @throws InvalidDataTypeException |
||
152 | */ |
||
153 | private function setMessage($message) |
||
164 | |||
165 | |||
166 | |||
167 | /** |
||
168 | * @return bool |
||
169 | */ |
||
170 | public function getForceUpdate() |
||
174 | |||
175 | |||
176 | |||
177 | /** |
||
178 | * @param bool $force_update |
||
179 | */ |
||
180 | private function setForceUpdate($force_update) |
||
184 | |||
185 | |||
186 | |||
187 | /** |
||
188 | * @return string |
||
189 | */ |
||
190 | public function getCapability() |
||
194 | |||
195 | |||
196 | |||
197 | /** |
||
198 | * @param string $capability |
||
199 | * @throws InvalidDataTypeException |
||
200 | */ |
||
201 | private function setCapability($capability) |
||
208 | |||
209 | |||
210 | |||
211 | /** |
||
212 | * @return string |
||
213 | */ |
||
214 | public function getCapContext() |
||
218 | |||
219 | |||
220 | |||
221 | /** |
||
222 | * @param string $cap_context |
||
223 | * @throws InvalidDataTypeException |
||
224 | */ |
||
225 | private function setCapContext($cap_context) |
||
232 | |||
233 | |||
234 | |||
235 | /** |
||
236 | * @return bool |
||
237 | */ |
||
238 | public function getDismissed() |
||
242 | |||
243 | |||
244 | |||
245 | /** |
||
246 | * @param bool $dismissed |
||
247 | */ |
||
248 | public function setDismissed($dismissed) |
||
252 | |||
253 | |||
254 | |||
255 | /** |
||
256 | * @return CapCheckInterface |
||
257 | * @throws InvalidDataTypeException |
||
258 | */ |
||
259 | public function getCapCheck() |
||
271 | |||
272 | |||
273 | |||
274 | /** |
||
275 | * @param CapCheckInterface $cap_check |
||
276 | */ |
||
277 | private function setCapCheck(CapCheckInterface $cap_check) |
||
281 | |||
282 | |||
283 | |||
284 | /** |
||
285 | * @return bool |
||
286 | */ |
||
287 | public function getPurge() |
||
291 | |||
292 | |||
293 | |||
294 | /** |
||
295 | * @param bool $purge |
||
296 | */ |
||
297 | public function setPurge($purge) |
||
301 | |||
302 | |||
303 | |||
304 | /** |
||
305 | * given a valid PersistentAdminNotice Collection, |
||
306 | * this notice will be added if it is not already found in the collection (using its name as the identifier) |
||
307 | * if an existing notice is found that has already been dismissed, |
||
308 | * but we are overriding with a forced update, then we will toggle its dismissed state, |
||
309 | * so that the notice is displayed again |
||
310 | * |
||
311 | * @param Collection $persistent_admin_notice_collection |
||
312 | * @throws InvalidEntityException |
||
313 | */ |
||
314 | public function registerPersistentAdminNotice(Collection $persistent_admin_notice_collection) |
||
332 | |||
333 | |||
334 | |||
335 | /** |
||
336 | * @throws DomainException |
||
337 | */ |
||
338 | public function confirmRegistered() |
||
352 | |||
353 | |||
354 | } |
||
355 | // End of file PersistentAdminNotice.php |
||
356 | // Location: core/domain/entities/notifications/PersistentAdminNotice.php |