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 / password.php
pods / classes / fields Last commit date
avatar.php 3 days ago boolean.php 3 days ago code.php 3 days ago color.php 3 days ago comment.php 3 days ago currency.php 3 days ago date.php 3 days ago datetime.php 3 days ago email.php 3 days ago file.php 3 days ago html.php 3 days ago link.php 3 days ago number.php 3 days ago oembed.php 3 days ago paragraph.php 3 days ago password.php 3 days ago phone.php 3 days ago pick.php 3 days ago slug.php 3 days ago taxonomy.php 3 days ago text.php 3 days ago time.php 3 days ago website.php 3 days ago wysiwyg.php 3 days ago
password.php
148 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 self::$label = __( 'Password', 'pods' );
34 }
35
36 /**
37 * {@inheritdoc}
38 */
39 public function options() {
40
41 $options = array(
42 static::$type . '_max_length' => array(
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' => array(
49 'label' => __( 'HTML Placeholder', 'pods' ),
50 'default' => '',
51 'type' => 'text',
52 'help' => array(
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 = (array) $options;
84 $form_field_type = PodsForm::$field_type;
85
86 if ( is_array( $value ) ) {
87 $value = implode( ' ', $value );
88 }
89
90 if ( isset( $options['name'] ) && false === PodsForm::permission( static::$type, $options['name'], $options, null, $pod, $id ) ) {
91 if ( pods_v( 'read_only', $options, false ) ) {
92 $options['readonly'] = true;
93 } else {
94 return;
95 }
96 } elseif ( ! pods_has_permissions( $options ) && pods_v( 'read_only', $options, false ) ) {
97 $options['readonly'] = true;
98 }
99
100 pods_view( PODS_DIR . 'ui/fields/password.php', compact( array_keys( get_defined_vars() ) ) );
101 }
102
103 /**
104 * {@inheritdoc}
105 */
106 public function validate( $value, $name = null, $options = null, $fields = null, $pod = null, $id = null, $params = null ) {
107 $validate = parent::validate( $value, $name, $options, $fields, $pod, $id, $params );
108
109 $errors = array();
110
111 if ( is_array( $validate ) ) {
112 $errors = $validate;
113 }
114
115 $check = $this->pre_save( $value, $id, $name, $options, $fields, $pod, $params );
116
117 if ( is_array( $check ) ) {
118 $errors = $check;
119 } else {
120 if ( 0 < strlen( $value ) && '' === $check ) {
121 if ( $this->is_required( $options ) ) {
122 $errors[] = __( 'This field is required.', 'pods' );
123 }
124 }
125 }
126
127 if ( ! empty( $errors ) ) {
128 return $errors;
129 }
130
131 return $validate;
132 }
133
134 /**
135 * {@inheritdoc}
136 */
137 public function pre_save( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) {
138
139 $length = (int) pods_v( static::$type . '_max_length', $options, 255 );
140
141 if ( 0 < $length && $length < pods_mb_strlen( $value ) ) {
142 $value = pods_mb_substr( $value, 0, $length );
143 }
144
145 return $value;
146 }
147 }
148