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