|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* ACF Text Field Class |
|
5
|
|
|
* |
|
6
|
|
|
* All the logic for this field type |
|
7
|
|
|
* |
|
8
|
|
|
* @class acf_field_text |
|
9
|
|
|
* @extends acf_field |
|
10
|
|
|
* @package ACF |
|
11
|
|
|
* @subpackage Fields |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
if( ! class_exists('acf_field_text') ) : |
|
15
|
|
|
|
|
16
|
|
|
class acf_field_text 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
|
|
|
*/ |
|
|
|
|
|
|
31
|
|
|
|
|
32
|
|
View Code Duplication |
function __construct() { |
|
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
// vars |
|
35
|
|
|
$this->name = 'text'; |
|
36
|
|
|
$this->label = __("Text",'acf'); |
|
|
|
|
|
|
37
|
|
|
$this->defaults = array( |
|
38
|
|
|
'default_value' => '', |
|
39
|
|
|
'maxlength' => '', |
|
40
|
|
|
'placeholder' => '', |
|
41
|
|
|
'prepend' => '', |
|
42
|
|
|
'append' => '', |
|
43
|
|
|
'readonly' => 0, |
|
44
|
|
|
'disabled' => 0, |
|
45
|
|
|
); |
|
46
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
// do not delete! |
|
49
|
|
|
parent::__construct(); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
/* |
|
54
|
|
|
* render_field() |
|
55
|
|
|
* |
|
56
|
|
|
* Create the HTML interface for your field |
|
57
|
|
|
* |
|
58
|
|
|
* @param $field - an array holding all the field's data |
|
59
|
|
|
* |
|
60
|
|
|
* @type action |
|
61
|
|
|
* @since 3.6 |
|
62
|
|
|
* @date 23/01/13 |
|
63
|
|
|
*/ |
|
64
|
|
|
|
|
65
|
|
|
function render_field( $field ) { |
|
|
|
|
|
|
66
|
|
|
|
|
67
|
|
|
// vars |
|
68
|
|
|
$o = array( 'type', 'id', 'class', 'name', 'value', 'placeholder' ); |
|
69
|
|
|
$s = array( 'readonly', 'disabled' ); |
|
70
|
|
|
$e = ''; |
|
71
|
|
|
|
|
72
|
|
|
|
|
73
|
|
|
// maxlength |
|
74
|
|
|
if( $field['maxlength'] !== "" ) { |
|
75
|
|
|
|
|
76
|
|
|
$o[] = 'maxlength'; |
|
77
|
|
|
|
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
|
|
81
|
|
|
// prepend |
|
82
|
|
View Code Duplication |
if( $field['prepend'] !== "" ) { |
|
|
|
|
|
|
83
|
|
|
|
|
84
|
|
|
$field['class'] .= ' acf-is-prepended'; |
|
85
|
|
|
$e .= '<div class="acf-input-prepend">' . $field['prepend'] . '</div>'; |
|
86
|
|
|
|
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
|
|
90
|
|
|
// append |
|
91
|
|
View Code Duplication |
if( $field['append'] !== "" ) { |
|
|
|
|
|
|
92
|
|
|
|
|
93
|
|
|
$field['class'] .= ' acf-is-appended'; |
|
94
|
|
|
$e .= '<div class="acf-input-append">' . $field['append'] . '</div>'; |
|
95
|
|
|
|
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
|
|
99
|
|
|
// populate atts |
|
100
|
|
|
$atts = array(); |
|
101
|
|
|
foreach( $o as $k ) { |
|
102
|
|
|
|
|
103
|
|
|
$atts[ $k ] = $field[ $k ]; |
|
104
|
|
|
|
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
|
|
108
|
|
|
// special atts |
|
109
|
|
|
foreach( $s as $k ) { |
|
110
|
|
|
|
|
111
|
|
|
if( $field[ $k ] ) { |
|
112
|
|
|
|
|
113
|
|
|
$atts[ $k ] = $k; |
|
114
|
|
|
|
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
|
|
120
|
|
|
// render |
|
121
|
|
|
$e .= '<div class="acf-input-wrap">'; |
|
122
|
|
|
$e .= '<input ' . acf_esc_attr( $atts ) . ' />'; |
|
123
|
|
|
$e .= '</div>'; |
|
124
|
|
|
|
|
125
|
|
|
|
|
126
|
|
|
// return |
|
127
|
|
|
echo $e; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
|
|
131
|
|
|
/* |
|
132
|
|
|
* render_field_settings() |
|
133
|
|
|
* |
|
134
|
|
|
* Create extra options for your field. This is rendered when editing a field. |
|
135
|
|
|
* The value of $field['name'] can be used (like bellow) to save extra data to the $field |
|
136
|
|
|
* |
|
137
|
|
|
* @param $field - an array holding all the field's data |
|
138
|
|
|
* |
|
139
|
|
|
* @type action |
|
140
|
|
|
* @since 3.6 |
|
141
|
|
|
* @date 23/01/13 |
|
142
|
|
|
*/ |
|
143
|
|
|
|
|
144
|
|
|
function render_field_settings( $field ) { |
|
|
|
|
|
|
145
|
|
|
|
|
146
|
|
|
// default_value |
|
147
|
|
|
acf_render_field_setting( $field, array( |
|
148
|
|
|
'label' => __('Default Value','acf'), |
|
149
|
|
|
'instructions' => __('Appears when creating a new post','acf'), |
|
150
|
|
|
'type' => 'text', |
|
151
|
|
|
'name' => 'default_value', |
|
152
|
|
|
)); |
|
153
|
|
|
|
|
154
|
|
|
|
|
155
|
|
|
// placeholder |
|
156
|
|
|
acf_render_field_setting( $field, array( |
|
157
|
|
|
'label' => __('Placeholder Text','acf'), |
|
158
|
|
|
'instructions' => __('Appears within the input','acf'), |
|
159
|
|
|
'type' => 'text', |
|
160
|
|
|
'name' => 'placeholder', |
|
161
|
|
|
)); |
|
162
|
|
|
|
|
163
|
|
|
|
|
164
|
|
|
// prepend |
|
165
|
|
|
acf_render_field_setting( $field, array( |
|
166
|
|
|
'label' => __('Prepend','acf'), |
|
167
|
|
|
'instructions' => __('Appears before the input','acf'), |
|
168
|
|
|
'type' => 'text', |
|
169
|
|
|
'name' => 'prepend', |
|
170
|
|
|
)); |
|
171
|
|
|
|
|
172
|
|
|
|
|
173
|
|
|
// append |
|
174
|
|
|
acf_render_field_setting( $field, array( |
|
175
|
|
|
'label' => __('Append','acf'), |
|
176
|
|
|
'instructions' => __('Appears after the input','acf'), |
|
177
|
|
|
'type' => 'text', |
|
178
|
|
|
'name' => 'append', |
|
179
|
|
|
)); |
|
180
|
|
|
|
|
181
|
|
|
|
|
182
|
|
|
// maxlength |
|
183
|
|
|
acf_render_field_setting( $field, array( |
|
184
|
|
|
'label' => __('Character Limit','acf'), |
|
185
|
|
|
'instructions' => __('Leave blank for no limit','acf'), |
|
186
|
|
|
'type' => 'number', |
|
187
|
|
|
'name' => 'maxlength', |
|
188
|
|
|
)); |
|
189
|
|
|
|
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
new acf_field_text(); |
|
195
|
|
|
|
|
196
|
|
|
endif; |
|
197
|
|
|
|
|
198
|
|
|
?> |
|
|
|
|
|
|
199
|
|
|
|
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.