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/fields/radio.php (21 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
/*
4
*  ACF Radio Button Field Class
5
*
6
*  All the logic for this field type
7
*
8
*  @class 		acf_field_radio
9
*  @extends		acf_field
10
*  @package		ACF
11
*  @subpackage	Fields
12
*/
13
14
if( ! class_exists('acf_field_radio') ) :
15
16
class acf_field_radio extends acf_field {
17
	
18
	
19
	/*
20
	*  __construct
21
	*
22
	*  This function will setup the field type data
23
	*
24
	*  @type	function
25
	*  @date	5/03/2014
26
	*  @since	5.0.0
27
	*
28
	*  @param	n/a
29
	*  @return	n/a
30
	*/
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...
31
	
32 View Code Duplication
	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...
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...
33
		
34
		// vars
35
		$this->name = 'radio';
36
		$this->label = __("Radio Button",'acf');
0 ignored issues
show
The property label does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
37
		$this->category = 'choice';
38
		$this->defaults = array(
39
			'layout'			=> 'vertical',
40
			'choices'			=> array(),
41
			'default_value'		=> '',
42
			'other_choice'		=> 0,
43
			'save_other_choice'	=> 0,
44
		);
45
		
46
		
47
		// do not delete!
48
    	parent::__construct();
49
		
50
	}
51
	
52
		
53
	/*
54
	*  render_field()
55
	*
56
	*  Create the HTML interface for your field
57
	*
58
	*  @param	$field (array) the $field being rendered
59
	*
60
	*  @type	action
61
	*  @since	3.6
62
	*  @date	23/01/13
63
	*
64
	*  @param	$field (array) the $field being edited
65
	*  @return	n/a
66
	*/
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...
67
	
68
	function render_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...
69
		
70
		// vars
71
		$i = 0;
72
		$checked = false;
0 ignored issues
show
$checked is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
73
		
74
		
75
		// class
76
		$field['class'] .= ' acf-radio-list';
77
		$field['class'] .= ($field['layout'] == 'horizontal') ? ' acf-hl' : ' acf-bl';
78
79
		
80
		// e
81
		$e = '<ul ' . acf_esc_attr(array( 'class' => $field['class'] )) . '>';
82
		
83
		
84
		// other choice
85
		if( $field['other_choice'] ) {
86
			
87
			// vars
88
			$input = array(
89
				'type'		=> 'text',
90
				'name'		=> $field['name'],
91
				'value'		=> '',
92
				'disabled'	=> 'disabled'
93
			);
94
			
95
			
96
			// select other choice if value is not a valid choice
97
			if( !isset($field['choices'][ $field['value'] ]) ) {
98
				
99
				unset($input['disabled']);
100
				$input['value'] = $field['value'];
101
				$field['value'] = 'other';
102
				
103
			}
104
			
105
			
106
			$field['choices']['other'] = '</label><input type="text" ' . acf_esc_attr($input) . ' /><label>';
107
		
108
		}
109
		
110
		
111
		// require choices
112
		if( !empty($field['choices']) ) {
113
			
114
			// select first choice if value is not a valid choice
115 View Code Duplication
			if( !isset($field['choices'][ $field['value'] ]) ) {
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...
116
				
117
				$field['value'] = key($field['choices']);
118
				
119
			}
120
			
121
			
122
			// foreach choices
123 View Code Duplication
			foreach( $field['choices'] as $value => $label ) {
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...
124
				
125
				// increase counter
126
				$i++;
127
				
128
				
129
				// vars
130
				$atts = array(
131
					'type'	=> 'radio',
132
					'id'	=> $field['id'], 
133
					'name'	=> $field['name'],
134
					'value'	=> $value,
135
				);
136
				
137
				
138
				if( strval($value) === strval($field['value']) ) {
139
					
140
					$atts['checked'] = 'checked';
141
					$checked = true;
0 ignored issues
show
$checked is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
142
					
143
				}
144
				
145
				if( isset($field['disabled']) && acf_in_array($value, $field['disabled']) ) {
146
				
147
					$atts['disabled'] = 'disabled';
148
					
149
				}
150
				
151
				
152
				// each input ID is generated with the $key, however, the first input must not use $key so that it matches the field's label for attribute
153
				if( $i > 1 ) {
154
				
155
					$atts['id'] .= '-' . $value;
156
					
157
				}
158
				
159
				$e .= '<li><label><input ' . acf_esc_attr( $atts ) . '/>' . $label . '</label></li>';
160
			}
161
		
162
		}
163
		
164
165
		$e .= '</ul>';
166
		
167
		echo $e;
168
		
169
	}
170
	
171
	
172
	/*
173
	*  render_field_settings()
174
	*
175
	*  Create extra options for your field. This is rendered when editing a field.
176
	*  The value of $field['name'] can be used (like bellow) to save extra data to the $field
177
	*
178
	*  @type	action
179
	*  @since	3.6
180
	*  @date	23/01/13
181
	*
182
	*  @param	$field	- an array holding all the field's data
183
	*/
184
	
