1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* ACF Text Area Field Class |
5
|
|
|
* |
6
|
|
|
* All the logic for this field type |
7
|
|
|
* |
8
|
|
|
* @class acf_field_textarea |
9
|
|
|
* @extends acf_field |
10
|
|
|
* @package ACF |
11
|
|
|
* @subpackage Fields |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
if( ! class_exists('acf_field_textarea') ) : |
15
|
|
|
|
16
|
|
|
class acf_field_textarea 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 = 'textarea'; |
36
|
|
|
$this->label = __("Text Area",'acf'); |
|
|
|
|
37
|
|
|
$this->defaults = array( |
38
|
|
|
'default_value' => '', |
39
|
|
|
'new_lines' => '', |
40
|
|
|
'maxlength' => '', |
41
|
|
|
'placeholder' => '', |
42
|
|
|
'readonly' => 0, |
43
|
|
|
'disabled' => 0, |
44
|
|
|
'rows' => '' |
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( 'id', 'class', 'name', 'placeholder', 'rows' ); |
69
|
|
|
$s = array( 'readonly', 'disabled' ); |
70
|
|
|
$e = ''; |
71
|
|
|
|
72
|
|
|
|
73
|
|
|
// maxlength |
74
|
|
|
if( $field['maxlength'] !== '' ) { |
75
|
|
|
|
76
|
|
|
$o[] = 'maxlength'; |
77
|
|
|
|
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
|
81
|
|
|
// rows |
82
|
|
|
if( empty($field['rows']) ) { |
83
|
|
|
|
84
|
|
|
$field['rows'] = 8; |
85
|
|
|
|
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
|
89
|
|
|
// populate atts |
90
|
|
|
$atts = array(); |
91
|
|
|
foreach( $o as $k ) { |
92
|
|
|
|
93
|
|
|
$atts[ $k ] = $field[ $k ]; |
94
|
|
|
|
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
|
98
|
|
|
// special atts |
99
|
|
|
foreach( $s as $k ) { |
100
|
|
|
|
101
|
|
|
if( $field[ $k ] ) { |
102
|
|
|
|
103
|
|
|
$atts[ $k ] = $k; |
104
|
|
|
|
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
|
110
|
|
|
$e .= '<textarea ' . acf_esc_attr( $atts ) . ' >'; |
111
|
|
|
$e .= esc_textarea( $field['value'] ); |
112
|
|
|
$e .= '</textarea>'; |
113
|
|
|
|
114
|
|
|
|
115
|
|
|
// return |
116
|
|
|
echo $e; |
117
|
|
|
|
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/* |
121
|
|
|
* render_field_settings() |
122
|
|
|
* |
123
|
|
|
* Create extra options for your field. This is rendered when editing a field. |
124
|
|
|
* The value of $field['name'] can be used (like bellow) to save extra data to the $field |
125
|
|
|
* |
126
|
|
|
* @param $field - an array holding all the field's data |
127
|
|
|
* |
128
|
|
|
* @type action |
129
|
|
|
* @since 3.6 |
130
|
|
|
* @date 23/01/13 |
131
|
|
|
*/ |
132
|
|
|
|
133
|
|
|
function render_field_settings( $field ) { |
|
|
|
|
134
|
|
|
|
135
|
|
|
// ACF4 migration |
136
|
|
|
if( empty($field['ID']) ) { |
137
|
|
|
|
138
|
|
|
$field['new_lines'] = 'wpautop'; |
139
|
|
|
|
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
|
143
|
|
|
// default_value |
144
|
|
|
acf_render_field_setting( $field, array( |
145
|
|
|
'label' => __('Default Value','acf'), |
146
|
|
|
'instructions' => __('Appears when creating a new post','acf'), |
147
|
|
|
'type' => 'textarea', |
148
|
|
|
'name' => 'default_value', |
149
|
|
|
)); |
150
|
|
|
|
151
|
|
|
|
152
|
|
|
// placeholder |
153
|
|
|
acf_render_field_setting( $field, array( |
154
|
|
|
'label' => __('Placeholder Text','acf'), |
155
|
|
|
'instructions' => __('Appears within the input','acf'), |
156
|
|
|
'type' => 'text', |
157
|
|
|
'name' => 'placeholder', |
158
|
|
|
)); |
159
|
|
|
|
160
|
|
|
|
161
|
|
|
// maxlength |
162
|
|
|
acf_render_field_setting( $field, array( |
163
|
|
|
'label' => __('Character Limit','acf'), |
164
|
|
|
'instructions' => __('Leave blank for no limit','acf'), |
165
|
|
|
'type' => 'number', |
166
|
|
|
'name' => 'maxlength', |
167
|
|
|
)); |
168
|
|
|
|
169
|
|
|
|
170
|
|
|
// rows |
171
|
|
|
acf_render_field_setting( $field, array( |
172
|
|
|
'label' => __('Rows','acf'), |
173
|
|
|
'instructions' => __('Sets the textarea height','acf'), |
174
|
|
|
'type' => 'number', |
175
|
|
|
'name' => 'rows', |
176
|
|
|
'placeholder' => 8 |
177
|
|
|
)); |
178
|
|
|
|
179
|
|
|
|
180
|
|
|
// formatting |
181
|
|
|
acf_render_field_setting( $field, array( |
182
|
|
|
'label' => __('New Lines','acf'), |
183
|
|
|
'instructions' => __('Controls how new lines are rendered','acf'), |
184
|
|
|
'type' => 'select', |
185
|
|
|
'name' => 'new_lines', |
186
|
|
|
'choices' => array( |
187
|
|
|
'wpautop' => __("Automatically add paragraphs",'acf'), |
188
|
|
|
'br' => __("Automatically add <br>",'acf'), |
189
|
|
|
'' => __("No Formatting",'acf') |
190
|
|
|
) |
191
|
|
|
)); |
192
|
|
|
|
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
|
196
|
|
|
/* |
197
|
|
|
* format_value() |
198
|
|
|
* |
199
|
|
|
* This filter is applied to the $value after it is loaded from the db and before it is returned to the template |
200
|
|
|
* |
201
|
|
|
* @type filter |
202
|
|
|
* @since 3.6 |
203
|
|
|
* @date 23/01/13 |
204
|
|
|
* |
205
|
|
|
* @param $value (mixed) the value which was loaded from the database |
206
|
|
|
* @param $post_id (mixed) the $post_id from which the value was loaded |
207
|
|
|
* @param $field (array) the field array holding all the field options |
208
|
|
|
* |
209
|
|
|
* @return $value (mixed) the modified value |
210
|
|
|
*/ |
|
|
|
|
211
|
|
|
|
212
|
|
|
function format_value( $value, $post_id, $field ) { |
|
|
|
|
213
|
|
|
|
214
|
|
|
// bail early if no value or not for template |
215
|
|
|
if( empty($value) || !is_string($value) ) { |
216
|
|
|
|
217
|
|
|
return $value; |
218
|
|
|
|
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
|
222
|
|
|
// new lines |
223
|
|
View Code Duplication |
if( $field['new_lines'] == 'wpautop' ) { |
|
|
|
|
224
|
|
|
|
225
|
|
|
$value = wpautop($value); |
226
|
|
|
|
227
|
|
|
} elseif( $field['new_lines'] == 'br' ) { |
228
|
|
|
|
229
|
|
|
$value = nl2br($value); |
230
|
|
|
|
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
|
234
|
|
|
// return |
235
|
|
|
return $value; |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
new acf_field_textarea(); |
241
|
|
|
|
242
|
|
|
endif; |
243
|
|
|
|
244
|
|
|
?> |
|
|
|
|
245
|
|
|
|
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.