PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 3.3.9.1
Pods – Custom Content Types and Fields v3.3.9.1
2.8.23.4 2.9.19.4 3.0.10.4 3.1.4.2 3.2.8.3 3.3.9.1 trunk 1.14.8 2.7.31.3 2.8.23.3 2.9.19.3 3.0.10.3 3.1.4.1 3.2.0 3.2.1 3.2.1.1 3.2.2 3.2.4 3.2.5 3.2.6 3.2.7 3.2.7.1 3.2.8 3.2.8.1 3.2.8.2 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9
pods / classes / fields / email.php
pods / classes / fields Last commit date
avatar.php 2 weeks ago boolean.php 2 weeks ago code.php 2 weeks ago color.php 2 weeks ago comment.php 2 weeks ago currency.php 2 weeks ago date.php 2 weeks ago datetime.php 2 weeks ago email.php 2 weeks ago file.php 2 weeks ago heading.php 2 weeks ago html.php 2 weeks ago link.php 2 weeks ago number.php 2 weeks ago oembed.php 2 weeks ago paragraph.php 2 weeks ago password.php 2 weeks ago phone.php 2 weeks ago pick.php 2 weeks ago slug.php 2 weeks ago taxonomy.php 2 weeks ago text.php 2 weeks ago time.php 2 weeks ago website.php 2 weeks ago wysiwyg.php 2 weeks ago
email.php
194 lines
1 <?php
2
3 // Don't load directly.
4 if ( ! defined( 'ABSPATH' ) ) {
5 die( '-1' );
6 }
7
8 /**
9 * @package Pods\Fields
10 */
11 class PodsField_Email extends PodsField {
12
13 /**
14 * {@inheritdoc}
15 */
16 public static $group = 'Text';
17
18 /**
19 * {@inheritdoc}
20 */
21 public static $type = 'email';
22
23 /**
24 * {@inheritdoc}
25 */
26 public static $label = 'E-mail';
27
28 /**
29 * {@inheritdoc}
30 */
31 public static $prepare = '%s';
32
33 /**
34 * {@inheritdoc}
35 */
36 public function setup() {
37
38 static::$group = __( 'Text', 'pods' );
39 static::$label = __( 'E-mail', 'pods' );
40 }
41
42 /**
43 * {@inheritdoc}
44 */
45 public function options() {
46
47 $options = [
48 static::$type . '_max_length' => [
49 'label' => __( 'Maximum Length', 'pods' ),
50 'default' => 255,
51 'type' => 'number',
52 'help' => __( 'Set to -1 for no limit', 'pods' ),
53 ],
54 static::$type . '_html5' => [
55 'label' => __( 'Enable HTML5 Input Field', 'pods' ),
56 'default' => apply_filters( 'pods_form_ui_field_html5', 0, static::$type ),
57 'type' => 'boolean',
58 ],
59 static::$type . '_placeholder' => [
60 'label' => __( 'HTML Placeholder', 'pods' ),
61 'default' => '',
62 'type' => 'text',
63 'help' => [
64 __( 'Placeholders can provide instructions or an example of the required data format for a field. Please note: It is not a replacement for labels or description text, and it is less accessible for people using screen readers.', 'pods' ),
65 'https://www.w3.org/WAI/tutorials/forms/instructions/#placeholder-text',
66 ],
67 ],
68 ];
69
70 return $options;
71 }
72
73 /**
74 * {@inheritdoc}
75 */
76 public function schema( $options = null ) {
77
78 $length = (int) pods_v( static::$type . '_max_length', $options, 255 );
79
80 $schema = 'VARCHAR(' . $length . ')';
81
82 if ( 255 < $length || $length < 1 ) {
83 $schema = 'LONGTEXT';
84 }
85
86 return $schema;
87 }
88
89 /**
90 * {@inheritdoc}
91 */
92 public function input( $name, $value = null, $options = null, $pod = null, $id = null ) {
93
94 $options = ( is_array( $options ) || is_object( $options ) ) ? $options : (array) $options;
95 $form_field_type = PodsForm::$field_type;
96
97 $value = $this->normalize_value_for_input( $value, $options );
98
99 $field_type = 'email';
100
101 if ( isset( $options['name'] ) && ! pods_permission( $options ) ) {
102 if ( pods_v_bool( 'read_only_restricted', $options ) ) {
103 $options['readonly'] = true;
104
105 $field_type = 'text';
106 } else {
107 return;
108 }
109 } elseif ( ! pods_has_permissions( $options ) ) {
110 if ( pods_v_bool( 'read_only', $options ) ) {
111 $options['readonly'] = true;
112
113 $field_type = 'text';
114 }
115 }
116
117 if ( ! empty( $options['disable_dfv'] ) ) {
118 return pods_view( PODS_DIR . 'ui/fields/email.php', compact( array_keys( get_defined_vars() ) ) );
119 }
120
121 $type = pods_v( 'type', $options, static::$type );
122
123 $args = compact( array_keys( get_defined_vars() ) );
124 $args = (object) $args;
125
126 $this->render_input_script( $args );
127 }
128
129 /**
130 * {@inheritdoc}
131 */
132 public function validate( $value, $name = null, $options = null, $fields = null, $pod = null, $id = null, $params = null ) {
133 $validate = parent::validate( $value, $name, $options, $fields, $pod, $id, $params );
134
135 $errors = [];
136
137 if ( is_array( $validate ) ) {
138 $errors = $validate;
139 }
140
141 $check = $this->pre_save( $value, $id, $name, $options, $fields, $pod, $params );
142
143 if ( is_array( $check ) ) {
144 $errors = $check;
145 } else {
146 if ( 0 < strlen( (string) $value ) && '' === $check ) {
147 $label = pods_v( 'label', $options, ucwords( str_replace( '_', ' ', $name ) ) );
148
149 if ( $this->is_required( $options ) ) {
150 // translators: %s is the field label.
151 $errors[] = sprintf( __( '%s is required', 'pods' ), $label );
152 } else {
153 // translators: %s is the field label.
154 $errors[] = sprintf( __( 'Invalid e-mail provided for %s', 'pods' ), $label );
155 }
156 }
157 }
158
159 if ( ! empty( $errors ) ) {
160 return $errors;
161 }
162
163 return $validate;
164 }
165
166 /**
167 * {@inheritdoc}
168 */
169 public function pre_save( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) {
170
171 $options = ( is_array( $options ) || is_object( $options ) ) ? $options : (array) $options;
172
173 if ( ! is_email( $value ) ) {
174 $value = '';
175 }
176
177 $length = (int) pods_v( static::$type . '_max_length', $options, 255 );
178
179 if ( 0 < $length && $length < pods_mb_strlen( $value ) ) {
180 $value = pods_mb_substr( $value, 0, $length );
181 }
182
183 return $value;
184 }
185
186 /**
187 * {@inheritdoc}
188 */
189 public function ui( $id, $value, $name = null, $options = null, $fields = null, $pod = null ) {
190
191 return '<a href="mailto:' . esc_attr( $value ) . '">' . $value . '</a>';
192 }
193 }
194