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