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