PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 3.3.4
Pods – Custom Content Types and Fields v3.3.4
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 / password.php
pods / classes / fields Last commit date
avatar.php 3 years ago boolean.php 3 years ago code.php 2 years ago color.php 1 year ago comment.php 4 years ago currency.php 9 months ago date.php 2 years ago datetime.php 1 year ago email.php 1 year ago file.php 11 months ago heading.php 1 year ago html.php 2 years ago link.php 1 year ago number.php 9 months ago oembed.php 1 year ago paragraph.php 2 years ago password.php 1 year ago phone.php 1 year ago pick.php 11 months ago slug.php 3 years ago taxonomy.php 4 years ago text.php 2 years ago time.php 2 years ago website.php 11 months ago wysiwyg.php 1 year ago
password.php
155 lines
1 <?php
2
3 /**
4 * @package Pods\Fields
5 */
6 class PodsField_Password extends PodsField {
7
8 /**
9 * {@inheritdoc}
10 */
11 public static $group = 'Text';
12
13 /**
14 * {@inheritdoc}
15 */
16 public static $type = 'password';
17
18 /**
19 * {@inheritdoc}
20 */
21 public static $label = 'Password';
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 = __( 'Password', 'pods' );
35 }
36
37 /**
38 * {@inheritdoc}
39 */
40 public function options() {
41 $options = [
42 static::$type . '_max_length' => [
43 'label' => __( 'Maximum Length', 'pods' ),
44 'default' => 255,
45 'type' => 'number',
46 'help' => __( 'Set to -1 for no limit', 'pods' ),
47 ],
48 static::$type . '_placeholder' => [
49 'label' => __( 'HTML Placeholder', 'pods' ),
50 'default' => '',
51 'type' => 'text',
52 'help' => [
53 __( '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' ),
54 'https://www.w3.org/WAI/tutorials/forms/instructions/#placeholder-text',
55 ],
56 ],
57 ];
58
59 return $options;
60 }
61
62 /**
63 * {@inheritdoc}
64 */
65 public function schema( $options = null ) {
66
67 $length = (int) pods_v( static::$type . '_max_length', $options, 255 );
68
69 $schema = 'VARCHAR(' . $length . ')';
70
71 if ( 255 < $length || $length < 1 ) {
72 $schema = 'LONGTEXT';
73 }
74
75 return $schema;
76 }
77
78 /**
79 * {@inheritdoc}
80 */
81 public function input( $name, $value = null, $options = null, $pod = null, $id = null ) {
82
83 $options = ( is_array( $options ) || is_object( $options ) ) ? $options : (array) $options;
84 $form_field_type = PodsForm::$field_type;
85
86 $value = $this->normalize_value_for_input( $value, $options );
87
88 if ( isset( $options['name'] ) && ! pods_permission( $options ) ) {
89 if ( pods_v( 'read_only', $options, false ) ) {
90 $options['readonly'] = true;
91 } else {
92 return;
93 }
94 } elseif ( ! pods_has_permissions( $options ) && pods_v( 'read_only', $options, false ) ) {
95 $options['readonly'] = true;
96 }
97
98 if ( ! empty( $options['disable_dfv'] ) ) {
99 return pods_view( PODS_DIR . 'ui/fields/password.php', compact( array_keys( get_defined_vars() ) ) );
100 }
101
102 $type = pods_v( 'type', $options, static::$type );
103
104 $args = compact( array_keys( get_defined_vars() ) );
105 $args = (object) $args;
106
107 $this->render_input_script( $args );
108 }
109
110 /**
111 * {@inheritdoc}
112 */
113 public function validate( $value, $name = null, $options = null, $fields = null, $pod = null, $id = null, $params = null ) {
114 $validate = parent::validate( $value, $name, $options, $fields, $pod, $id, $params );
115
116 $errors = array();
117
118 if ( is_array( $validate ) ) {
119 $errors = $validate;
120 }
121
122 $check = $this->pre_save( $value, $id, $name, $options, $fields, $pod, $params );
123
124 if ( is_array( $check ) ) {
125 $errors = $check;
126 } else {
127 if ( 0 < strlen( (string) $value ) && '' === $check ) {
128 if ( $this->is_required( $options ) ) {
129 $errors[] = __( 'This field is required.', 'pods' );
130 }
131 }
132 }
133
134 if ( ! empty( $errors ) ) {
135 return $errors;
136 }
137
138 return $validate;
139 }
140
141 /**
142 * {@inheritdoc}
143 */
144 public function pre_save( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) {
145
146 $length = (int) pods_v( static::$type . '_max_length', $options, 255 );
147
148 if ( 0 < $length && $length < pods_mb_strlen( $value ) ) {
149 $value = pods_mb_substr( $value, 0, $length );
150 }
151
152 return $value;
153 }
154 }
155