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.2.1 4.2.2 4.3.0 4.3.1 4.3.2 4.3.3 4.3.4 4.3.5 4.3.6 4.3.7 4.3.8 4.3.9 4.4.0 4.4.1 4.4.10 4.4.11 4.4.12 4.4.2 4.4.3 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9 5.10 5.10.1 5.10.2 5.11 5.11.1 5.11.2 5.11.3 5.11.4 5.12 5.12.1 5.12.2 5.12.3 5.12.4 5.12.5 5.12.6 5.6.10 5.6.2 5.6.3 5.6.4 5.6.5 5.6.6 5.6.7 5.6.8 5.6.9 5.7.0 5.7.1 5.7.10 5.7.12 5.7.13 5.7.2 5.7.3 5.7.4 5.7.5 5.7.6 5.7.7 5.7.8 5.7.9 5.8.0 5.8.1 5.8.10 5.8.11 5.8.12 5.8.13 5.8.14 5.8.2 5.8.3 5.8.4
advanced-custom-fields / includes / fields / class-acf-field-textarea.php
advanced-custom-fields / includes / fields Last commit date
class-acf-field-accordion.php 5 months ago class-acf-field-button-group.php 5 months ago class-acf-field-checkbox.php 2 months ago class-acf-field-color_picker.php 5 months ago class-acf-field-date_picker.php 5 months ago class-acf-field-date_time_picker.php 5 months ago class-acf-field-email.php 5 months ago class-acf-field-file.php 5 months ago class-acf-field-google-map.php 5 months ago class-acf-field-group.php 5 months ago class-acf-field-icon_picker.php 6 months ago class-acf-field-image.php 1 month ago class-acf-field-link.php 5 months ago class-acf-field-message.php 6 months ago class-acf-field-number.php 5 months ago class-acf-field-oembed.php 2 months ago class-acf-field-output.php 6 months ago class-acf-field-page_link.php 1 month ago class-acf-field-password.php 5 months ago class-acf-field-post_object.php 1 month ago class-acf-field-radio.php 2 months ago class-acf-field-range.php 5 months ago class-acf-field-relationship.php 1 month ago class-acf-field-select.php 2 months ago class-acf-field-separator.php 6 months ago class-acf-field-tab.php 6 months ago class-acf-field-taxonomy.php 2 months ago class-acf-field-text.php 5 months ago class-acf-field-textarea.php 5 months ago class-acf-field-time_picker.php 5 months ago class-acf-field-true_false.php 5 months ago class-acf-field-url.php 5 months ago class-acf-field-user.php 2 months ago class-acf-field-wysiwyg.php 5 months ago class-acf-field.php 5 months ago index.php 2 years ago
class-acf-field-textarea.php
265 lines
1 <?php
2 /**
3 * @package ACF
4 * @author WP Engine
5 *
6 * © 2026 Advanced Custom Fields (ACF®). All rights reserved.
7 * "ACF" is a trademark of WP Engine.
8 * Licensed under the GNU General Public License v2 or later.
9 * https://www.gnu.org/licenses/gpl-2.0.html
10 */
11
12 if ( ! class_exists( 'acf_field_textarea' ) ) :
13
14 class acf_field_textarea extends acf_field {
15
16
17 /**
18 * This function will setup the field type data
19 *
20 * @type function
21 * @date 5/03/2014
22 * @since 5.0.0
23 *
24 * @param n/a
25 * @return n/a
26 */
27 function initialize() {
28
29 // vars
30 $this->name = 'textarea';
31 $this->label = __( 'Text Area', 'acf' );
32 $this->description = __( 'A basic textarea input for storing paragraphs of text.', 'acf' );
33 $this->preview_image = acf_get_url() . '/assets/images/field-type-previews/field-preview-textarea.png';
34 $this->doc_url = acf_add_url_utm_tags( 'https://www.advancedcustomfields.com/resources/textarea/', 'docs', 'field-type-selection' );
35 $this->defaults = array(
36 'default_value' => '',
37 'new_lines' => '',
38 'maxlength' => '',
39 'placeholder' => '',
40 'rows' => '',
41 );
42 }
43
44
45 /**
46 * Create the HTML interface for your field
47 *
48 * @param $field - an array holding all the field's data
49 *
50 * @type action
51 * @since 3.6
52 * @date 23/01/13
53 */
54 function render_field( $field ) {
55
56 // vars
57 $atts = array();
58 $keys = array( 'id', 'class', 'name', 'value', 'placeholder', 'rows', 'maxlength' );
59 $keys2 = array( 'readonly', 'disabled', 'required' );
60
61 // rows
62 if ( ! $field['rows'] ) {
63 $field['rows'] = 8;
64 }
65
66 // atts (value="123")
67 foreach ( $keys as $k ) {
68 if ( isset( $field[ $k ] ) ) {
69 $atts[ $k ] = $field[ $k ];
70 }
71 }
72
73 // atts2 (disabled="disabled")
74 foreach ( $keys2 as $k ) {
75 if ( ! empty( $field[ $k ] ) ) {
76 $atts[ $k ] = $k;
77 }
78 }
79
80 // remove empty atts
81 $atts = acf_clean_atts( $atts );
82
83 // return
84 acf_textarea_input( $atts );
85 }
86
87
88 /**
89 * Create extra options for your field. This is rendered when editing a field.
90 * The value of $field['name'] can be used (like bellow) to save extra data to the $field
91 *
92 * @param $field - an array holding all the field's data
93 *
94 * @type action
95 * @since 3.6
96 * @date 23/01/13
97 */
98 function render_field_settings( $field ) {
99 acf_render_field_setting(
100 $field,
101 array(
102 'label' => __( 'Default Value', 'acf' ),
103 'instructions' => __( 'Appears when creating a new post', 'acf' ),
104 'type' => 'textarea',
105 'name' => 'default_value',
106 )
107 );
108 }
109
110 /**
111 * Renders the field settings used in the "Validation" tab.
112 *
113 * @since 6.0
114 *
115 * @param array $field The field settings array.
116 * @return void
117 */
118 function render_field_validation_settings( $field ) {
119 acf_render_field_setting(
120 $field,
121 array(
122 'label' => __( 'Character Limit', 'acf' ),
123 'instructions' => __( 'Leave blank for no limit', 'acf' ),
124 'type' => 'number',
125 'name' => 'maxlength',
126 )
127 );
128 }
129
130 /**
131 * Renders the field settings used in the "Presentation" tab.
132 *
133 * @since 6.0
134 *
135 * @param array $field The field settings array.
136 * @return void
137 */
138 function render_field_presentation_settings( $field ) {
139
140 acf_render_field_setting(
141 $field,
142 array(
143 'label' => __( 'Rows', 'acf' ),
144 'instructions' => __( 'Sets the textarea height', 'acf' ),
145 'type' => 'number',
146 'name' => 'rows',
147 'placeholder' => 8,
148 )
149 );
150
151 acf_render_field_setting(
152 $field,
153 array(
154 'label' => __( 'Placeholder Text', 'acf' ),
155 'instructions' => __( 'Appears within the input', 'acf' ),
156 'type' => 'text',
157 'name' => 'placeholder',
158 )
159 );
160
161 acf_render_field_setting(
162 $field,
163 array(
164 'label' => __( 'New Lines', 'acf' ),
165 'instructions' => __( 'Controls how new lines are rendered', 'acf' ),
166 'type' => 'select',
167 'name' => 'new_lines',
168 'choices' => array(
169 'wpautop' => __( 'Automatically add paragraphs', 'acf' ),
170 'br' => __( 'Automatically add &lt;br&gt;', 'acf' ),
171 '' => __( 'No Formatting', 'acf' ),
172 ),
173 )
174 );
175 }
176
177 /**
178 * This filter is applied to the $value after it is loaded from the db and before it is returned to the template
179 *
180 * @type filter
181 * @since 3.6
182 * @date 23/01/13
183 *
184 * @param $value (mixed) the value which was loaded from the database
185 * @param $post_id (mixed) the post_id from which the value was loaded
186 * @param $field (array) the field array holding all the field options
187 *
188 * @return $value (mixed) the modified value
189 */
190 function format_value( $value, $post_id, $field ) {
191
192 // bail early if no value or not for template
193 if ( empty( $value ) || ! is_string( $value ) ) {
194 return $value;
195 }
196
197 // new lines
198 if ( $field['new_lines'] == 'wpautop' ) {
199 $value = wpautop( $value );
200 } elseif ( $field['new_lines'] == 'br' ) {
201 $value = nl2br( $value );
202 }
203
204 // return
205 return $value;
206 }
207
208 /**
209 * validate_value
210 *
211 * Validates a field's value.
212 *
213 * @date 29/1/19
214 * @since 5.7.11
215 *
216 * @param (bool|string) Whether the value is vaid or not.
217 * @param mixed $value The field value.
218 * @param array $field The field array.
219 * @param string $input The HTML input name.
220 * @return (bool|string)
221 */
222 function validate_value( $valid, $value, $field, $input ) {
223
224 // Check maxlength.
225 if ( $field['maxlength'] && ( acf_strlen( $value ) > $field['maxlength'] ) ) {
226 return sprintf( __( 'Value must not exceed %d characters', 'acf' ), $field['maxlength'] );
227 }
228
229 // Return.
230 return $valid;
231 }
232
233 /**
234 * Return the schema array for the REST API.
235 *
236 * @param array $field
237 * @return array
238 */
239 function get_rest_schema( array $field ) {
240 $schema = parent::get_rest_schema( $field );
241
242 if ( ! empty( $field['maxlength'] ) ) {
243 $schema['maxLength'] = (int) $field['maxlength'];
244 }
245
246 return $schema;
247 }
248
249 /**
250 * Returns an array of JSON-LD Property output types that are supported by this field type.
251 *
252 * @since 6.8
253 *
254 * @return string[]
255 */
256 public function get_jsonld_output_types(): array {
257 return array( 'Text' );
258 }
259 }
260
261
262 // initialize
263 acf_register_field_type( 'acf_field_textarea' );
264 endif; // class_exists check
265