acf_field_email::render_field()   A
last analyzed

Complexity

Conditions 4
Paths 8

Size

Total Lines 43

Duplication

Lines 12
Ratio 27.91 %

Importance

Changes 0
Metric Value
cc 4
nc 8
nop 1
dl 12
loc 43
rs 9.232
c 0
b 0
f 0
1
<?php
2
3
/*
4
*  ACF Email Field Class
5
*
6
*  All the logic for this field type
7
*
8
*  @class 		acf_field_email
9
*  @extends		acf_field
10
*  @package		ACF
11
*  @subpackage	Fields
12
*/
13
14
if( ! class_exists('acf_field_email') ) :
15
16
class acf_field_email 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
Documentation introduced by
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
Best Practice introduced by
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...
Duplication introduced by
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 = 'email';
36
		$this->label = __("Email",'acf');
0 ignored issues
show
Bug introduced by
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->defaults = array(
38
			'default_value'	=> '',
39
			'placeholder'	=> '',
40
			'prepend'		=> '',
41
			'append'		=> ''
42
		);
43
		
44
		
45
		// do not delete!
46
    	parent::__construct();
47
	}
48
		
49
	
50
	/*
51
	*  render_field()
52
	*
53
	*  Create the HTML interface for your field
54
	*
55
	*  @param	$field - an array holding all the field's data
56
	*
57
	*  @type	action
58
	*  @since	3.6
59
	*  @date	23/01/13
60
	*/
61
	
62
	function render_field( $field ) {
0 ignored issues
show
Best Practice introduced by
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...
63
		
64
		// vars
65
		$o = array( 'type', 'id', 'class', 'name', 'value', 'placeholder' );
66
		$e = '';
67
		
68
		
69
		// prepend
70 View Code Duplication
		if( $field['prepend'] !== "" ) {
0 ignored issues
show
Duplication introduced by
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...
71
		
72
			$field['class'] .= ' acf-is-prepended';
73
			$e .= '<div class="acf-input-prepend">' . $field['prepend'] . '</div>';
74
			
75
		}
76
		
77
		
78
		// append
79 View Code Duplication
		if( $field['append'] !== "" ) {
0 ignored issues
show
Duplication introduced by
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...
80
		
81
			$field['class'] .= ' acf-is-appended';
82
			$e .= '<div class="acf-input-append">' . $field['append'] . '</div>';
83
			
84
		}
85
		
86
		
87
		// populate atts
88
		$atts = array();
89
		foreach( $o as $k ) {
90
		
91
			$atts[ $k ] = $field[ $k ];	
92
			
93
		}
94
		
95
		
96
		// render
97
		$e .= '<div class="acf-input-wrap">';
98
		$e .= '<input ' . acf_esc_attr( $atts ) . ' />';
99
		$e .= '</div>';
100
		
101
		
102
		// return
103
		echo $e;
104
	}
105
	
106
	
107
	/*
108
	*  render_field_settings()
109
	*
110
	*  Create extra options for your field. This is rendered when editing a field.
111
	*  The value of $field['name'] can be used (like bellow) to save extra data to the $field
112
	*
113
	*  @type	action
114
	*  @since	3.6
115
	*  @date	23/01/13
116
	*
117
	*  @param	$field	- an array holding all the field's data
118
	*/
119
	
120
	function render_field_settings( $field ) {
0 ignored issues
show
Best Practice introduced by
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...
121
		
122
		// default_value
123
		acf_render_field_setting( $field, array(
124
			'label'			=> __('Default Value','acf'),
125
			'instructions'	=> __('Appears when creating a new post','acf'),
126
			'type'			=> 'text',
127
			'name'			=> 'default_value',
128
		));
129
		
130
		
131
		// placeholder
132
		acf_render_field_setting( $field, array(
133
			'label'			=> __('Placeholder Text','acf'),
134
			'instructions'	=> __('Appears within the input','acf'),
135
			'type'			=> 'text',
136
			'name'			=> 'placeholder',
137
		));
138
		
139
		
140
		// prepend
141
		acf_render_field_setting( $field, array(
142
			'label'			=> __('Prepend','acf'),
143
			'instructions'	=> __('Appears before the input','acf'),
144
			'type'			=> 'text',
145
			'name'			=> 'prepend',
146
		));
147
		
148
		
149
		// append
150
		acf_render_field_setting( $field, array(
151
			'label'			=> __('Append','acf'),
152
			'instructions'	=> __('Appears after the input','acf'),
153
			'type'			=> 'text',
154
			'name'			=> 'append',
155
		));
156
157
	}	
158
	
159
}
160
161
new acf_field_email();
162
163
endif;
164
165
?>
0 ignored issues
show
Best Practice introduced by
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...
166