Issues (1378)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

includes/acf/admin/settings-tools.php (25 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php 
2
3
class acf_settings_tools {
4
	
5
	var $view = 'settings-tools',
6
		$data = array();
7
	
8
	
9
	/*
10
	*  __construct
11
	*
12
	*  Initialize filters, action, variables and includes
13
	*
14
	*  @type	function
15
	*  @date	23/06/12
16
	*  @since	5.0.0
17
	*
18
	*  @param	n/a
19
	*  @return	n/a
20
	*/
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.

Loading history...
21
	
22
	function __construct() {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
23
	
24
		// actions
25
		add_action('admin_menu', array($this, 'admin_menu'));
26
		
27
	}
28
	
29
	
30
	/*
31
	*  admin_menu
32
	*
33
	*  This function will add the ACF menu item to the WP admin
34
	*
35
	*  @type	action (admin_menu)
36
	*  @date	28/09/13
37
	*  @since	5.0.0
38
	*
39
	*  @param	n/a
40
	*  @return	n/a
41
	*/
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.

Loading history...
42
	
43 View Code Duplication
	function admin_menu() {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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.

Loading history...
44
		
45
		// bail early if no show_admin
46
		if( !acf_get_setting('show_admin') ) {
47
			
48
			return;
49
			
50
		}
51
		
52
		
53
		// add page
54
		$page = add_submenu_page('edit.php?post_type=acf-field-group', __('Tools','acf'), __('Tools','acf'), acf_get_setting('capability'),'acf-settings-tools', array($this,'html') );
55
		
56
		
57
		// actions
58
		add_action('load-' . $page, array($this,'load'));
59
		
60
	}
61
	
62
	
63
	/*
64
	*  load
65
	*
66
	*  This function will look at the $_POST data and run any functions if needed
67
	*
68
	*  @type	function
69
	*  @date	7/01/2014
70
	*  @since	5.0.0
71
	*
72
	*  @param	n/a
73
	*  @return	n/a
74
	*/
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.

Loading history...
75
	
76
	function load() {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
77
		
78
		// all export pages should not load local fields
79
		acf_disable_local();
80
		
81
		
82
		// run import / export
83
		if( acf_verify_nonce('import') ) {
84
			
85
			$this->import();
86
		
87
		} elseif( acf_verify_nonce('export') ) {
88
			
89
			if( isset($_POST['generate']) ) {
90
				
91
				$this->generate();
92
			
93
			} else {
94
				
95
				$this->export();
96
			
97
			}
98
		
99
		}
100
		
101
		
102
		// load acf scripts
103
		acf_enqueue_scripts();
104
		
105
	}
106
	
107
	
108
	/*
109
	*  html
110
	*
111
	*  This function will render the view
112
	*
113
	*  @type	function
114
	*  @date	7/01/2014
115
	*  @since	5.0.0
116
	*
117
	*  @param	n/a
118
	*  @return	n/a
119
	*/
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.

Loading history...
120
	
121
	function html() {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
122
		
123
		// load view
124
		acf_get_view($this->view, $this->data);
125
		
126
	}
127
	
128
	
129
	/*
130
	*  export
131
	*
132
	*  This function will export field groups to a .json file
133
	*
134
	*  @type	function
135
	*  @date	11/03/2014
136
	*  @since	5.0.0
137
	*
138
	*  @param	n/a
139
	*  @return	n/a
140
	*/
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.

Loading history...
141
	
142
	function export() {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
143
		
144
		// vars
145
		$json = $this->get_json();
146
		
147
		
148
		// validate
149
		if( $json === false ) {
150
			
151
			acf_add_admin_notice( __("No field groups selected", 'acf') , 'error');
152
			return;
153
		
154
		}
155
		
156
		
157
		// set headers
158
		$file_name = 'acf-export-' . date('Y-m-d') . '.json';
159
		
160
		header( "Content-Description: File Transfer" );
161
		header( "Content-Disposition: attachment; filename={$file_name}" );
162
		header( "Content-Type: application/json; charset=utf-8" );
163
		
164
		echo acf_json_encode( $json );
165
		die;
166
		
167
	}
168
	
169
	
170
	/*
171
	*  import
172
	*
173
	*  This function will import a .json file of field groups
174
	*
175
	*  @type	function
176
	*  @date	11/03/2014
177
	*  @since	5.0.0
178
	*
179
	*  @param	n/a
180
	*  @return	n/a
181
	*/
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.

Loading history...
182
	
183
	function import() {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
184
		
185
		// validate
186
		if( empty($_FILES['acf_import_file']) ) {
187
			
188
			acf_add_admin_notice( __("No file selected", 'acf') , 'error');
189
			return;
190
		
191
		}
192
		
193
		
194
		// vars
195
		$file = $_FILES['acf_import_file'];
196
		
197
		
198
		// validate error
199
		if( $file['error'] ) {
200
			
201
			acf_add_admin_notice(__('Error uploading file. Please try again', 'acf'), 'error');
202
			return;
203
		
204
		}
205
		
206
		
207
		// validate type
208
		if( pathinfo($file['name'], PATHINFO_EXTENSION) !== 'json' ) {
209
		
210
			acf_add_admin_notice(__('Incorrect file type', 'acf'), 'error');
211
			return;
212
			
213
		}
214
		
215
		
216
		// read file
217
		$json = file_get_contents( $file['tmp_name'] );
218
		
219
		
220
		// decode json
221
		$json = json_decode($json, true);
222
		
223
		
224
		// validate json
225
    	if( empty($json) ) {
226
    	
227
    		acf_add_admin_notice(__('Import file empty', 'acf'), 'error');
228
	    	return;
229
    	
230
    	}
231
    	
232
    	
233
    	// if importing an auto-json, wrap field group in array
234
    	if( isset($json['key']) ) {
235
	    	
236
	    	$json = array( $json );
237
	    	
238
    	}
239
    	
240
    	
241
    	// vars
242
    	$added = array();
243
    	$ignored = array();
244
    	$ref = array();
245
    	$order = array();
246
    	
247
    	foreach( $json as $field_group ) {
248
    		
249
	    	// check if field group exists
250
	    	if( acf_get_field_group($field_group['key'], true) ) {
0 ignored issues
show
The call to acf_get_field_group() has too many arguments starting with true.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
251
	    		
252
	    		// append to ignored
253
	    		$ignored[] = $field_group['title'];
254
	    		continue;
255
	    	
256
	    	}
257
	    	
258
	    	
259
	    	// remove fields
260
			$fields = acf_extract_var($field_group, 'fields');
261
			
262
			
263
			// format fields
264
			$fields = acf_prepare_fields_for_import( $fields );
265
			
266
			
267
			// save field group
268
			$field_group = acf_update_field_group( $field_group );
269
			
270
			
271
			// add to ref
272
			$ref[ $field_group['key'] ] = $field_group['ID'];
273
			
274
			
275
			// add to order
276
			$order[ $field_group['ID'] ] = 0;
277
			
278
			
279
			// add fields
280
			foreach( $fields as $field ) {
281
				
282
				// add parent
283 View Code Duplication
				if( empty($field['parent']) ) {
0 ignored issues
show
This code seems to be duplicated across 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.

Loading history...
284
					
285
					$field['parent'] = $field_group['ID'];
286
					
287
				} elseif( isset($ref[ $field['parent'] ]) ) {
288
					
289
					$field['parent'] = $ref[ $field['parent'] ];
290
						
291
				}
292
				
293
				
294
				// add field menu_order
295
				if( !isset($order[ $field['parent'] ]) ) {
296
					
297
					$order[ $field['parent'] ] = 0;
298
					
299
				}
300
				
301
				$field['menu_order'] = $order[ $field['parent'] ];
302
				$order[ $field['parent'] ]++;
303
				
304
				
305
				// save field
306
				$field = acf_update_field( $field );
0 ignored issues
show
$field is of type array<string,integer,{"menu_order":"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);
Loading history...
307
				
308
				
309
				// add to ref
310
				$ref[ $field['key'] ] = $field['ID'];
311
				
312
			}
313
			
314
			// append to added
315
			$added[] = '<a href="' . admin_url("post.php?post={$field_group['ID']}&action=edit") . '" target="_blank">' . $field_group['title'] . '</a>';
316
			
317
    	}
318
    	
319
    	
320
    	// messages
321 View Code Duplication
    	if( !empty($added) ) {
0 ignored issues
show
This code seems to be duplicated across 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.

Loading history...
322
    		
323
    		$message = __('<b>Success</b>. Import tool added %s field groups: %s', 'acf');
324
    		$message = sprintf( $message, count($added), implode(', ', $added) );
325
    		
326
	    	acf_add_admin_notice( $message );
327
    	
328
    	}
329
    	
330 View Code Duplication
    	if( !empty($ignored) ) {
0 ignored issues
show
This code seems to be duplicated across 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.

Loading history...
331
    		
332
    		$message = __('<b>Warning</b>. Import tool detected %s field groups already exist and have been ignored: %s', 'acf');
333
    		$message = sprintf( $message, count($ignored), implode(', ', $ignored) );
334
    		
335
	    	acf_add_admin_notice( $message, 'error' );
336
    	
337
    	}
338
    	
339
		
340
	}
341
	
342
	
343
	/*
344
	*  generate
345
	*
346
	*  This function will generate PHP code to include in your theme
347
	*
348
	*  @type	function
349
	*  @date	11/03/2014
350
	*  @since	5.0.0
351
	*
352
	*  @param	n/a
353
	*  @return	n/a
354
	*/
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.

Loading history...
355
	
356
	function generate() {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
357
		
358
		// translate
359
		if( acf_get_setting('l10n_textdomain') ) {
360
			
361
			// prevent default translation
362
			acf_update_setting('l10n_var_export', true);
363
						
364
			
365
			// filters
366
			add_filter('acf/prepare_field_group_for_export', 	array($this, '_translate_field_group'));
367
			add_filter('acf/prepare_field_for_export', 			array($this, '_translate_field'));
368
		
369
		}
370
		
371
		
372
		// vars
373
		$json = $this->get_json();
374
		
375
		
376
		// validate
377
		if( $json === false ) {
378
			
379
			acf_add_admin_notice( __("No field groups selected", 'acf') , 'error');
380
			return;
381
		
382
		}
383
		
384
				
385
		// update view
386
		$this->view = 'settings-tools-export';
387
		$this->data['field_groups'] = $json;
388
		
389
	}
390
	
391
	function _translate_field( $field ) {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
392
		
393
		return acf_translate_keys($field, acf_get_setting('l10n_field'));
394
		
395
	}
396
	
397
	function _translate_field_group( $field_group ) {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
398
		
399
		return acf_translate_keys($field_group, acf_get_setting('l10n_field_group'));
400
		
401
	}
402
	
403
	
404
	/*
405
	*  get_json
406
	*
407
	*  This function will return the JSON data for given $_POST args
408
	*
409
	*  @type	function
410
	*  @date	3/02/2015
411
	*  @since	5.1.5
412
	*
413
	*  @param	$post_id (int)
414
	*  @return	$post_id (int)
415
	*/
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.

Loading history...
416
	
417
	function get_json() {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
418
		
419
		// validate
420
		if( empty($_POST['acf_export_keys']) ) {
421
			
422
			return false;
423
				
424
		}
425
		
426
		
427
		// vars
428
		$json = array();
429
		
430
		
431
		// construct JSON
432
		foreach( $_POST['acf_export_keys'] as $key ) {
433
			
434
			// load field group
435
			$field_group = acf_get_field_group( $key );
436
			
437
			
438
			// validate field group
439
			if( empty($field_group) ) continue;
440
			
441
			
442
			// load fields
443
			$field_group['fields'] = acf_get_fields( $field_group );
444
	
445
	
446
			// prepare for export
447
			$field_group = acf_prepare_field_group_for_export( $field_group );
448
			
449
			
450
			// add to json array
451
			$json[] = $field_group;
452
			
453
		}
454
		
455
		
456
		// return
457
		return $json;
458
		
459
	}
460
	
461
}
462
463
464
// initialize
465
new acf_settings_tools();
466
467
?>
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.

Loading history...
468