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-text.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-text.php
211 lines
1 <?php
2
3 if ( ! class_exists( 'acf_field_text' ) ) :
4
5 class acf_field_text 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.0.0
15 *
16 * @param n/a
17 * @return n/a
18 */
19 function initialize() {
20
21 // vars
22 $this->name = 'text';
23 $this->label = __( 'Text', 'secure-custom-fields' );
24 $this->description = __( 'A basic text input, useful for storing single string values.', 'secure-custom-fields' );
25 $this->preview_image = acf_get_url() . '/assets/images/field-type-previews/field-preview-text.png';
26 $this->doc_url = 'https://www.advancedcustomfields.com/resources/text/';
27 $this->defaults = array(
28 'default_value' => '',
29 'maxlength' => '',
30 'placeholder' => '',
31 'prepend' => '',
32 'append' => '',
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 3.6
44 * @date 23/01/13
45 */
46 function render_field( $field ) {
47 $html = '';
48
49 // Prepend text.
50 if ( $field['prepend'] !== '' ) {
51 $field['class'] .= ' acf-is-prepended';
52 $html .= '<div class="acf-input-prepend">' . acf_esc_html( $field['prepend'] ) . '</div>';
53 }
54
55 // Append text.
56 if ( $field['append'] !== '' ) {
57 $field['class'] .= ' acf-is-appended';
58 $html .= '<div class="acf-input-append">' . acf_esc_html( $field['append'] ) . '</div>';
59 }
60
61 // Input.
62 $input_attrs = array();
63 foreach ( array( 'type', 'id', 'class', 'name', 'value', 'placeholder', 'maxlength', 'pattern', 'readonly', 'disabled', 'required' ) as $k ) {
64 if ( isset( $field[ $k ] ) ) {
65 $input_attrs[ $k ] = $field[ $k ];
66 }
67 }
68
69 if ( isset( $field['input-data'] ) && is_array( $field['input-data'] ) ) {
70 foreach ( $field['input-data'] as $name => $attr ) {
71 $input_attrs[ 'data-' . $name ] = $attr;
72 }
73 }
74
75 $html .= '<div class="acf-input-wrap">' . acf_get_text_input( acf_filter_attrs( $input_attrs ) ) . '</div>';
76
77 // Display.
78 echo $html; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- only safe HTML output generated and escaped by functions above.
79 }
80
81
82 /**
83 * Create extra options for your field. This is rendered when editing a field.
84 * The value of $field['name'] can be used (like bellow) to save extra data to the $field
85 *
86 * @param $field - an array holding all the field's data
87 *
88 * @type action
89 * @since ACF 3.6 3.6
90 * @date 23/01/13
91 */
92 function render_field_settings( $field ) {
93 acf_render_field_setting(
94 $field,
95 array(
96 'label' => __( 'Default Value', 'secure-custom-fields' ),
97 'instructions' => __( 'Appears when creating a new post', 'secure-custom-fields' ),
98 'type' => 'text',
99 'name' => 'default_value',
100 )
101 );
102 }
103
104 /**
105 * Renders the field settings used in the "Validation" tab.
106 *
107 * @since ACF 6.0 6.0
108 *
109 * @param array $field The field settings array.
110 * @return void
111 */
112 function render_field_validation_settings( $field ) {
113 acf_render_field_setting(
114 $field,
115 array(
116 'label' => __( 'Character Limit', 'secure-custom-fields' ),
117 'instructions' => __( 'Leave blank for no limit', 'secure-custom-fields' ),
118 'type' => 'number',
119 'name' => 'maxlength',
120 )
121 );
122 }
123
124 /**
125 * Renders the field settings used in the "Presentation" tab.
126 *
127 * @since ACF 6.0 6.0
128 *
129 * @param array $field The field settings array.
130 * @return void
131 */
132 function render_field_presentation_settings( $field ) {
133 acf_render_field_setting(
134 $field,
135 array(
136 'label' => __( 'Placeholder Text', 'secure-custom-fields' ),
137 'instructions' => __( 'Appears within the input', 'secure-custom-fields' ),
138 'type' => 'text',
139 'name' => 'placeholder',
140 )
141 );
142
143 acf_render_field_setting(
144 $field,
145 array(
146 'label' => __( 'Prepend', 'secure-custom-fields' ),
147 'instructions' => __( 'Appears before the input', 'secure-custom-fields' ),
148 'type' => 'text',
149 'name' => 'prepend',
150 )
151 );
152
153 acf_render_field_setting(
154 $field,
155 array(
156 'label' => __( 'Append', 'secure-custom-fields' ),
157 'instructions' => __( 'Appears after the input', 'secure-custom-fields' ),
158 'type' => 'text',
159 'name' => 'append',
160 )
161 );
162 }
163
164 /**
165 * validate_value
166 *
167 * Validates a field's value.
168 *
169 * @date 29/1/19
170 * @since ACF 5.7.117.11
171 *
172 * @param (bool|string) Whether the value is vaid or not.
173 * @param mixed $value The field value.
174 * @param array $field The field array.
175 * @param string $input The HTML input name.
176 * @return (bool|string)
177 */
178 function validate_value( $valid, $value, $field, $input ) {
179
180 // Check maxlength
181 if ( $field['maxlength'] && ( acf_strlen( $value ) > $field['maxlength'] ) ) {
182 /* translators: %d: the maximum number of characters */
183 return sprintf( __( 'Value must not exceed %d characters', 'secure-custom-fields' ), $field['maxlength'] );
184 }
185
186 // Return.
187 return $valid;
188 }
189
190 /**
191 * Return the schema array for the REST API.
192 *
193 * @param array $field
194 * @return array
195 */
196 function get_rest_schema( array $field ) {
197 $schema = parent::get_rest_schema( $field );
198
199 if ( ! empty( $field['maxlength'] ) ) {
200 $schema['maxLength'] = (int) $field['maxlength'];
201 }
202
203 return $schema;
204 }
205 }
206
207
208 // initialize
209 acf_register_field_type( 'acf_field_text' );
210 endif; // class_exists check
211