PluginProbe ʕ •ᴥ•ʔ
Secure Custom Fields / 6.4.0-beta2
Secure Custom Fields v6.4.0-beta2
6.9.5 6.9.4 6.9.3 6.9.2 6.9.1 6.9.0 6.8.9 6.8.7 6.8.8 6.8.6 6.8.4 6.8.5 trunk 6.4.0-beta1 6.4.0-beta2 6.4.1 6.4.1-beta3 6.4.1-beta4 6.4.1-beta5 6.4.1-beta6 6.4.1-beta7 6.4.2 6.5.0 6.5.1 6.5.2 6.5.3 6.5.4 6.5.5 6.5.6 6.5.7 6.6.0 6.7.0 6.7.1 6.8.0 6.8.1 6.8.2 6.8.3
secure-custom-fields / includes / fields / class-acf-field-textarea.php
secure-custom-fields / includes / fields Last commit date
class-acf-field-accordion.php 1 year ago class-acf-field-button-group.php 1 year ago class-acf-field-checkbox.php 1 year ago class-acf-field-color_picker.php 1 year ago class-acf-field-date_picker.php 1 year ago class-acf-field-date_time_picker.php 1 year ago class-acf-field-email.php 1 year ago class-acf-field-file.php 1 year ago class-acf-field-google-map.php 1 year ago class-acf-field-group.php 1 year ago class-acf-field-icon_picker.php 1 year ago class-acf-field-image.php 1 year ago class-acf-field-link.php 1 year ago class-acf-field-message.php 1 year ago class-acf-field-number.php 1 year ago class-acf-field-oembed.php 1 year ago class-acf-field-output.php 1 year ago class-acf-field-page_link.php 1 year ago class-acf-field-password.php 1 year ago class-acf-field-post_object.php 1 year ago class-acf-field-radio.php 1 year ago class-acf-field-range.php 1 year ago class-acf-field-relationship.php 1 year ago class-acf-field-select.php 1 year ago class-acf-field-separator.php 1 year ago class-acf-field-tab.php 1 year ago class-acf-field-taxonomy.php 1 year ago class-acf-field-text.php 1 year ago class-acf-field-textarea.php 1 year ago class-acf-field-time_picker.php 1 year ago class-acf-field-true_false.php 1 year ago class-acf-field-url.php 1 year ago class-acf-field-user.php 1 year ago class-acf-field-wysiwyg.php 1 year ago class-acf-field.php 1 year ago index.php 1 year ago
class-acf-field-textarea.php
245 lines
1 <?php
2
3 if ( ! class_exists( 'acf_field_textarea' ) ) :
4
5 class acf_field_textarea extends acf_field {
6
7
8 /**
9 * This function will setup the field type data
10 *
11 * @type function
12 * @date 5/03/2014
13 * @since 5.0.0
14 *
15 * @param n/a
16 * @return n/a
17 */
18 function initialize() {
19
20 // vars
21 $this->name = 'textarea';
22 $this->label = __( 'Text Area', 'acf' );
23 $this->description = __( 'A basic textarea input for storing paragraphs of text.', 'acf' );
24 $this->preview_image = acf_get_url() . '/assets/images/field-type-previews/field-preview-textarea.png';
25 $this->doc_url = 'https://www.advancedcustomfields.com/resources/textarea/';
26 $this->defaults = array(
27 'default_value' => '',
28 'new_lines' => '',
29 'maxlength' => '',
30 'placeholder' => '',
31 'rows' => '',
32 );
33 }
34
35
36 /**
37 * Create the HTML interface for your field
38 *
39 * @param $field - an array holding all the field's data
40 *
41 * @type action
42 * @since 3.6
43 * @date 23/01/13
44 */
45 function render_field( $field ) {
46
47 // vars
48 $atts = array();
49 $keys = array( 'id', 'class', 'name', 'value', 'placeholder', 'rows', 'maxlength' );
50 $keys2 = array( 'readonly', 'disabled', 'required' );
51
52 // rows
53 if ( ! $field['rows'] ) {
54 $field['rows'] = 8;
55 }
56
57 // atts (value="123")
58 foreach ( $keys as $k ) {
59 if ( isset( $field[ $k ] ) ) {
60 $atts[ $k ] = $field[ $k ];
61 }
62 }
63
64 // atts2 (disabled="disabled")
65 foreach ( $keys2 as $k ) {
66 if ( ! empty( $field[ $k ] ) ) {
67 $atts[ $k ] = $k;
68 }
69 }
70
71 // remove empty atts
72 $atts = acf_clean_atts( $atts );
73
74 // return
75 acf_textarea_input( $atts );
76 }
77
78
79 /**
80 * Create extra options for your field. This is rendered when editing a field.
81 * The value of $field['name'] can be used (like bellow) to save extra data to the $field
82 *
83 * @param $field - an array holding all the field's data
84 *
85 * @type action
86 * @since 3.6
87 * @date 23/01/13
88 */
89 function render_field_settings( $field ) {
90 acf_render_field_setting(
91 $field,
92 array(
93 'label' => __( 'Default Value', 'acf' ),
94 'instructions' => __( 'Appears when creating a new post', 'acf' ),
95 'type' => 'textarea',
96 'name' => 'default_value',
97 )
98 );
99 }
100
101 /**
102 * Renders the field settings used in the "Validation" tab.
103 *
104 * @since 6.0
105 *
106 * @param array $field The field settings array.
107 * @return void
108 */
109 function render_field_validation_settings( $field ) {
110 acf_render_field_setting(
111 $field,
112 array(
113 'label' => __( 'Character Limit', 'acf' ),
114 'instructions' => __( 'Leave blank for no limit', 'acf' ),
115 'type' => 'number',
116 'name' => 'maxlength',
117 )
118 );
119 }
120
121 /**
122 * Renders the field settings used in the "Presentation" tab.
123 *
124 * @since 6.0
125 *
126 * @param array $field The field settings array.
127 * @return void
128 */
129 function render_field_presentation_settings( $field ) {
130
131 acf_render_field_setting(
132 $field,
133 array(
134 'label' => __( 'Rows', 'acf' ),
135 'instructions' => __( 'Sets the textarea height', 'acf' ),
136 'type' => 'number',
137 'name' => 'rows',
138 'placeholder' => 8,
139 )
140 );
141
142 acf_render_field_setting(
143 $field,
144 array(
145 'label' => __( 'Placeholder Text', 'acf' ),
146 'instructions' => __( 'Appears within the input', 'acf' ),
147 'type' => 'text',
148 'name' => 'placeholder',
149 )
150 );
151
152 acf_render_field_setting(
153 $field,
154 array(
155 'label' => __( 'New Lines', 'acf' ),
156 'instructions' => __( 'Controls how new lines are rendered', 'acf' ),
157 'type' => 'select',
158 'name' => 'new_lines',
159 'choices' => array(
160 'wpautop' => __( 'Automatically add paragraphs', 'acf' ),
161 'br' => __( 'Automatically add &lt;br&gt;', 'acf' ),
162 '' => __( 'No Formatting', 'acf' ),
163 ),
164 )
165 );
166 }
167
168 /**
169 * This filter is applied to the $value after it is loaded from the db and before it is returned to the template
170 *
171 * @type filter
172 * @since 3.6
173 * @date 23/01/13
174 *
175 * @param $value (mixed) the value which was loaded from the database
176 * @param $post_id (mixed) the post_id from which the value was loaded
177 * @param $field (array) the field array holding all the field options
178 *
179 * @return $value (mixed) the modified value
180 */
181 function format_value( $value, $post_id, $field ) {
182
183 // bail early if no value or not for template
184 if ( empty( $value ) || ! is_string( $value ) ) {
185 return $value;
186 }
187
188 // new lines
189 if ( $field['new_lines'] == 'wpautop' ) {
190 $value = wpautop( $value );
191 } elseif ( $field['new_lines'] == 'br' ) {
192 $value = nl2br( $value );
193 }
194
195 // return
196 return $value;
197 }
198
199 /**
200 * validate_value
201 *
202 * Validates a field's value.
203 *
204 * @date 29/1/19
205 * @since 5.7.11
206 *
207 * @param (bool|string) Whether the value is vaid or not.
208 * @param mixed $value The field value.
209 * @param array $field The field array.
210 * @param string $input The HTML input name.
211 * @return (bool|string)
212 */
213 function validate_value( $valid, $value, $field, $input ) {
214
215 // Check maxlength.
216 if ( $field['maxlength'] && ( acf_strlen( $value ) > $field['maxlength'] ) ) {
217 return sprintf( __( 'Value must not exceed %d characters', 'acf' ), $field['maxlength'] );
218 }
219
220 // Return.
221 return $valid;
222 }
223
224 /**
225 * Return the schema array for the REST API.
226 *
227 * @param array $field
228 * @return array
229 */
230 function get_rest_schema( array $field ) {
231 $schema = parent::get_rest_schema( $field );
232
233 if ( ! empty( $field['maxlength'] ) ) {
234 $schema['maxLength'] = (int) $field['maxlength'];
235 }
236
237 return $schema;
238 }
239 }
240
241
242 // initialize
243 acf_register_field_type( 'acf_field_textarea' );
244 endif; // class_exists check
245