PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 2.8.23.4
Pods – Custom Content Types and Fields v2.8.23.4
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 weeks ago boolean.php 2 weeks ago code.php 2 weeks ago color.php 2 weeks ago comment.php 2 weeks ago currency.php 2 weeks ago date.php 2 weeks ago datetime.php 2 weeks ago email.php 2 weeks ago file.php 2 weeks ago heading.php 2 weeks ago html.php 2 weeks ago link.php 2 weeks ago number.php 2 weeks ago oembed.php 2 weeks ago paragraph.php 2 weeks ago password.php 2 weeks ago phone.php 2 weeks ago pick.php 2 weeks ago slug.php 2 weeks ago taxonomy.php 2 weeks ago text.php 2 weeks ago time.php 2 weeks ago website.php 2 weeks ago wysiwyg.php 2 weeks 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
42 $options = array(
43 static::$type . '_repeatable' => array(
44 'label' => __( 'Repeatable Field', 'pods' ),
45 'default' => 0,
46 'type' => 'boolean',
47 'help' => __( 'Making a field repeatable will add controls next to the field which allows users to Add/Remove/Reorder additional values. These values are saved in the database as an array, so searching and filtering by them may require further adjustments".', 'pods' ),
48 'boolean_yes_label' => '',
49 'dependency' => true,
50 'developer_mode' => true,
51 ),
52 'output_options' => array(
53 'label' => __( 'Output Options', 'pods' ),
54 'type' => 'boolean_group',
55 'boolean_group' => array(
56 static::$type . '_trim' => array(
57 'label' => __( 'Trim extra whitespace before/after contents', 'pods' ),
58 'default' => 1,
59 'type' => 'boolean',
60 'dependency' => true,
61 ),
62 static::$type . '_allow_html' => array(
63 'label' => __( 'Allow HTML', 'pods' ),
64 'default' => 0,
65 'type' => 'boolean',
66 'dependency' => true,
67 ),
68 static::$type . '_allow_shortcode' => array(
69 'label' => __( 'Allow Shortcodes', 'pods' ),
70 'default' => 0,
71 'type' => 'boolean',
72 'dependency' => true,
73 ),
74 ),
75 ),
76 static::$type . '_allowed_html_tags' => array(
77 'label' => __( 'Allowed HTML Tags', 'pods' ),
78 'depends-on' => array( static::$type . '_allow_html' => true ),
79 'default' => 'strong em a ul ol li b i',
80 'type' => 'text',
81 ),
82 static::$type . '_max_length' => array(
83 'label' => __( 'Maximum Length', 'pods' ),
84 'default' => 255,
85 'type' => 'number',
86 'help' => __( 'Set to -1 for no limit', 'pods' ),
87 ),
88 static::$type . '_placeholder' => array(
89 'label' => __( 'HTML Placeholder', 'pods' ),
90 'default' => '',
91 'type' => 'text',
92 'help' => array(
93 __( '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' ),
94 'https://www.w3.org/WAI/tutorials/forms/instructions/#placeholder-text',
95 ),
96 ),
97 );
98
99 return $options;
100 }
101
102 /**
103 * {@inheritdoc}
104 */
105 public function schema( $options = null ) {
106
107 $length = (int) pods_v( static::$type . '_max_length', $options, 255 );
108
109 $schema = 'VARCHAR(' . $length . ')';
110
111 if ( 255 < $length || $length < 1 ) {
112 $schema = 'LONGTEXT';
113 }
114
115 return $schema;
116 }
117
118 /**
119 * {@inheritdoc}
120 */
121 public function display( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
122 $value = $this->strip_html( $value, $options );
123 $value = $this->strip_shortcodes( $value, $options );
124 $value = $this->trim_whitespace( $value, $options );
125
126 if ( 1 === (int) pods_v( static::$type . '_allow_shortcode', $options ) ) {
127 $value = do_shortcode( $value );
128 }
129
130 return $value;
131 }
132
133 /**
134 * {@inheritdoc}
135 */
136 public function input( $name, $value = null, $options = null, $pod = null, $id = null ) {
137
138 $options = ( is_array( $options ) || is_object( $options ) ) ? $options : (array) $options;
139 $form_field_type = PodsForm::$field_type;
140
141 if ( is_array( $value ) ) {
142 $value = implode( ' ', $value );
143 }
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