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