PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 2.7.31.4
Pods – Custom Content Types and Fields v2.7.31.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 days ago boolean.php 2 days ago code.php 2 days ago color.php 2 days ago comment.php 2 days ago currency.php 2 days ago date.php 2 days ago datetime.php 2 days ago email.php 2 days ago file.php 2 days ago html.php 2 days ago link.php 2 days ago number.php 2 days ago oembed.php 2 days ago paragraph.php 2 days ago password.php 2 days ago phone.php 2 days ago pick.php 2 days ago slug.php 2 days ago taxonomy.php 2 days ago text.php 2 days ago time.php 2 days ago website.php 2 days ago wysiwyg.php 2 days ago
email.php
186 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 self::$label = __( 'E-mail', 'pods' );
34 }
35
36 /**
37 * {@inheritdoc}
38 */
39 public function options() {
40
41 $options = array(
42 static::$type . '_repeatable' => array(
43 'label' => __( 'Repeatable Field', 'pods' ),
44 'default' => 0,
45 'type' => 'boolean',
46 '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' ),
47 'boolean_yes_label' => '',
48 'dependency' => true,
49 'developer_mode' => true,
50 ),
51 static::$type . '_max_length' => array(
52 'label' => __( 'Maximum Length', 'pods' ),
53 'default' => 255,
54 'type' => 'number',
55 'help' => __( 'Set to -1 for no limit', 'pods' ),
56 ),
57 static::$type . '_html5' => array(
58 'label' => __( 'Enable HTML5 Input Field?', 'pods' ),
59 'default' => apply_filters( 'pods_form_ui_field_html5', 0, static::$type ),
60 'type' => 'boolean',
61 ),
62 static::$type . '_placeholder' => array(
63 'label' => __( 'HTML Placeholder', 'pods' ),
64 'default' => '',
65 'type' => 'text',
66 'help' => array(
67 __( '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' ),
68 'https://www.w3.org/WAI/tutorials/forms/instructions/#placeholder-text',
69 ),
70 ),
71 );
72
73 return $options;
74 }
75
76 /**
77 * {@inheritdoc}
78 */
79 public function schema( $options = null ) {
80
81 $length = (int) pods_v( static::$type . '_max_length', $options, 255 );
82
83 $schema = 'VARCHAR(' . $length . ')';
84
85 if ( 255 < $length || $length < 1 ) {
86 $schema = 'LONGTEXT';
87 }
88
89 return $schema;
90 }
91
92 /**
93 * {@inheritdoc}
94 */
95 public function input( $name, $value = null, $options = null, $pod = null, $id = null ) {
96
97 $options = (array) $options;
98 $form_field_type = PodsForm::$field_type;
99
100 if ( is_array( $value ) ) {
101 $value = implode( ' ', $value );
102 }
103
104 $field_type = 'email';
105
106 if ( isset( $options['name'] ) && false === PodsForm::permission( static::$type, $options['name'], $options, null, $pod, $id ) ) {
107 if ( pods_v( 'read_only', $options, false ) ) {
108 $options['readonly'] = true;
109
110 $field_type = 'text';
111 } else {
112 return;
113 }
114 } elseif ( ! pods_has_permissions( $options ) && pods_v( 'read_only', $options, false ) ) {
115 $options['readonly'] = true;
116
117 $field_type = 'text';
118 }
119
120 pods_view( PODS_DIR . 'ui/fields/' . $field_type . '.php', compact( array_keys( get_defined_vars() ) ) );
121 }
122
123 /**
124 * {@inheritdoc}
125 */
126 public function validate( $value, $name = null, $options = null, $fields = null, $pod = null, $id = null, $params = null ) {
127 $validate = parent::validate( $value, $name, $options, $fields, $pod, $id, $params );
128
129 $errors = array();
130
131 if ( is_array( $validate ) ) {
132 $errors = $validate;
133 }
134
135 $check = $this->pre_save( $value, $id, $name, $options, $fields, $pod, $params );
136
137 if ( is_array( $check ) ) {
138 $errors = $check;
139 } else {
140 if ( 0 < strlen( $value ) && '' === $check ) {
141 $label = pods_v( 'label', $options, ucwords( str_replace( '_', ' ', $name ) ) );
142
143 if ( $this->is_required( $options ) ) {
144 $errors[] = sprintf( __( '%s is required', 'pods' ), $label );
145 } else {
146 $errors[] = sprintf( __( 'Invalid e-mail provided for %s', 'pods' ), $label );
147 }
148 }
149 }
150
151 if ( ! empty( $errors ) ) {
152 return $errors;
153 }
154
155 return $validate;
156 }
157
158 /**
159 * {@inheritdoc}
160 */
161 public function pre_save( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) {
162
163 $options = (array) $options;
164
165 if ( ! is_email( $value ) ) {
166 $value = '';
167 }
168
169 $length = (int) pods_v( static::$type . '_max_length', $options, 255 );
170
171 if ( 0 < $length && $length < pods_mb_strlen( $value ) ) {
172 $value = pods_mb_substr( $value, 0, $length );
173 }
174
175 return $value;
176 }
177
178 /**
179 * {@inheritdoc}
180 */
181 public function ui( $id, $value, $name = null, $options = null, $fields = null, $pod = null ) {
182
183 return '<a href="mailto:' . esc_attr( $value ) . '">' . $value . '</a>';
184 }
185 }
186