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