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 |
||
2 | |||
3 | /* |
||
4 | * ACF Admin Update Class |
||
5 | * |
||
6 | * All the logic for updates |
||
7 | * |
||
8 | * @class acf_admin_update |
||
9 | * @package ACF |
||
10 | * @subpackage Admin |
||
11 | */ |
||
12 | |||
13 | if( ! class_exists('acf_admin_update') ) : |
||
14 | |||
15 | class acf_admin_update { |
||
16 | |||
17 | /* |
||
18 | * __construct |
||
19 | * |
||
20 | * A good place to add actions / filters |
||
21 | * |
||
22 | * @type function |
||
23 | * @date 11/08/13 |
||
24 | * |
||
25 | * @param N/A |
||
26 | * @return N/A |
||
27 | */ |
||
0 ignored issues
–
show
|
|||
28 | |||
29 | function __construct() { |
||
0 ignored issues
–
show
|
|||
30 | |||
31 | // actions |
||
32 | add_action('admin_menu', array($this,'admin_menu'), 20); |
||
33 | add_action('network_admin_menu', array($this,'network_admin_menu'), 20); |
||
34 | |||
35 | |||
36 | // ajax |
||
37 | add_action('wp_ajax_acf/admin/data_upgrade', array($this, 'ajax_upgrade')); |
||
38 | |||
39 | } |
||
40 | |||
41 | |||
42 | /* |
||
43 | * network_admin_menu |
||
44 | * |
||
45 | * This function will chck for available updates and add actions if needed |
||
46 | * |
||
47 | * @type function |
||
48 | * @date 2/04/2015 |
||
49 | * @since 5.1.5 |
||
50 | * |
||
51 | * @param n/a |
||
52 | * @return n/a |
||
53 | */ |
||
0 ignored issues
–
show
The doc-type
n/a could not be parsed: Unknown type name "n/a" at position 0. (view supported doc-types)
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types. ![]() |
|||
54 | |||
55 | function network_admin_menu() { |
||
0 ignored issues
–
show
|
|||
56 | |||
57 | // bail early if no show_admin |
||
58 | if( !acf_get_setting('show_admin') ) { |
||
59 | |||
60 | return; |
||
61 | |||
62 | } |
||
63 | |||
64 | |||
65 | // vars |
||
66 | $prompt = false; |
||
67 | |||
68 | |||
69 | // loop through sites and find updates |
||
70 | $sites = wp_get_sites(); |
||
71 | |||
72 | if( $sites ) { |
||
73 | |||
74 | foreach( $sites as $site ) { |
||
75 | |||
76 | // switch blog |
||
77 | switch_to_blog( $site['blog_id'] ); |
||
78 | |||
79 | |||
80 | // get site updates |
||
81 | $updates = acf_get_updates(); |
||
82 | |||
83 | |||
84 | // restore |
||
85 | restore_current_blog(); |
||
86 | |||
87 | |||
88 | if( $updates ) { |
||
89 | |||
90 | $prompt = true; |
||
91 | break; |
||
92 | |||
93 | } |
||
94 | |||
95 | } |
||
96 | |||
97 | } |
||
98 | |||
99 | |||
100 | // bail if no prompt |
||
101 | if( !$prompt ) { |
||
102 | |||
103 | return; |
||
104 | |||
105 | } |
||
106 | |||
107 | |||
108 | // actions |
||
109 | add_action('network_admin_notices', array($this, 'network_admin_notices'), 1); |
||
110 | |||
111 | |||
112 | // add page |
||
113 | add_submenu_page('update-core.php', __('Upgrade ACF','acf'), __('Upgrade ACF','acf'), acf_get_setting('capability'),'acf-upgrade', array($this,'network_html')); |
||
114 | |||
115 | } |
||
116 | |||
117 | |||
118 | /* |
||
119 | * network_admin_notices |
||
120 | * |
||
121 | * This function will render the update notice |
||
122 | * |
||
123 | * @type function |
||
124 | * @date 2/04/2015 |
||
125 | * @since 5.1.5 |
||
126 | * |
||
127 | * @param n/a |
||
128 | * @return n/a |
||
129 | */ |
||
0 ignored issues
–
show
The doc-type
n/a could not be parsed: Unknown type name "n/a" at position 0. (view supported doc-types)
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types. ![]() |
|||
130 | |||
131 | View Code Duplication | function network_admin_notices() { |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
132 | |||
133 | // bail ealry if already on update page |
||
134 | if( acf_is_screen('admin_page_acf-upgrade-network') ) { |
||
135 | |||
136 | return; |
||
137 | |||
138 | } |
||
139 | |||
140 | |||
141 | // view |
||
142 | $view = array( |
||
143 | 'button_text' => __("Review sites & upgrade", 'acf'), |
||
144 | 'button_url' => network_admin_url('update-core.php?page=acf-upgrade'), |
||
145 | 'confirm' => false |
||
146 | ); |
||
147 | |||
148 | |||
149 | // load view |
||
150 | acf_get_view('update-notice', $view); |
||
151 | |||
152 | } |
||
153 | |||
154 | |||
155 | /* |
||
156 | * network_html |
||
157 | * |
||
158 | * This function will render the HTML for the network upgrade page |
||
159 | * |
||
160 | * @type function |
||
161 | * @date 19/02/2014 |
||
162 | * @since 5.0.0 |
||
163 | * |
||
164 | * @param n/a |
||
165 | * @return n/a |
||
166 | */ |
||
0 ignored issues
–
show
The doc-type
n/a could not be parsed: Unknown type name "n/a" at position 0. (view supported doc-types)
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types. ![]() |
|||
167 | |||
168 | function network_html() { |
||
0 ignored issues
–
show
|
|||
169 | |||
170 | // vars |
||
171 | $plugin_version = acf_get_setting('version'); |
||
172 | |||
173 | |||
174 | // loop through sites and find updates |
||
175 | $sites = wp_get_sites(); |
||
176 | |||
177 | if( $sites ) { |
||
178 | |||
179 | foreach( $sites as $i => $site ) { |
||
180 | |||
181 | // switch blog |
||
182 | switch_to_blog( $site['blog_id'] ); |
||
183 | |||
184 | |||
185 | // extra info |
||
186 | $site['name'] = get_bloginfo('name'); |
||
187 | $site['url'] = home_url(); |
||
188 | |||
189 | |||
190 | // get site updates |
||
191 | $site['updates'] = acf_get_updates(); |
||
192 | |||
193 | |||
194 | // get site version |
||
195 | $site['acf_version'] = get_option('acf_version'); |
||
196 | |||
197 | |||
198 | // no value equals new instal |
||
199 | if( !$site['acf_version'] ) { |
||
200 | |||
201 | $site['acf_version'] = $plugin_version; |
||
202 | |||
203 | } |
||
204 | |||
205 | |||
206 | // update |
||
207 | $sites[ $i ] = $site; |
||
208 | |||
209 | |||
210 | // restore |
||
211 | restore_current_blog(); |
||
212 | |||
213 | } |
||
214 | |||
215 | } |
||
216 | |||
217 | |||
218 | // view |
||
219 | $view = array( |
||
220 | 'sites' => $sites, |
||
221 | 'plugin_version' => $plugin_version |
||
222 | ); |
||
223 | |||
224 | |||
225 | // enqueue |
||
226 | acf_enqueue_scripts(); |
||
227 | |||
228 | |||
229 | // load view |
||
230 | acf_get_view('update-network', $view); |
||
231 | |||
232 | } |
||
233 | |||
234 | |||
235 | /* |
||
236 | * admin_menu |
||
237 | * |
||
238 | * This function will chck for available updates and add actions if needed |
||
239 | * |
||
240 | * @type function |
||
241 | * @date 19/02/2014 |
||
242 | * @since 5.0.0 |
||
243 | * |
||
244 | * @param n/a |
||
245 | * @return n/a |
||
246 | */ |
||
0 ignored issues
–
show
The doc-type
n/a could not be parsed: Unknown type name "n/a" at position 0. (view supported doc-types)
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types. ![]() |
|||
247 | |||
248 | function admin_menu() { |
||
0 ignored issues
–
show
|
|||
249 | |||
250 | // vars |
||
251 | $plugin_version = acf_get_setting('version'); |
||
252 | $acf_version = get_option('acf_version'); |
||
253 | |||
254 | |||
255 | // bail early if a new install |
||
256 | if( !$acf_version ) { |
||
257 | |||
258 | update_option('acf_version', $plugin_version ); |
||
259 | return; |
||
260 | |||
261 | } |
||
262 | |||
263 | |||
264 | // bail early if $acf_version is >= $plugin_version |
||
265 | if( version_compare( $acf_version, $plugin_version, '>=') ) { |
||
266 | |||
267 | return; |
||
268 | |||
269 | } |
||
270 | |||
271 | |||
272 | // vars |
||
273 | $updates = acf_get_updates(); |
||
274 | |||
275 | |||
276 | // bail early if no updates available |
||
277 | if( empty($updates) ) { |
||
278 | |||
279 | update_option('acf_version', $plugin_version ); |
||
280 | return; |
||
281 | |||
282 | } |
||
283 | |||
284 | |||
285 | // bail early if no show_admin |
||
286 | if( !acf_get_setting('show_admin') ) { |
||
287 | |||
288 | return; |
||
289 | |||
290 | } |
||
291 | |||
292 | |||
293 | // actions |
||
294 | add_action('admin_notices', array($this, 'admin_notices'), 1); |
||
295 | |||
296 | |||
297 | // add page |
||
298 | add_submenu_page('edit.php?post_type=acf-field-group', __('Upgrade','acf'), __('Upgrade','acf'), acf_get_setting('capability'),'acf-upgrade', array($this,'html') ); |
||
299 | |||
300 | } |
||
301 | |||
302 | |||
303 | /* |
||
304 | * admin_notices |
||
305 | * |
||
306 | * This function will render any admin notices |
||
307 | * |
||
308 | * @type function |
||
309 | * @date 17/10/13 |
||
310 | * @since 5.0.0 |
||
311 | * |
||
312 | * @param n/a |
||
313 | * @return n/a |
||
314 | */ |
||
0 ignored issues
–
show
The doc-type
n/a could not be parsed: Unknown type name "n/a" at position 0. (view supported doc-types)
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types. ![]() |
|||
315 | |||
316 | View Code Duplication | function admin_notices() { |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
317 | |||
318 | // bail ealry if already on update page |
||
319 | if( acf_is_screen('custom-fields_page_acf-upgrade') ) { |
||
320 | |||
321 | return; |
||
322 | |||
323 | } |
||
324 | |||
325 | |||
326 | // view |
||
327 | $view = array( |
||
328 | 'button_text' => __("Upgrade Database", 'acf'), |
||
329 | 'button_url' => admin_url('edit.php?post_type=acf-field-group&page=acf-upgrade') |
||
330 | ); |
||
331 | |||
332 | |||
333 | // load view |
||
334 | acf_get_view('update-notice', $view); |
||
335 | |||
336 | } |
||
337 | |||
338 | |||
339 | /* |
||
340 | * html |
||
341 | * |
||
342 | * description |
||
343 | * |
||
344 | * @type function |
||
345 | * @date 19/02/2014 |
||
346 | * @since 5.0.0 |
||
347 | * |
||
348 | * @param $post_id (int) |
||
349 | * @return $post_id (int) |
||
350 | */ |
||
0 ignored issues
–
show
The doc-type
$post_id could not be parsed: Unknown type name "$post_id" at position 0. (view supported doc-types)
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types. ![]() |
|||
351 | |||
352 | function html() { |
||
0 ignored issues
–
show
|
|||
353 | |||
354 | // view |
||
355 | $view = array( |
||
356 | 'updates' => acf_get_updates(), |
||
357 | 'plugin_version' => acf_get_setting('version') |
||
358 | ); |
||
359 | |||
360 | |||
361 | // enqueue |
||
362 | acf_enqueue_scripts(); |
||
363 | |||
364 | |||
365 | // load view |
||
366 | acf_get_view('update', $view); |
||
367 | |||
368 | } |
||
369 | |||
370 | |||
371 | /* |
||
372 | * ajax_upgrade |
||
373 | * |
||
374 | * description |
||
375 | * |
||
376 | * @type function |
||
377 | * @date 24/10/13 |
||
378 | * @since 5.0.0 |
||
379 | * |
||
380 | * @param $post_id (int) |
||
381 | * @return $post_id (int) |
||
382 | */ |
||
0 ignored issues
–
show
The doc-type
$post_id could not be parsed: Unknown type name "$post_id" at position 0. (view supported doc-types)
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types. ![]() |
|||
383 | |||
384 | function ajax_upgrade() { |
||
0 ignored issues
–
show
|
|||
385 | |||
386 | // options |
||
387 | $options = wp_parse_args( $_POST, array( |
||
388 | 'nonce' => '', |
||
389 | 'blog_id' => '', |
||
390 | )); |
||
391 | |||
392 | |||
393 | // validate |
||
394 | if( !wp_verify_nonce($options['nonce'], 'acf_upgrade') ) { |
||
395 | |||
396 | wp_send_json_error(); |
||
397 | |||
398 | } |
||
399 | |||
400 | |||
401 | // switch blog |
||
402 | if( $options['blog_id'] ) { |
||
403 | |||
404 | switch_to_blog( $options['blog_id'] ); |
||
405 | |||
406 | } |
||
407 | |||
408 | |||
409 | // vars |
||
410 | $updates = acf_get_updates(); |
||
411 | $message = ''; |
||
412 | |||
413 | |||
414 | // bail early if no updates |
||
415 | if( empty($updates) ) { |
||
416 | |||
417 | wp_send_json_error(array( |
||
418 | 'message' => 'No updates available' |
||
419 | )); |
||
420 | |||
421 | } |
||
422 | |||
423 | |||
424 | // install updates |
||
425 | foreach( $updates as $version ) { |
||
0 ignored issues
–
show
The expression
$updates of type false|array is not guaranteed to be traversable. How about adding an additional type check?
There are different options of fixing this problem.
![]() |
|||
426 | |||
427 | // get path |
||
428 | $path = acf_get_path("admin/updates/{$version}.php"); |
||
429 | |||
430 | |||
431 | // load version |
||
432 | if( !file_exists($path) ) { |
||
433 | |||
434 | wp_send_json_error(array( |
||
435 | 'message' => 'Error loading update' |
||
436 | )); |
||
437 | |||
438 | } |
||
439 | |||
440 | |||
441 | // load any errors / feedback from update |
||
442 | ob_start(); |
||
443 | |||
444 | |||
445 | // action for 3rd party |
||
446 | do_action('acf/upgrade_start/' . $version ); |
||
447 | |||
448 | |||
449 | // include |
||
450 | include( $path ); |
||
451 | |||
452 | |||
453 | // action for 3rd party |
||
454 | do_action('acf/upgrade_finish/' . $version ); |
||
455 | |||
456 | |||
457 | // get feedback |
||
458 | $message .= ob_get_clean(); |
||
459 | |||
460 | |||
461 | // update successful |
||
462 | update_option('acf_version', $version ); |
||
463 | |||
464 | } |
||
465 | |||
466 | |||
467 | // updates complete |
||
468 | update_option('acf_version', acf_get_setting('version')); |
||
469 | |||
470 | |||
471 | // return |
||
472 | wp_send_json_success(array( |
||
473 | 'message' => $message |
||
474 | )); |
||
475 | |||
476 | } |
||
477 | |||
478 | |||
479 | /* |
||
480 | * inject_downgrade |
||
481 | * |
||
482 | * description |
||
483 | * |
||
484 | * @type function |
||
485 | * @date 16/01/2014 |
||
486 | * @since 5.0.0 |
||
487 | * |
||
488 | * @param $post_id (int) |
||
489 | * @return $post_id (int) |
||
490 | */ |
||
491 | |||
492 | /* |
||
493 | function inject_downgrade( $transient ) { |
||
494 | |||
495 | // bail early if no plugins are being checked |
||
496 | if( empty($transient->checked) ) { |
||
497 | |||
498 | return $transient; |
||
499 | |||
500 | } |
||
501 | |||
502 | |||
503 | // bail early if no nonce |
||
504 | if( empty($_GET['_acfrollback']) ) { |
||
505 | |||
506 | return $transient; |
||
507 | |||
508 | } |
||
509 | |||
510 | |||
511 | // vars |
||
512 | $rollback = get_option('acf_version'); |
||
513 | |||
514 | |||
515 | // bail early if nonce is not correct |
||
516 | if( !wp_verify_nonce( $_GET['_acfrollback'], 'rollback-acf_' . $rollback ) ) { |
||
517 | |||
518 | return $transient; |
||
519 | |||
520 | } |
||
521 | |||
522 | |||
523 | // create new object for update |
||
524 | $obj = new stdClass(); |
||
525 | $obj->slug = $_GET['plugin']; |
||
526 | $obj->new_version = $rollback; |
||
527 | $obj->url = 'https://wordpress.org/plugins/advanced-custom-fields'; |
||
528 | $obj->package = 'http://downloads.wordpress.org/plugin/advanced-custom-fields.' . $rollback . '.zip';; |
||
529 | |||
530 | |||
531 | // add to transient |
||
532 | $transient->response[ $_GET['plugin'] ] = $obj; |
||
533 | |||
534 | |||
535 | // return |
||
536 | return $transient; |
||
537 | } |
||
538 | */ |
||
539 | |||
540 | } |
||
541 | |||
542 | // initialize |
||
543 | new acf_admin_update(); |
||
544 | |||
545 | endif; |
||
546 | |||
547 | ?> |
||
0 ignored issues
–
show
It is not recommended to use PHP's closing tag
?> in files other than templates.
Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore. A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever. ![]() |
|||
548 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.