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-email.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-email.php
190 lines
1 <?php
2
3 if ( ! class_exists( 'acf_field_email' ) ) :
4
5 class acf_field_email 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 = 'email';
22 $this->label = __( 'Email', 'acf' );
23 $this->description = __( 'A text input specifically designed for storing email addresses.', 'acf' );
24 $this->preview_image = acf_get_url() . '/assets/images/field-type-previews/field-preview-email.png';
25 $this->doc_url = 'https://www.advancedcustomfields.com/resources/email/';
26 $this->defaults = array(
27 'default_value' => '',
28 'placeholder' => '',
29 'prepend' => '',
30 'append' => '',
31 );
32 }
33
34
35 /**
36 * Create the HTML interface for your field
37 *
38 * @param $field - an array holding all the field's data
39 *
40 * @type action
41 * @since 3.6
42 * @date 23/01/13
43 */
44 function render_field( $field ) {
45
46 // vars
47 $atts = array();
48 $keys = array( 'type', 'id', 'class', 'name', 'value', 'placeholder', 'pattern' );
49 $keys2 = array( 'readonly', 'disabled', 'required', 'multiple' );
50 $html = '';
51
52 // prepend
53 if ( $field['prepend'] !== '' ) {
54 $field['class'] .= ' acf-is-prepended';
55 $html .= '<div class="acf-input-prepend">' . acf_esc_html( $field['prepend'] ) . '</div>';
56 }
57
58 // append
59 if ( $field['append'] !== '' ) {
60 $field['class'] .= ' acf-is-appended';
61 $html .= '<div class="acf-input-append">' . acf_esc_html( $field['append'] ) . '</div>';
62 }
63
64 // atts (value="123")
65 foreach ( $keys as $k ) {
66 if ( isset( $field[ $k ] ) ) {
67 $atts[ $k ] = $field[ $k ];
68 }
69 }
70
71 // atts2 (disabled="disabled")
72 foreach ( $keys2 as $k ) {
73 if ( ! empty( $field[ $k ] ) ) {
74 $atts[ $k ] = $k;
75 }
76 }
77
78 // remove empty atts
79 $atts = acf_clean_atts( $atts );
80
81 // render
82 $html .= '<div class="acf-input-wrap">' . acf_get_text_input( $atts ) . '</div>';
83
84 // return
85 echo $html; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- safe HTML escaped by acf_get_text_input
86 }
87
88
89 /**
90 * Create extra options for your field. This is rendered when editing a field.
91 * The value of $field['name'] can be used (like bellow) to save extra data to the $field
92 *
93 * @type action
94 * @since 3.6
95 * @date 23/01/13
96 *
97 * @param $field - an array holding all the field's data
98 */
99 function render_field_settings( $field ) {
100 acf_render_field_setting(
101 $field,
102 array(
103 'label' => __( 'Default Value', 'acf' ),
104 'instructions' => __( 'Appears when creating a new post', 'acf' ),
105 'type' => 'text',
106 'name' => 'default_value',
107 )
108 );
109 }
110
111 /**
112 * Renders the field settings used in the "Presentation" tab.
113 *
114 * @since 6.0
115 *
116 * @param array $field The field settings array.
117 * @return void
118 */
119 function render_field_presentation_settings( $field ) {
120 acf_render_field_setting(
121 $field,
122 array(
123 'label' => __( 'Placeholder Text', 'acf' ),
124 'instructions' => __( 'Appears within the input', 'acf' ),
125 'type' => 'text',
126 'name' => 'placeholder',
127 )
128 );
129
130 acf_render_field_setting(
131 $field,
132 array(
133 'label' => __( 'Prepend', 'acf' ),
134 'instructions' => __( 'Appears before the input', 'acf' ),
135 'type' => 'text',
136 'name' => 'prepend',
137 )
138 );
139
140 acf_render_field_setting(
141 $field,
142 array(
143 'label' => __( 'Append', 'acf' ),
144 'instructions' => __( 'Appears after the input', 'acf' ),
145 'type' => 'text',
146 'name' => 'append',
147 )
148 );
149 }
150
151 /**
152 * Validate the email value. If this method returns TRUE, the input value is valid. If
153 * FALSE or a string is returned, the input value is invalid and the user is shown a
154 * notice. If a string is returned, the string is show as the message text.
155 *
156 * @param boolean $valid Whether the value is valid.
157 * @param mixed $value The field value.
158 * @param array $field The field array.
159 * @param string $input The request variable name for the inbound field.
160 * @return boolean|string
161 */
162 public function validate_value( $valid, $value, $field, $input ) {
163 $flags = defined( 'FILTER_FLAG_EMAIL_UNICODE' ) ? FILTER_FLAG_EMAIL_UNICODE : 0;
164
165 if ( $value && filter_var( wp_unslash( $value ), FILTER_VALIDATE_EMAIL, $flags ) === false ) {
166 return sprintf( __( "'%s' is not a valid email address", 'acf' ), esc_html( $value ) );
167 }
168
169 return $valid;
170 }
171
172 /**
173 * Return the schema array for the REST API.
174 *
175 * @param array $field
176 * @return array
177 */
178 public function get_rest_schema( array $field ) {
179 $schema = parent::get_rest_schema( $field );
180 $schema['format'] = 'email';
181
182 return $schema;
183 }
184 }
185
186
187 // initialize
188 acf_register_field_type( 'acf_field_email' );
189 endif; // class_exists check
190