PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 3.0.10.5
Pods – Custom Content Types and Fields v3.0.10.5
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 / text.php
pods / classes / fields Last commit date
avatar.php 2 days ago boolean.php 2 days ago code.php 2 days ago color.php 2 days ago comment.php 2 days ago currency.php 2 days ago date.php 2 days ago datetime.php 2 days ago email.php 2 days ago file.php 2 days ago heading.php 2 days ago html.php 2 days ago link.php 2 days ago number.php 2 days ago oembed.php 2 days ago paragraph.php 2 days ago password.php 2 days ago phone.php 2 days ago pick.php 2 days ago slug.php 2 days ago taxonomy.php 2 days ago text.php 2 days ago time.php 2 days ago website.php 2 days ago wysiwyg.php 2 days ago
text.php
232 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 . '_allow_shortcode' => [
73 'label' => __( 'Allow Shortcodes', 'pods' ),
74 'default' => 0,
75 'type' => 'boolean',
76 'dependency' => true,
77 ],
78 ],
79 ],
80 static::$type . '_allowed_html_tags' => [
81 'label' => __( 'Allowed HTML Tags', 'pods' ),
82 'depends-on' => [ static::$type . '_allow_html' => true ],
83 'default' => 'strong em a ul ol li b i',
84 'type' => 'text',
85 ],
86 static::$type . '_max_length' => [
87 'label' => __( 'Maximum Length', 'pods' ),
88 'default' => 255,
89 'type' => 'number',
90 'help' => __( 'Set to -1 for no limit', 'pods' ),
91 ],
92 static::$type . '_placeholder' => [
93 'label' => __( 'HTML Placeholder', 'pods' ),
94 'default' => '',
95 'type' => 'text',
96 'help' => [
97 __( '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' ),
98 'https://www.w3.org/WAI/tutorials/forms/instructions/#placeholder-text',
99 ],
100 ],
101 ];
102 }
103
104 /**
105 * {@inheritdoc}
106 */
107 public function schema( $options = null ) {
108
109 $length = (int) pods_v( static::$type . '_max_length', $options, 255 );
110
111 $schema = 'VARCHAR(' . $length . ')';
112
113 if ( 255 < $length || $length < 1 ) {
114 $schema = 'LONGTEXT';
115 }
116
117 return $schema;
118 }
119
120 /**
121 * {@inheritdoc}
122 */
123 public function display( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
124 $value = $this->strip_html( $value, $options );
125 $value = $this->strip_shortcodes( $value, $options );
126 $value = $this->trim_whitespace( $value, $options );
127
128 if ( 1 === (int) pods_v( static::$type . '_allow_shortcode', $options ) ) {
129 $value = do_shortcode( $value );
130 }
131
132 return $value;
133 }
134
135 /**
136 * {@inheritdoc}
137 */
138 public function input( $name, $value = null, $options = null, $pod = null, $id = null ) {
139
140 $options = ( is_array( $options ) || is_object( $options ) ) ? $options : (array) $options;
141 $form_field_type = PodsForm::$field_type;
142
143 $value = $this->normalize_value_for_input( $value, $options );
144
145 $is_read_only = (boolean) pods_v( 'read_only', $options, false );
146
147 if ( isset( $options['name'] ) && ! pods_permission( $options ) ) {
148 if ( $is_read_only ) {
149 $options['readonly'] = true;
150 } else {
151 return;
152 }
153 } elseif ( ! pods_has_permissions( $options ) && $is_read_only ) {
154 $options['readonly'] = true;
155 }
156
157 if ( ! empty( $options['disable_dfv'] ) ) {
158 return pods_view( PODS_DIR . 'ui/fields/text.php', compact( array_keys( get_defined_vars() ) ) );
159 }
160
161 $type = pods_v( 'type', $options, static::$type );
162
163 $args = compact( array_keys( get_defined_vars() ) );
164 $args = (object) $args;
165
166 $this->render_input_script( $args );
167 }
168
169 /**
170 * {@inheritdoc}
171 */
172 public function validate( $value, $name = null, $options = null, $fields = null, $pod = null, $id = null, $params = null ) {
173 $validate = parent::validate( $value, $name, $options, $fields, $pod, $id, $params );
174
175 $errors = array();
176
177 if ( is_array( $validate ) ) {
178 $errors = $validate;
179 }
180
181 $check = $this->pre_save( $value, $id, $name, $options, $fields, $pod, $params );
182
183 if ( is_array( $check ) ) {
184 $errors = $check;
185 } else {
186 if ( '' !== $value && '' === $check ) {
187 if ( $this->is_required( $options ) ) {
188 $errors[] = __( 'This field is required.', 'pods' );
189 }
190 }
191 }
192
193 if ( ! empty( $errors ) ) {
194 return $errors;
195 }
196
197 return $validate;
198 }
199
200 /**
201 * {@inheritdoc}
202 */
203 public function pre_save( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) {
204 $value = $this->strip_html( $value, $options );
205 $value = $this->strip_shortcodes( $value, $options );
206 $value = $this->trim_whitespace( $value, $options );
207
208 $length = (int) pods_v( static::$type . '_max_length', $options, 255 );
209
210 if ( 0 < $length && $length < pods_mb_strlen( $value ) ) {
211 $value = pods_mb_substr( $value, 0, $length );
212 }
213
214 return $value;
215 }
216
217 /**
218 * {@inheritdoc}
219 */
220 public function ui( $id, $value, $name = null, $options = null, $fields = null, $pod = null ) {
221 $value = $this->strip_html( $value, $options );
222 $value = $this->strip_shortcodes( $value, $options );
223 $value = $this->trim_whitespace( $value, $options );
224
225 if ( 0 === (int) pods_v( static::$type . '_allow_html', $options, 0, true ) ) {
226 $value = wp_trim_words( $value );
227 }
228
229 return $value;
230 }
231 }
232