PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 3.2.4
Pods – Custom Content Types and Fields v3.2.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 / text.php
pods / classes / fields Last commit date
avatar.php 3 years ago boolean.php 3 years ago code.php 2 years ago color.php 3 years ago comment.php 4 years ago currency.php 3 years ago date.php 2 years ago datetime.php 2 years ago email.php 3 years ago file.php 1 year ago heading.php 2 years ago html.php 2 years ago link.php 3 years ago number.php 2 years ago oembed.php 2 years ago paragraph.php 2 years ago password.php 3 years ago phone.php 3 years ago pick.php 1 year ago slug.php 3 years ago taxonomy.php 4 years ago text.php 2 years ago time.php 2 years ago website.php 3 years ago wysiwyg.php 2 years ago
text.php
239 lines
1 <?php
2
3 /**
4 * @package Pods\Fields
5 */
6 class PodsField_Text extends PodsField {
7
8 /**
9 * {@inheritdoc}
10 */
11 public static $group = 'Text';
12
13 /**
14 * {@inheritdoc}
15 */
16 public static $type = 'text';
17
18 /**
19 * {@inheritdoc}
20 */
21 public static $label = 'Plain Text';
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 = __( 'Plain Text', 'pods' );
35 }
36
37 /**
38 * {@inheritdoc}
39 */
40 public function options() {
41 return [
42 'output_options' => [
43 'label' => __( 'Output Options', 'pods' ),
44 'type' => 'boolean_group',
45 'boolean_group' => [
46 static::$type . '_trim' => [
47 'label' => __( 'Trim extra whitespace before/after contents', 'pods' ),
48 'default' => 1,
49 'type' => 'boolean',
50 ],
51 static::$type . '_trim_lines' => [
52 'label' => __( 'Trim whitespace at the end of lines', 'pods' ),
53 'default' => 0,
54 'type' => 'boolean',
55 ],
56 static::$type . '_trim_p_brs' => [
57 'label' => __( 'Remove blank lines including empty "p" tags and "br" tags', 'pods' ),
58 'default' => 0,
59 'type' => 'boolean',
60 ],
61 static::$type . '_trim_extra_lines' => [
62 'label' => __( 'Remove extra blank lines (when there are 3+ blank lines, replace with a maximum of 2)', 'pods' ),
63 'default' => 0,
64 'type' => 'boolean',
65 ],
66 static::$type . '_allow_html' => [
67 'label' => __( 'Allow HTML', 'pods' ),
68 'default' => 0,
69 'type' => 'boolean',
70 'dependency' => true,
71 ],
72 static::$type . '_sanitize_html' => [
73 'label' => __( 'Sanitize HTML', 'pods' ),
74 'default' => 1,
75 'help' => __( 'This sanitizes things like script tags and other content not normally allowed in WordPress content. Disable this only if you trust users who will have access to enter content into this field.', 'pods' ),
76 'type' => 'boolean',
77 'dependency' => true,
78 ],
79 static::$type . '_allow_shortcode' => [
80 'label' => __( 'Allow Shortcodes', 'pods' ),
81 'default' => 0,
82 'type' => 'boolean',
83 'dependency' => true,
84 ],
85 ],
86 ],
87 static::$type . '_allowed_html_tags' => [
88 'label' => __( 'Allowed HTML Tags', 'pods' ),
89 'depends-on' => [ static::$type . '_allow_html' => true ],
90 'default' => 'strong em a ul ol li b i',
91 'type' => 'text',
92 ],
93 static::$type . '_max_length' => [
94 'label' => __( 'Maximum Length', 'pods' ),
95 'default' => 255,
96 'type' => 'number',
97 'help' => __( 'Set to -1 for no limit', 'pods' ),
98 ],
99 static::$type . '_placeholder' => [
100 'label' => __( 'HTML Placeholder', 'pods' ),
101 'default' => '',
102 'type' => 'text',
103 'help' => [
104 __( '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' ),
105 'https://www.w3.org/WAI/tutorials/forms/instructions/#placeholder-text',
106 ],
107 ],
108 ];
109 }
110
111 /**
112 * {@inheritdoc}
113 */
114 public function schema( $options = null ) {
115
116 $length = (int) pods_v( static::$type . '_max_length', $options, 255 );
117
118 $schema = 'VARCHAR(' . $length . ')';
119
120 if ( 255 < $length || $length < 1 ) {
121 $schema = 'LONGTEXT';
122 }
123
124 return $schema;
125 }
126
127 /**
128 * {@inheritdoc}
129 */
130 public function display( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
131 $value = $this->strip_html( $value, $options );
132 $value = $this->strip_shortcodes( $value, $options );
133 $value = $this->trim_whitespace( $value, $options );
134
135 if ( 1 === (int) pods_v( static::$type . '_allow_shortcode', $options ) ) {
136 $value = do_shortcode( $value );
137 }
138
139 return $value;
140 }
141
142 /**
143 * {@inheritdoc}
144 */
145 public function input( $name, $value = null, $options = null, $pod = null, $id = null ) {
146
147 $options = ( is_array( $options ) || is_object( $options ) ) ? $options : (array) $options;
148 $form_field_type = PodsForm::$field_type;
149
150 $value = $this->normalize_value_for_input( $value, $options );
151
152 $is_read_only = (boolean) pods_v( 'read_only', $options, false );
153
154 if ( isset( $options['name'] ) && ! pods_permission( $options ) ) {
155 if ( $is_read_only ) {
156 $options['readonly'] = true;
157 } else {
158 return;
159 }
160 } elseif ( ! pods_has_permissions( $options ) && $is_read_only ) {
161 $options['readonly'] = true;
162 }
163
164 if ( ! empty( $options['disable_dfv'] ) ) {
165 return pods_view( PODS_DIR . 'ui/fields/text.php', compact( array_keys( get_defined_vars() ) ) );
166 }
167
168 $type = pods_v( 'type', $options, static::$type );
169
170 $args = compact( array_keys( get_defined_vars() ) );
171 $args = (object) $args;
172
173 $this->render_input_script( $args );
174 }
175
176 /**
177 * {@inheritdoc}
178 */
179 public function validate( $value, $name = null, $options = null, $fields = null, $pod = null, $id = null, $params = null ) {
180 $validate = parent::validate( $value, $name, $options, $fields, $pod, $id, $params );
181
182 $errors = array();
183
184 if ( is_array( $validate ) ) {
185 $errors = $validate;
186 }
187
188 $check = $this->pre_save( $value, $id, $name, $options, $fields, $pod, $params );
189
190 if ( is_array( $check ) ) {
191 $errors = $check;
192 } else {
193 if ( '' !== $value && '' === $check ) {
194 if ( $this->is_required( $options ) ) {
195 $errors[] = __( 'This field is required.', 'pods' );
196 }
197 }
198 }
199
200 if ( ! empty( $errors ) ) {
201 return $errors;
202 }
203
204 return $validate;
205 }
206
207 /**
208 * {@inheritdoc}
209 */
210 public function pre_save( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) {
211 $value = $this->strip_html( $value, $options );
212 $value = $this->strip_shortcodes( $value, $options );
213 $value = $this->trim_whitespace( $value, $options );
214
215 $length = (int) pods_v( static::$type . '_max_length', $options, 255 );
216
217 if ( 0 < $length && $length < pods_mb_strlen( $value ) ) {
218 $value = pods_mb_substr( $value, 0, $length );
219 }
220
221 return $value;
222 }
223
224 /**
225 * {@inheritdoc}
226 */
227 public function ui( $id, $value, $name = null, $options = null, $fields = null, $pod = null ) {
228 $value = $this->strip_html( $value, $options );
229 $value = $this->strip_shortcodes( $value, $options );
230 $value = $this->trim_whitespace( $value, $options );
231
232 if ( 0 === (int) pods_v( static::$type . '_allow_html', $options, 0, true ) ) {
233 $value = wp_trim_words( $value );
234 }
235
236 return $value;
237 }
238 }
239