FlexibleContent
2 months ago
class-acf-field-accordion.php
2 months ago
class-acf-field-button-group.php
2 months ago
class-acf-field-checkbox.php
2 days ago
class-acf-field-clone.php
2 months ago
class-acf-field-color_picker.php
2 months ago
class-acf-field-date_picker.php
2 months ago
class-acf-field-date_time_picker.php
2 months ago
class-acf-field-email.php
2 months ago
class-acf-field-file.php
2 months ago
class-acf-field-flexible-content.php
1 week ago
class-acf-field-gallery.php
3 weeks ago
class-acf-field-google-map.php
2 months ago
class-acf-field-group.php
2 months ago
class-acf-field-icon_picker.php
7 months ago
class-acf-field-image.php
2 months ago
class-acf-field-link.php
2 months ago
class-acf-field-message.php
1 year ago
class-acf-field-nav-menu.php
1 week ago
class-acf-field-number.php
2 months ago
class-acf-field-oembed.php
3 weeks ago
class-acf-field-output.php
1 year ago
class-acf-field-page_link.php
3 weeks ago
class-acf-field-password.php
2 months ago
class-acf-field-post_object.php
3 weeks ago
class-acf-field-radio.php
2 days ago
class-acf-field-range.php
2 months ago
class-acf-field-relationship.php
3 weeks ago
class-acf-field-repeater.php
3 weeks ago
class-acf-field-select.php
2 days ago
class-acf-field-separator.php
1 year ago
class-acf-field-tab.php
1 year ago
class-acf-field-taxonomy.php
3 weeks ago
class-acf-field-text.php
3 weeks ago
class-acf-field-textarea.php
3 weeks ago
class-acf-field-time_picker.php
2 months ago
class-acf-field-true_false.php
2 months ago
class-acf-field-url.php
3 weeks ago
class-acf-field-user.php
3 weeks ago
class-acf-field-wysiwyg.php
2 months ago
class-acf-field.php
2 months ago
class-acf-repeater-table.php
1 year ago
index.php
1 year ago
class-acf-field-textarea.php
259 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://developer.wordpress.org/secure-custom-fields/features/fields/textarea/'; |
| 27 | $this->tutorial_url = 'https://developer.wordpress.org/secure-custom-fields/features/fields/textarea/textarea-tutorial/'; |
| 28 | $this->defaults = array( |
| 29 | 'default_value' => '', |
| 30 | 'new_lines' => '', |
| 31 | 'maxlength' => '', |
| 32 | 'placeholder' => '', |
| 33 | 'rows' => '', |
| 34 | ); |
| 35 | } |
| 36 | |
| 37 | |
| 38 | /** |
| 39 | * Create the HTML interface for your field |
| 40 | * |
| 41 | * @param $field - an array holding all the field's data |
| 42 | * |
| 43 | * @type action |
| 44 | * @since ACF 3.6 |
| 45 | * @date 23/01/13 |
| 46 | */ |
| 47 | function render_field( $field ) { |
| 48 | |
| 49 | // vars |
| 50 | $atts = array(); |
| 51 | $keys = array( 'id', 'class', 'name', 'value', 'placeholder', 'rows', 'maxlength' ); |
| 52 | $keys2 = array( 'readonly', 'disabled', 'required' ); |
| 53 | |
| 54 | // rows |
| 55 | if ( ! $field['rows'] ) { |
| 56 | $field['rows'] = 8; |
| 57 | } |
| 58 | |
| 59 | // atts (value="123") |
| 60 | foreach ( $keys as $k ) { |
| 61 | if ( isset( $field[ $k ] ) ) { |
| 62 | $atts[ $k ] = $field[ $k ]; |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | // atts2 (disabled="disabled") |
| 67 | foreach ( $keys2 as $k ) { |
| 68 | if ( ! empty( $field[ $k ] ) ) { |
| 69 | $atts[ $k ] = $k; |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | // remove empty atts |
| 74 | $atts = acf_clean_atts( $atts ); |
| 75 | |
| 76 | // return |
| 77 | acf_textarea_input( $atts ); |
| 78 | } |
| 79 | |
| 80 | |
| 81 | /** |
| 82 | * Create extra options for your field. This is rendered when editing a field. |
| 83 | * The value of $field['name'] can be used (like bellow) to save extra data to the $field |
| 84 | * |
| 85 | * @param $field - an array holding all the field's data |
| 86 | * |
| 87 | * @type action |
| 88 | * @since ACF 3.6 |
| 89 | * @date 23/01/13 |
| 90 | */ |
| 91 | function render_field_settings( $field ) { |
| 92 | acf_render_field_setting( |
| 93 | $field, |
| 94 | array( |
| 95 | 'label' => __( 'Default Value', 'secure-custom-fields' ), |
| 96 | 'instructions' => __( 'Appears when creating a new post', 'secure-custom-fields' ), |
| 97 | 'type' => 'textarea', |
| 98 | 'name' => 'default_value', |
| 99 | ) |
| 100 | ); |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Renders the field settings used in the "Validation" tab. |
| 105 | * |
| 106 | * @since ACF 6.0 |
| 107 | * |
| 108 | * @param array $field The field settings array. |
| 109 | * @return void |
| 110 | */ |
| 111 | function render_field_validation_settings( $field ) { |
| 112 | acf_render_field_setting( |
| 113 | $field, |
| 114 | array( |
| 115 | 'label' => __( 'Character Limit', 'secure-custom-fields' ), |
| 116 | 'instructions' => __( 'Leave blank for no limit', 'secure-custom-fields' ), |
| 117 | 'type' => 'number', |
| 118 | 'name' => 'maxlength', |
| 119 | ) |
| 120 | ); |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * Renders the field settings used in the "Presentation" tab. |
| 125 | * |
| 126 | * @since ACF 6.0 |
| 127 | * |
| 128 | * @param array $field The field settings array. |
| 129 | * @return void |
| 130 | */ |
| 131 | function render_field_presentation_settings( $field ) { |
| 132 | |
| 133 | acf_render_field_setting( |
| 134 | $field, |
| 135 | array( |
| 136 | 'label' => __( 'Rows', 'secure-custom-fields' ), |
| 137 | 'instructions' => __( 'Sets the textarea height', 'secure-custom-fields' ), |
| 138 | 'type' => 'number', |
| 139 | 'name' => 'rows', |
| 140 | 'placeholder' => 8, |
| 141 | ) |
| 142 | ); |
| 143 | |
| 144 | acf_render_field_setting( |
| 145 | $field, |
| 146 | array( |
| 147 | 'label' => __( 'Placeholder Text', 'secure-custom-fields' ), |
| 148 | 'instructions' => __( 'Appears within the input', 'secure-custom-fields' ), |
| 149 | 'type' => 'text', |
| 150 | 'name' => 'placeholder', |
| 151 | ) |
| 152 | ); |
| 153 | |
| 154 | acf_render_field_setting( |
| 155 | $field, |
| 156 | array( |
| 157 | 'label' => __( 'New Lines', 'secure-custom-fields' ), |
| 158 | 'instructions' => __( 'Controls how new lines are rendered', 'secure-custom-fields' ), |
| 159 | 'type' => 'select', |
| 160 | 'name' => 'new_lines', |
| 161 | 'choices' => array( |
| 162 | 'wpautop' => __( 'Automatically add paragraphs', 'secure-custom-fields' ), |
| 163 | 'br' => __( 'Automatically add <br>', 'secure-custom-fields' ), |
| 164 | '' => __( 'No Formatting', 'secure-custom-fields' ), |
| 165 | ), |
| 166 | ) |
| 167 | ); |
| 168 | } |
| 169 | |
| 170 | /** |
| 171 | * This filter is applied to the $value after it is loaded from the db and before it is returned to the template |
| 172 | * |
| 173 | * @type filter |
| 174 | * @since ACF 3.6 |
| 175 | * @date 23/01/13 |
| 176 | * |
| 177 | * @param $value (mixed) the value which was loaded from the database |
| 178 | * @param $post_id (mixed) the post_id from which the value was loaded |
| 179 | * @param $field (array) the field array holding all the field options |
| 180 | * |
| 181 | * @return $value (mixed) the modified value |
| 182 | */ |
| 183 | function format_value( $value, $post_id, $field ) { |
| 184 | |
| 185 | // bail early if no value or not for template |
| 186 | if ( empty( $value ) || ! is_string( $value ) ) { |
| 187 | return $value; |
| 188 | } |
| 189 | |
| 190 | // new lines |
| 191 | if ( $field['new_lines'] == 'wpautop' ) { |
| 192 | $value = wpautop( $value ); |
| 193 | } elseif ( $field['new_lines'] == 'br' ) { |
| 194 | $value = nl2br( $value ); |
| 195 | } |
| 196 | |
| 197 | // return |
| 198 | return $value; |
| 199 | } |
| 200 | |
| 201 | /** |
| 202 | * validate_value |
| 203 | * |
| 204 | * Validates a field's value. |
| 205 | * |
| 206 | * @date 29/1/19 |
| 207 | * @since ACF 5.7.11 |
| 208 | * |
| 209 | * @param mixed $valid Whether the value is valid or not. |
| 210 | * @param mixed $value The field value. |
| 211 | * @param array $field The field array. |
| 212 | * @param string $input The HTML input name. |
| 213 | * @return (bool|string) |
| 214 | */ |
| 215 | function validate_value( $valid, $value, $field, $input ) { |
| 216 | |
| 217 | // Check maxlength. A non-scalar value (e.g. an array from a crafted submission) is not valid text, so skip the string length check. |
| 218 | if ( $field['maxlength'] && is_scalar( $value ) && ( acf_strlen( $value ) > $field['maxlength'] ) ) { |
| 219 | /* translators: %d: the maximum number of characters */ |
| 220 | return sprintf( __( 'Value must not exceed %d characters', 'secure-custom-fields' ), $field['maxlength'] ); |
| 221 | } |
| 222 | |
| 223 | // Return. |
| 224 | return $valid; |
| 225 | } |
| 226 | |
| 227 | /** |
| 228 | * Return the schema array for the REST API. |
| 229 | * |
| 230 | * @param array $field |
| 231 | * @return array |
| 232 | */ |
| 233 | function get_rest_schema( array $field ) { |
| 234 | $schema = parent::get_rest_schema( $field ); |
| 235 | |
| 236 | if ( ! empty( $field['maxlength'] ) ) { |
| 237 | $schema['maxLength'] = (int) $field['maxlength']; |
| 238 | } |
| 239 | |
| 240 | return $schema; |
| 241 | } |
| 242 | |
| 243 | /** |
| 244 | * Returns an array of JSON-LD Property output types that are supported by this field type. |
| 245 | * |
| 246 | * @since 6.8 |
| 247 | * |
| 248 | * @return string[] |
| 249 | */ |
| 250 | public function get_jsonld_output_types(): array { |
| 251 | return array( 'Text' ); |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | |
| 256 | // initialize |
| 257 | acf_register_field_type( 'acf_field_textarea' ); |
| 258 | endif; // class_exists check |
| 259 |