This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
0 ignored issues
–
show
|
|||
2 | /** |
||
3 | * @package Freemius |
||
4 | * @copyright Copyright (c) 2015, Freemius, Inc. |
||
5 | * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3 |
||
6 | * @since 2.0.0 |
||
7 | */ |
||
8 | |||
9 | if ( ! defined( 'ABSPATH' ) ) { |
||
10 | exit; |
||
11 | } |
||
12 | |||
13 | /** |
||
14 | * WP Admin notices manager both for site level and network level. |
||
15 | * |
||
16 | * Class FS_Admin_Notices |
||
17 | */ |
||
18 | class FS_Admin_Notices { |
||
0 ignored issues
–
show
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.
You can fix this by adding a namespace to your class: namespace YourVendor;
class YourClass { }
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries. ![]() |
|||
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 ) { |
||
0 ignored issues
–
show
|
|||
64 | if ( ! isset( self::$_instances[ $id ] ) ) { |
||
65 | self::$_instances[ $id ] = new FS_Admin_Notices( $id, $title, $module_unique_affix, $is_network_and_blog_admins ); |
||
66 | } |
||
67 | |||
68 | return self::$_instances[ $id ]; |
||
69 | } |
||
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 ) { |
||
79 | $this->_id = $id; |
||
80 | $this->_title = $title; |
||
81 | $this->_module_unique_affix = $module_unique_affix; |
||
82 | $this->_is_multisite = is_multisite(); |
||
83 | |||
84 | if ( $this->_is_multisite ) { |
||
85 | $this->_blog_id = get_current_blog_id(); |
||
86 | |||
87 | $this->_network_notices = FS_Admin_Notice_Manager::instance( |
||
88 | $id, |
||
89 | $title, |
||
90 | $module_unique_affix, |
||
91 | $is_network_and_blog_admins, |
||
92 | true |
||
93 | ); |
||
94 | } |
||
95 | |||
96 | $this->_notices = FS_Admin_Notice_Manager::instance( |
||
97 | $id, |
||
98 | $title, |
||
99 | $module_unique_affix, |
||
100 | false, |
||
101 | $this->_blog_id |
||
102 | ); |
||
103 | } |
||
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( |
||
0 ignored issues
–
show
|
|||
122 | $message, |
||
123 | $title = '', |
||
124 | $type = 'success', |
||
125 | $is_sticky = false, |
||
126 | $id = '', |
||
127 | $store_if_sticky = true, |
||
128 | $network_level_or_blog_id = null |
||
129 | ) { |
||
130 | if ( $this->should_use_network_notices( $id, $network_level_or_blog_id ) ) { |
||
131 | $notices = $this->_network_notices; |
||
132 | } else { |
||
133 | $notices = $this->get_site_notices( $network_level_or_blog_id ); |
||
134 | } |
||
135 | |||
136 | $notices->add( |
||
137 | $message, |
||
138 | $title, |
||
139 | $type, |
||
140 | $is_sticky, |
||
141 | $id, |
||
142 | $store_if_sticky |
||
143 | ); |
||
144 | } |
||
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 ) { |
||
0 ignored issues
–
show
|
|||
154 | if ( ! is_array( $ids ) ) { |
||
155 | $ids = array( $ids ); |
||
156 | } |
||
157 | |||
158 | if ( $this->should_use_network_notices( $ids[0], $network_level_or_blog_id ) ) { |
||
159 | $notices = $this->_network_notices; |
||
160 | } else { |
||
161 | $notices = $this->get_site_notices( $network_level_or_blog_id ); |
||
162 | } |
||
163 | |||
164 | return $notices->remove_sticky( $ids ); |
||
165 | } |
||
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 ) { |
||
0 ignored issues
–
show
|
|||
179 | if ( $this->should_use_network_notices( $id, $network_level_or_blog_id ) ) { |
||
180 | $notices = $this->_network_notices; |
||
181 | } else { |
||
182 | $notices = $this->get_site_notices( $network_level_or_blog_id ); |
||
183 | } |
||
184 | |||
185 | return $notices->has_sticky( $id ); |
||
186 | } |
||
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( |
||
0 ignored issues
–
show
|
|||
205 | $message, |
||
206 | $id, |
||
207 | $title = '', |
||
208 | $type = 'success', |
||
209 | $network_level_or_blog_id = null, |
||
210 | $wp_user_id = null, |
||
211 | $plugin_title = null, |
||
212 | $is_network_and_blog_admins = false |
||
213 | ) { |
||
214 | if ( $this->should_use_network_notices( $id, $network_level_or_blog_id ) ) { |
||
215 | $notices = $this->_network_notices; |
||
216 | } else { |
||
217 | $notices = $this->get_site_notices( $network_level_or_blog_id ); |
||
218 | } |
||
219 | |||
220 | $notices->add_sticky( $message, $id, $title, $type, $wp_user_id, $plugin_title, $is_network_and_blog_admins ); |
||
221 | } |
||
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 ) { |
||
0 ignored issues
–
show
|
|||
232 | if ( ! $this->_is_multisite || |
||
233 | false === $network_level_or_blog_id || |
||
234 | 0 == $network_level_or_blog_id || |
||
0 ignored issues
–
show
|
|||
235 | is_null( $network_level_or_blog_id ) |
||
236 | ) { |
||
237 | $notices = $this->get_site_notices( $network_level_or_blog_id ); |
||
238 | $notices->clear_all_sticky(); |
||
239 | } |
||
240 | |||
241 | if ( $this->_is_multisite && |
||
242 | ( true === $network_level_or_blog_id || is_null( $network_level_or_blog_id ) ) |
||
243 | ) { |
||
244 | $this->_network_notices->clear_all_sticky(); |
||
245 | } |
||
246 | } |
||
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 = '' ) { |
||
0 ignored issues
–
show
|
|||
261 | $this->add( $message, $title, $type, $is_sticky, true, $id ); |
||
0 ignored issues
–
show
true is of type boolean , but the function expects a string .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() $id is of type string , but the function expects a boolean .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
262 | } |
||
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 ) { |
||
277 | if ( 0 == $blog_id || $blog_id == $this->_blog_id ) { |
||
278 | return $this->_notices; |
||
279 | } |
||
280 | |||
281 | return FS_Admin_Notice_Manager::instance( |
||
282 | $this->_id, |
||
283 | $this->_title, |
||
284 | $this->_module_unique_affix, |
||
285 | false, |
||
286 | $blog_id |
||
0 ignored issues
–
show
$blog_id is of type integer , but the function expects a boolean .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
287 | ); |
||
288 | } |
||
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 ) { |
||
0 ignored issues
–
show
|
|||
302 | if ( ! $this->_is_multisite ) { |
||
303 | // Not a multisite environment. |
||
304 | return false; |
||
305 | } |
||
306 | |||
307 | if ( is_numeric( $network_level_or_blog_id ) ) { |
||
308 | // Explicitly asked to use a specified blog storage. |
||
309 | return false; |
||
310 | } |
||
311 | |||
312 | if ( is_bool( $network_level_or_blog_id ) ) { |
||
313 | // Explicitly specified whether should use the network or blog level storage. |
||
314 | return $network_level_or_blog_id; |
||
315 | } |
||
316 | |||
317 | return fs_is_network_admin(); |
||
318 | } |
||
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.