PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 2.8.23.4
Pods – Custom Content Types and Fields v2.8.23.4
2.7.31.4 2.8.23.5 2.9.19.5 3.0.10.5 3.1.4.3 3.2.8.4 3.3.9.2 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
196 lines
1 <?php
2
3 /**
4 * @package Pods\Fields
5 */
6 class PodsField_Email extends PodsField {
7
8 /**
9 * {@inheritdoc}
10 */
11 public static $group = 'Text';
12
13 /**
14 * {@inheritdoc}
15 */
16 public static $type = 'email';
17
18 /**
19 * {@inheritdoc}
20 */
21 public static $label = 'E-mail';
22
23 /**
24 * {@inheritdoc}
25 */
26 public static $prepare = '%s';
27
28 /**
29 * {@inheritdoc}
30 */
31 public function setup() {
32
33 static::$group = __( 'Text', 'pods' );
34 static::$label = __( 'E-mail', 'pods' );
35 }
36
37 /**
38 * {@inheritdoc}
39 */
40 public function options() {
41
42 $options = array(
43 static::$type . '_repeatable' => array(
44 'label' => __( 'Repeatable Field', 'pods' ),
45 'default' => 0,
46 'type' => 'boolean',
47 'help' => __( 'Making a field repeatable will add controls next to the field which allows users to Add/Remove/Reorder additional values. These values are saved in the database as an array, so searching and filtering by them may require further adjustments".', 'pods' ),
48 'boolean_yes_label' => '',
49 'dependency' => true,
50 'developer_mode' => true,
51 ),
52 static::$type . '_max_length' => array(
53 'label' => __( 'Maximum Length', 'pods' ),
54 'default' => 255,
55 'type' => 'number',
56 'help' => __( 'Set to -1 for no limit', 'pods' ),
57 ),
58 static::$type . '_html5' => array(
59 'label' => __( 'Enable HTML5 Input Field', 'pods' ),
60 'default' => apply_filters( 'pods_form_ui_field_html5', 0, static::$type ),
61 'type' => 'boolean',
62 ),
63 static::$type . '_placeholder' => array(
64 'label' => __( 'HTML Placeholder', 'pods' ),
65 'default' => '',
66 'type' => 'text',
67 'help' => array(
68 __( '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' ),
69 'https://www.w3.org/WAI/tutorials/forms/instructions/#placeholder-text',
70 ),
71 ),
72 );
73
74 return $options;
75 }
76
77 /**
78 * {@inheritdoc}
79 */
80 public function schema( $options = null ) {
81
82 $length = (int) pods_v( static::$type . '_max_length', $options, 255 );
83
84 $schema = 'VARCHAR(' . $length . ')';
85
86 if ( 255 < $length || $length < 1 ) {
87 $schema = 'LONGTEXT';
88 }
89
90 return $schema;
91 }
92
93 /**
94 * {@inheritdoc}
95 */
96 public function input( $name, $value = null, $options = null, $pod = null, $id = null ) {
97
98 $options = ( is_array( $options ) || is_object( $options ) ) ? $options : (array) $options;
99 $form_field_type = PodsForm::$field_type;
100
101 if ( is_array( $value ) ) {
102 $value = implode( ' ', $value );
103 }
104
105 $field_type = 'email';
106
107 if ( isset( $options['name'] ) && ! pods_permission( $options ) ) {
108 if ( pods_v( 'read_only', $options, false ) ) {
109 $options['readonly'] = true;
110
111 $field_type = 'text';
112 } else {
113 return;
114 }
115 } elseif ( ! pods_has_permissions( $options ) && pods_v( 'read_only', $options, false ) ) {
116 $options['readonly'] = true;
117
118 $field_type = 'text';
119 }
120
121 if ( ! empty( $options['disable_dfv'] ) ) {
122 return pods_view( PODS_DIR . 'ui/fields/email.php', compact( array_keys( get_defined_vars() ) ) );
123 }
124
125 $type = pods_v( 'type', $options, static::$type );
126
127 $args = compact( array_keys( get_defined_vars() ) );
128 $args = (object) $args;
129
130 $this->render_input_script( $args );
131 }
132
133 /**
134 * {@inheritdoc}
135 */
136 public function validate( $value, $name = null, $options = null, $fields = null, $pod = null, $id = null, $params = null ) {
137 $validate = parent::validate( $value, $name, $options, $fields, $pod, $id, $params );
138
139 $errors = array();
140
141 if ( is_array( $validate ) ) {
142 $errors = $validate;
143 }
144
145 $check = $this->pre_save( $value, $id, $name, $options, $fields, $pod, $params );
146
147 if ( is_array( $check ) ) {
148 $errors = $check;
149 } else {
150 if ( 0 < strlen( $value ) && '' === $check ) {
151 $label = pods_v( 'label', $options, ucwords( str_replace( '_', ' ', $name ) ) );
152
153 if ( $this->is_required( $options ) ) {
154 $errors[] = sprintf( __( '%s is required', 'pods' ), $label );
155 } else {
156 $errors[] = sprintf( __( 'Invalid e-mail provided for %s', 'pods' ), $label );
157 }
158 }
159 }
160
161 if ( ! empty( $errors ) ) {
162 return $errors;
163 }
164
165 return $validate;
166 }
167
168 /**
169 * {@inheritdoc}
170 */
171 public function pre_save( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) {
172
173 $options = ( is_array( $options ) || is_object( $options ) ) ? $options : (array) $options;
174
175 if ( ! is_email( $value ) ) {
176 $value = '';
177 }
178
179 $length = (int) pods_v( static::$type . '_max_length', $options, 255 );
180
181 if ( 0 < $length && $length < pods_mb_strlen( $value ) ) {
182 $value = pods_mb_substr( $value, 0, $length );
183 }
184
185 return $value;
186 }
187
188 /**
189 * {@inheritdoc}
190 */
191 public function ui( $id, $value, $name = null, $options = null, $fields = null, $pod = null ) {
192
193 return '<a href="mailto:' . esc_attr( $value ) . '">' . $value . '</a>';
194 }
195 }
196