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