class-acf-field-accordion.php
5 months ago
class-acf-field-button-group.php
5 months ago
class-acf-field-checkbox.php
2 months ago
class-acf-field-color_picker.php
5 months ago
class-acf-field-date_picker.php
5 months ago
class-acf-field-date_time_picker.php
5 months ago
class-acf-field-email.php
5 months ago
class-acf-field-file.php
5 months ago
class-acf-field-google-map.php
5 months ago
class-acf-field-group.php
5 months ago
class-acf-field-icon_picker.php
6 months ago
class-acf-field-image.php
1 month ago
class-acf-field-link.php
5 months ago
class-acf-field-message.php
6 months ago
class-acf-field-number.php
5 months ago
class-acf-field-oembed.php
2 months ago
class-acf-field-output.php
6 months ago
class-acf-field-page_link.php
1 month ago
class-acf-field-password.php
5 months ago
class-acf-field-post_object.php
1 month ago
class-acf-field-radio.php
2 months ago
class-acf-field-range.php
5 months ago
class-acf-field-relationship.php
1 month ago
class-acf-field-select.php
2 months ago
class-acf-field-separator.php
6 months ago
class-acf-field-tab.php
6 months ago
class-acf-field-taxonomy.php
2 months ago
class-acf-field-text.php
5 months ago
class-acf-field-textarea.php
5 months ago
class-acf-field-time_picker.php
5 months ago
class-acf-field-true_false.php
5 months ago
class-acf-field-url.php
5 months ago
class-acf-field-user.php
2 months ago
class-acf-field-wysiwyg.php
5 months ago
class-acf-field.php
5 months ago
index.php
2 years ago
class-acf-field-email.php
210 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @package ACF |
| 4 | * @author WP Engine |
| 5 | * |
| 6 | * © 2026 Advanced Custom Fields (ACF®). All rights reserved. |
| 7 | * "ACF" is a trademark of WP Engine. |
| 8 | * Licensed under the GNU General Public License v2 or later. |
| 9 | * https://www.gnu.org/licenses/gpl-2.0.html |
| 10 | */ |
| 11 | |
| 12 | if ( ! class_exists( 'acf_field_email' ) ) : |
| 13 | |
| 14 | class acf_field_email extends acf_field { |
| 15 | |
| 16 | |
| 17 | /** |
| 18 | * This function will setup the field type data |
| 19 | * |
| 20 | * @type function |
| 21 | * @date 5/03/2014 |
| 22 | * @since 5.0.0 |
| 23 | * |
| 24 | * @param n/a |
| 25 | * @return n/a |
| 26 | */ |
| 27 | function initialize() { |
| 28 | |
| 29 | // vars |
| 30 | $this->name = 'email'; |
| 31 | $this->label = __( 'Email', 'acf' ); |
| 32 | $this->description = __( 'A text input specifically designed for storing email addresses.', 'acf' ); |
| 33 | $this->preview_image = acf_get_url() . '/assets/images/field-type-previews/field-preview-email.png'; |
| 34 | $this->doc_url = acf_add_url_utm_tags( 'https://www.advancedcustomfields.com/resources/email/', 'docs', 'field-type-selection' ); |
| 35 | $this->defaults = array( |
| 36 | 'default_value' => '', |
| 37 | 'placeholder' => '', |
| 38 | 'prepend' => '', |
| 39 | 'append' => '', |
| 40 | ); |
| 41 | } |
| 42 | |
| 43 | |
| 44 | /** |
| 45 | * Create the HTML interface for your field |
| 46 | * |
| 47 | * @param $field - an array holding all the field's data |
| 48 | * |
| 49 | * @type action |
| 50 | * @since 3.6 |
| 51 | * @date 23/01/13 |
| 52 | */ |
| 53 | function render_field( $field ) { |
| 54 | |
| 55 | // vars |
| 56 | $atts = array(); |
| 57 | $keys = array( 'type', 'id', 'class', 'name', 'value', 'placeholder', 'pattern' ); |
| 58 | $keys2 = array( 'readonly', 'disabled', 'required', 'multiple' ); |
| 59 | $html = ''; |
| 60 | |
| 61 | // prepend |
| 62 | if ( $field['prepend'] !== '' ) { |
| 63 | $field['class'] .= ' acf-is-prepended'; |
| 64 | $html .= '<div class="acf-input-prepend">' . acf_esc_html( $field['prepend'] ) . '</div>'; |
| 65 | } |
| 66 | |
| 67 | // append |
| 68 | if ( $field['append'] !== '' ) { |
| 69 | $field['class'] .= ' acf-is-appended'; |
| 70 | $html .= '<div class="acf-input-append">' . acf_esc_html( $field['append'] ) . '</div>'; |
| 71 | } |
| 72 | |
| 73 | // atts (value="123") |
| 74 | foreach ( $keys as $k ) { |
| 75 | if ( isset( $field[ $k ] ) ) { |
| 76 | $atts[ $k ] = $field[ $k ]; |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | // atts2 (disabled="disabled") |
| 81 | foreach ( $keys2 as $k ) { |
| 82 | if ( ! empty( $field[ $k ] ) ) { |
| 83 | $atts[ $k ] = $k; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | // remove empty atts |
| 88 | $atts = acf_clean_atts( $atts ); |
| 89 | |
| 90 | // render |
| 91 | $html .= '<div class="acf-input-wrap">' . acf_get_text_input( $atts ) . '</div>'; |
| 92 | |
| 93 | // return |
| 94 | echo $html; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- safe HTML escaped by acf_get_text_input |
| 95 | } |
| 96 | |
| 97 | |
| 98 | /** |
| 99 | * Create extra options for your field. This is rendered when editing a field. |
| 100 | * The value of $field['name'] can be used (like bellow) to save extra data to the $field |
| 101 | * |
| 102 | * @type action |
| 103 | * @since 3.6 |
| 104 | * @date 23/01/13 |
| 105 | * |
| 106 | * @param $field - an array holding all the field's data |
| 107 | */ |
| 108 | function render_field_settings( $field ) { |
| 109 | acf_render_field_setting( |
| 110 | $field, |
| 111 | array( |
| 112 | 'label' => __( 'Default Value', 'acf' ), |
| 113 | 'instructions' => __( 'Appears when creating a new post', 'acf' ), |
| 114 | 'type' => 'text', |
| 115 | 'name' => 'default_value', |
| 116 | ) |
| 117 | ); |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * Renders the field settings used in the "Presentation" tab. |
| 122 | * |
| 123 | * @since 6.0 |
| 124 | * |
| 125 | * @param array $field The field settings array. |
| 126 | * @return void |
| 127 | */ |
| 128 | function render_field_presentation_settings( $field ) { |
| 129 | acf_render_field_setting( |
| 130 | $field, |
| 131 | array( |
| 132 | 'label' => __( 'Placeholder Text', 'acf' ), |
| 133 | 'instructions' => __( 'Appears within the input', 'acf' ), |
| 134 | 'type' => 'text', |
| 135 | 'name' => 'placeholder', |
| 136 | ) |
| 137 | ); |
| 138 | |
| 139 | acf_render_field_setting( |
| 140 | $field, |
| 141 | array( |
| 142 | 'label' => __( 'Prepend', 'acf' ), |
| 143 | 'instructions' => __( 'Appears before the input', 'acf' ), |
| 144 | 'type' => 'text', |
| 145 | 'name' => 'prepend', |
| 146 | ) |
| 147 | ); |
| 148 | |
| 149 | acf_render_field_setting( |
| 150 | $field, |
| 151 | array( |
| 152 | 'label' => __( 'Append', 'acf' ), |
| 153 | 'instructions' => __( 'Appears after the input', 'acf' ), |
| 154 | 'type' => 'text', |
| 155 | 'name' => 'append', |
| 156 | ) |
| 157 | ); |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * Validate the email value. If this method returns TRUE, the input value is valid. If |
| 162 | * FALSE or a string is returned, the input value is invalid and the user is shown a |
| 163 | * notice. If a string is returned, the string is show as the message text. |
| 164 | * |
| 165 | * @param boolean $valid Whether the value is valid. |
| 166 | * @param mixed $value The field value. |
| 167 | * @param array $field The field array. |
| 168 | * @param string $input The request variable name for the inbound field. |
| 169 | * @return boolean|string |
| 170 | */ |
| 171 | public function validate_value( $valid, $value, $field, $input ) { |
| 172 | $flags = defined( 'FILTER_FLAG_EMAIL_UNICODE' ) ? FILTER_FLAG_EMAIL_UNICODE : 0; |
| 173 | |
| 174 | if ( $value && filter_var( wp_unslash( $value ), FILTER_VALIDATE_EMAIL, $flags ) === false ) { |
| 175 | return sprintf( __( "'%s' is not a valid email address", 'acf' ), esc_html( $value ) ); |
| 176 | } |
| 177 | |
| 178 | return $valid; |
| 179 | } |
| 180 | |
| 181 | /** |
| 182 | * Return the schema array for the REST API. |
| 183 | * |
| 184 | * @param array $field |
| 185 | * @return array |
| 186 | */ |
| 187 | public function get_rest_schema( array $field ) { |
| 188 | $schema = parent::get_rest_schema( $field ); |
| 189 | $schema['format'] = 'email'; |
| 190 | |
| 191 | return $schema; |
| 192 | } |
| 193 | |
| 194 | /** |
| 195 | * Returns an array of JSON-LD Property output types that are supported by this field type. |
| 196 | * |
| 197 | * @since 6.8 |
| 198 | * |
| 199 | * @return string[] |
| 200 | */ |
| 201 | public function get_jsonld_output_types(): array { |
| 202 | return array( 'Text' ); |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | |
| 207 | // initialize |
| 208 | acf_register_field_type( 'acf_field_email' ); |
| 209 | endif; // class_exists check |
| 210 |