185
	function render_field_settings( $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...
186
		
187
		// encode choices (convert from array)
188
		$field['choices'] = acf_encode_choices($field['choices']);
189
		
190
		
191
		// choices
192
		acf_render_field_setting( $field, array(
193
			'label'			=> __('Choices','acf'),
194
			'instructions'	=> __('Enter each choice on a new line.','acf') . '<br /><br />' . __('For more control, you may specify both a value and label like this:','acf'). '<br /><br />' . __('red : Red','acf'),
195
			'type'			=> 'textarea',
196
			'name'			=> 'choices',
197
		));
198
		
199
		
200
		// other_choice
201
		acf_render_field_setting( $field, array(
202
			'label'			=> __('Other','acf'),
203
			'instructions'	=> '',
204
			'type'			=> 'true_false',
205
			'name'			=> 'other_choice',
206
			'message'		=> __("Add 'other' choice to allow for custom values", 'acf')
207
		));
208
		
209
		
210
		// save_other_choice
211
		acf_render_field_setting( $field, array(
212
			'label'			=> __('Save Other','acf'),
213
			'instructions'	=> '',
214
			'type'			=> 'true_false',
215
			'name'			=> 'save_other_choice',
216
			'message'		=> __("Save 'other' values to the field's choices", 'acf')
217
		));
218
		
219
		
220
		// default_value
221
		acf_render_field_setting( $field, array(
222
			'label'			=> __('Default Value','acf'),
223
			'instructions'	=> __('Appears when creating a new post','acf'),
224
			'type'			=> 'text',
225
			'name'			=> 'default_value',
226
		));
227
		
228
		
229
		// layout
230
		acf_render_field_setting( $field, array(
231
			'label'			=> __('Layout','acf'),
232
			'instructions'	=> '',
233
			'type'			=> 'radio',
234
			'name'			=> 'layout',
235
			'layout'		=> 'horizontal', 
236
			'choices'		=> array(
237
				'vertical'		=> __("Vertical",'acf'), 
238
				'horizontal'	=> __("Horizontal",'acf')
239
			)
240
		));
241
		
242
		
243
	}
244
	
245
	
246
	/*
247
	*  update_field()
248
	*
249
	*  This filter is appied to the $field before it is saved to the database
250
	*
251
	*  @type	filter
252
	*  @since	3.6
253
	*  @date	23/01/13
254
	*
255
	*  @param	$field - the field array holding all the field options
256
	*  @param	$post_id - the field group ID (post_type = acf)
257
	*
258
	*  @return	$field - the modified field
259
	*/
0 ignored issues
show
The doc-type $field could not be parsed: Unknown type name "$field" 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...
260
261
	function update_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...
262
		
263
		// decode choices (convert to array)
264
		$field['choices'] = acf_decode_choices($field['choices']);
265
		
266
		
267
		// return
268
		return $field;
269
	}
270
	
271
	
272
	/*
273
	*  update_value()
274
	*
275
	*  This filter is appied to the $value before it is updated in the db
276
	*
277
	*  @type	filter
278
	*  @since	3.6
279
	*  @date	23/01/13
280
	*  @todo	Fix bug where $field was found via json and has no ID
281
	*
282
	*  @param	$value - the value which will be saved in the database
283
	*  @param	$post_id - the $post_id of which the value will be saved
284
	*  @param	$field - the field array holding all the field options
285
	*
286
	*  @return	$value - the modified value
287
	*/
0 ignored issues
show
The doc-type $value could not be parsed: Unknown type name "$value" 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...
288
	
289
	function update_value( $value, $post_id, $field ) {
0 ignored issues
show
The parameter $post_id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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...
290
		
291
		// save_other_choice
292
		if( $field['save_other_choice'] ) {
293
			
294
			// value isn't in choices yet
295
			if( !isset($field['choices'][ $value ]) ) {
296
				
297
				// get ID if local
298
				if( !$field['ID'] ) {
299
					
300
					$field = acf_get_field( $field['key'], true );
301
					
302
				}
303
				
304
				
305
				// bail early if no ID
306
				if( !$field['ID'] ) {
307
					
308
					return $value;
309
					
310
				}
311
				
312
				
313
				// update $field
314
				$field['choices'][ $value ] = $value;
315
				
316
				
317
				// save
318
				acf_update_field( $field );
319
				
320
			}
321
			
322
		}		
323
		
324
		
325
		// return
326
		return $value;
327
	}
328
	
329
	
330
	/*
331
	*  load_value()
332
	*
333
	*  This filter is appied to the $value after it is loaded from the db
334
	*
335
	*  @type	filter
336
	*  @since	5.2.9
337
	*  @date	23/01/13
338
	*
339
	*  @param	$value - the value found in the database
340
	*  @param	$post_id - the $post_id from which the value was loaded from
341
	*  @param	$field - the field array holding all the field options
342
	*
343
	*  @return	$value - the value to be saved in te database
344
	*/
0 ignored issues
show
The doc-type $value could not be parsed: Unknown type name "$value" 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...
345
	
346
	function load_value( $value, $post_id, $field ) {
0 ignored issues
show
The parameter $post_id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $field is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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...
347
		
348
		// must be single value
349
		if( is_array($value) ) {
350
			
351
			$value = array_pop($value);
352
			
353
		}
354
		
355
		
356
		// return
357
		return $value;
358
		
359
	}
360
	
361
}
362
363
new acf_field_radio();
364
365
endif;
366
367
?>
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...
368