1 | <?php |
||
18 | class FS_Admin_Notices { |
||
19 | /** |
||
20 | * @since 1.2.2 |
||
21 | * |
||
22 | * @var string |
||
23 | */ |
||
24 | protected $_module_unique_affix; |
||
25 | /** |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $_id; |
||
29 | /** |
||
30 | * @var string |
||
31 | */ |
||
32 | protected $_title; |
||
33 | /** |
||
34 | * @var FS_Admin_Notice_Manager |
||
35 | */ |
||
36 | protected $_notices; |
||
37 | /** |
||
38 | * @var FS_Admin_Notice_Manager |
||
39 | */ |
||
40 | protected $_network_notices; |
||
41 | /** |
||
42 | * @var int The ID of the blog that is associated with the current site level options. |
||
43 | */ |
||
44 | private $_blog_id = 0; |
||
45 | /** |
||
46 | * @var bool |
||
47 | */ |
||
48 | private $_is_multisite; |
||
49 | /** |
||
50 | * @var FS_Admin_Notices[] |
||
51 | */ |
||
52 | private static $_instances = array(); |
||
53 | |||
54 | /** |
||
55 | * @param string $id |
||
56 | * @param string $title |
||
57 | * @param string $module_unique_affix |
||
58 | * @param bool $is_network_and_blog_admins Whether or not the message should be shown both on network and |
||
59 | * blog admin pages. |
||
60 | * |
||
61 | * @return FS_Admin_Notices |
||
62 | */ |
||
63 | static function instance( $id, $title = '', $module_unique_affix = '', $is_network_and_blog_admins = false ) { |
||
70 | |||
71 | /** |
||
72 | * @param string $id |
||
73 | * @param string $title |
||
74 | * @param string $module_unique_affix |
||
75 | * @param bool $is_network_and_blog_admins Whether or not the message should be shown both on network and |
||
76 | * blog admin pages. |
||
77 | */ |
||
78 | protected function __construct( $id, $title = '', $module_unique_affix = '', $is_network_and_blog_admins = false ) { |
||
104 | |||
105 | /** |
||
106 | * Add admin message to admin messages queue, and hook to admin_notices / all_admin_notices if not yet hooked. |
||
107 | * |
||
108 | * @author Vova Feldman (@svovaf) |
||
109 | * @since 1.0.4 |
||
110 | * |
||
111 | * @param string $message |
||
112 | * @param string $title |
||
113 | * @param string $type |
||
114 | * @param bool $is_sticky |
||
115 | * @param string $id Message ID |
||
116 | * @param bool $store_if_sticky |
||
117 | * @param int|null $network_level_or_blog_id |
||
118 | * |
||
119 | * @uses add_action() |
||
120 | */ |
||
121 | function add( |
||
145 | |||
146 | /** |
||
147 | * @author Vova Feldman (@svovaf) |
||
148 | * @since 1.0.7 |
||
149 | * |
||
150 | * @param string|string[] $ids |
||
151 | * @param int|null $network_level_or_blog_id |
||
152 | */ |
||
153 | function remove_sticky( $ids, $network_level_or_blog_id = null ) { |
||
166 | |||
167 | /** |
||
168 | * Check if sticky message exists by id. |
||
169 | * |
||
170 | * @author Vova Feldman (@svovaf) |
||
171 | * @since 1.0.9 |
||
172 | * |
||
173 | * @param string $id |
||
174 | * @param int|null $network_level_or_blog_id |
||
175 | * |
||
176 | * @return bool |
||
177 | */ |
||
178 | function has_sticky( $id, $network_level_or_blog_id = null ) { |
||
187 | |||
188 | /** |
||
189 | * Adds sticky admin notification. |
||
190 | * |
||
191 | * @author Vova Feldman (@svovaf) |
||
192 | * @since 1.0.7 |
||
193 | * |
||
194 | * @param string $message |
||
195 | * @param string $id Message ID |
||
196 | * @param string $title |
||
197 | * @param string $type |
||
198 | * @param int|null $network_level_or_blog_id |
||
199 | * @param number|null $wp_user_id |
||
200 | * @param string|null $plugin_title |
||
201 | * @param bool $is_network_and_blog_admins Whether or not the message should be shown both on network and |
||
202 | * blog admin pages. |
||
203 | */ |
||
204 | function add_sticky( |
||
222 | |||
223 | /** |
||
224 | * Clear all sticky messages. |
||
225 | * |
||
226 | * @author Vova Feldman (@svovaf) |
||
227 | * @since 2.0.0 |
||
228 | * |
||
229 | * @param int|null $network_level_or_blog_id |
||
230 | */ |
||
231 | function clear_all_sticky( $network_level_or_blog_id = null ) { |
||
247 | |||
248 | /** |
||
249 | * Add admin message to all admin messages queue, and hook to all_admin_notices if not yet hooked. |
||
250 | * |
||
251 | * @author Vova Feldman (@svovaf) |
||
252 | * @since 1.0.4 |
||
253 | * |
||
254 | * @param string $message |
||
255 | * @param string $title |
||
256 | * @param string $type |
||
257 | * @param bool $is_sticky |
||
258 | * @param string $id Message ID |
||
259 | */ |
||
260 | function add_all( $message, $title = '', $type = 'success', $is_sticky = false, $id = '' ) { |
||
263 | |||
264 | #-------------------------------------------------------------------------------- |
||
265 | #region Helper Methods |
||
266 | #-------------------------------------------------------------------------------- |
||
267 | |||
268 | /** |
||
269 | * @author Vova Feldman (@svovaf) |
||
270 | * @since 2.0.0 |
||
271 | * |
||
272 | * @param int $blog_id |
||
273 | * |
||
274 | * @return FS_Admin_Notice_Manager |
||
275 | */ |
||
276 | private function get_site_notices( $blog_id = 0 ) { |
||
289 | |||
290 | /** |
||
291 | * Check if the network notices should be used. |
||
292 | * |
||
293 | * @author Vova Feldman (@svovaf) |
||
294 | * @since 2.0.0 |
||
295 | * |
||
296 | * @param string $id |
||
297 | * @param null|bool|int $network_level_or_blog_id When an integer, use the given blog storage. When `true` use the multisite notices (if there's a network). When `false`, use the current context blog notices. When `null`, the decision which notices manager to use (MS vs. Current S) will be handled internally and determined based on the $id and the context admin (blog admin vs. network level admin). |
||
298 | * |
||
299 | * @return bool |
||
300 | */ |
||
301 | private function should_use_network_notices( $id = '', $network_level_or_blog_id = null ) { |
||
319 | |||
320 | #endregion |
||
321 | } |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.