PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 3.1.4.2
Pods – Custom Content Types and Fields v3.1.4.2
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 / paragraph.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
paragraph.php
301 lines
1 <?php
2
3 /**
4 * @package Pods\Fields
5 */
6 class PodsField_Paragraph extends PodsField {
7
8 /**
9 * {@inheritdoc}
10 */
11 public static $group = 'Paragraph';
12
13
14 /**
15 * {@inheritdoc}
16 */
17 public static $type = 'paragraph';
18
19
20 /**
21 * {@inheritdoc}
22 */
23 public static $label = 'Plain Paragraph Text';
24
25
26 /**
27 * {@inheritdoc}
28 */
29 public static $prepare = '%s';
30
31
32 /**
33 * {@inheritdoc}
34 */
35 public function setup() {
36
37 static::$group = __( 'Paragraph', 'pods' );
38 static::$label = __( 'Plain Paragraph Text', 'pods' );
39 }
40
41 /**
42 * {@inheritdoc}
43 */
44 public function options() {
45 $options = [
46 'output_options' => [
47 'label' => __( 'Output Options', 'pods' ),
48 'type' => 'boolean_group',
49 'boolean_group' => [
50 static::$type . '_trim' => [
51 'label' => __( 'Trim extra whitespace before/after contents', 'pods' ),
52 'default' => 1,
53 'type' => 'boolean',
54 ],
55 static::$type . '_trim_lines' => [
56 'label' => __( 'Trim whitespace at the end of lines', 'pods' ),
57 'default' => 0,
58 'type' => 'boolean',
59 ],
60 static::$type . '_trim_p_brs' => [
61 'label' => __( 'Remove blank lines including empty "p" tags and "br" tags', 'pods' ),
62 'default' => 0,
63 'type' => 'boolean',
64 ],
65 static::$type . '_trim_extra_lines' => [
66 'label' => __( 'Remove extra blank lines (when there are 3+ blank lines, replace with a maximum of 2)', 'pods' ),
67 'default' => 0,
68 'type' => 'boolean',
69 ],
70 static::$type . '_allow_html' => [
71 'label' => __( 'Allow HTML', 'pods' ),
72 'default' => 1,
73 'type' => 'boolean',
74 'dependency' => true,
75 ],
76 static::$type . '_sanitize_html' => [
77 'label' => __( 'Sanitize HTML', 'pods' ),
78 'default' => 1,
79 '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' ),
80 'type' => 'boolean',
81 'dependency' => true,
82 ],
83 static::$type . '_oembed' => [
84 'label' => __( 'Enable oEmbed', 'pods' ),
85 'default' => 0,
86 'type' => 'boolean',
87 'help' => [
88 __( 'Embed videos, images, tweets, and other content.', 'pods' ),
89 'https://wordpress.org/support/article/embeds/',
90 ],
91 ],
92 static::$type . '_wptexturize' => [
93 'label' => __( 'Enable wptexturize', 'pods' ),
94 'default' => 1,
95 'type' => 'boolean',
96 'help' => [
97 __( 'Transforms less-beautiful text characters into stylized equivalents.', 'pods' ),
98 'https://developer.wordpress.org/reference/functions/wptexturize/',
99 ],
100 ],
101 static::$type . '_convert_chars' => [
102 'label' => __( 'Enable convert_chars', 'pods' ),
103 'default' => 1,
104 'type' => 'boolean',
105 'help' => [
106 __( 'Converts text into valid XHTML and Unicode', 'pods' ),
107 'https://developer.wordpress.org/reference/functions/convert_chars/',
108 ],
109 ],
110 static::$type . '_wpautop' => [
111 'label' => __( 'Enable wpautop', 'pods' ),
112 'default' => 1,
113 'type' => 'boolean',
114 'help' => [
115 __( 'Changes double line-breaks in the text into HTML paragraphs', 'pods' ),
116 'https://developer.wordpress.org/reference/functions/wpautop/',
117 ],
118 ],
119 static::$type . '_allow_shortcode' => [
120 'label' => __( 'Allow Shortcodes', 'pods' ),
121 'default' => 0,
122 'type' => 'boolean',
123 'dependency' => true,
124 'help' => [
125 __( 'Embed [shortcodes] that help transform your static content into dynamic content.', 'pods' ),
126 'https://codex.wordpress.org/Shortcode_API',
127 ],
128 ],
129 ],
130 ],
131 static::$type . '_allowed_html_tags' => [
132 'label' => __( 'Allowed HTML Tags', 'pods' ),
133 'depends-on' => [ static::$type . '_allow_html' => true ],
134 'default' => 'strong em a ul ol li b i',
135 'type' => 'text',
136 'help' => __( 'Format: strong em a ul ol li b i', 'pods' ),
137 ],
138 static::$type . '_max_length' => [
139 'label' => __( 'Maximum Length', 'pods' ),
140 'default' => - 1,
141 'type' => 'number',
142 'help' => __( 'Set to -1 for no limit', 'pods' ),
143 ],
144 static::$type . '_placeholder' => [
145 'label' => __( 'HTML Placeholder', 'pods' ),
146 'default' => '',
147 'type' => 'text',
148 'help' => [
149 __( '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' ),
150 'https://www.w3.org/WAI/tutorials/forms/instructions/#placeholder-text',
151 ],
152 ],
153 ];
154
155 return $options;
156 }
157
158 /**
159 * {@inheritdoc}
160 */
161 public function schema( $options = null ) {
162
163 $length = (int) pods_v( static::$type . '_max_length', $options, 0 );
164
165 $schema = 'LONGTEXT';
166
167 if ( 0 < $length ) {
168 $schema = 'VARCHAR(' . $length . ')';
169 }
170
171 return $schema;
172 }
173
174 /**
175 * {@inheritdoc}
176 */
177 public function display( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
178 $value = $this->strip_html( $value, $options );
179
180 /**
181 * Allow filtering of the display value for the Paragraph field type before it's processed.
182 *
183 * NOTE: HTML has already been stripped at this point.
184 *
185 * @since 3.1.0
186 *
187 * @param mixed|null $value Current value.
188 * @param string $type Field type.
189 * @param string|null $name Field name.
190 * @param array|null $options Field options.
191 * @param array|null $pod Pod information.
192 * @param int|string|null $id Current item ID.
193 */
194 $value = apply_filters( 'pods_form_ui_field_paragraph_display_value_pre_process', $value, static::$type, $name, $options, $pod, $id );
195
196 $value = $this->strip_shortcodes( $value, $options );
197 $value = $this->trim_whitespace( $value, $options );
198
199 if ( 1 === (int) pods_v( static::$type . '_oembed', $options, 0 ) ) {
200 $embed = $GLOBALS['wp_embed'];
201 $value = $embed->run_shortcode( $value );
202 $value = $embed->autoembed( $value );
203 }
204
205 if ( 1 === (int) pods_v( static::$type . '_wptexturize', $options, 1 ) ) {
206 $value = wptexturize( $value );
207 }
208
209 if ( 1 === (int) pods_v( static::$type . '_convert_chars', $options, 1 ) ) {
210 $value = convert_chars( $value );
211 }
212
213 if ( 1 === (int) pods_v( static::$type . '_wpautop', $options, 1 ) ) {
214 $value = wpautop( $value );
215 }
216
217 if ( 1 === (int) pods_v( static::$type . '_allow_shortcode', $options, 0 ) ) {
218 if ( 1 === (int) pods_v( static::$type . '_wpautop', $options, 1 ) ) {
219 $value = shortcode_unautop( $value );
220 }
221
222 $value = do_shortcode( $value );
223 }
224
225 /**
226 * Allow filtering of the display value for the Paragraph field type.
227 *
228 * @since 3.1.0
229 *
230 * @param mixed|null $value Current value.
231 * @param string $type Field type.
232 * @param string|null $name Field name.
233 * @param array|null $options Field options.
234 * @param array|null $pod Pod information.
235 * @param int|string|null $id Current item ID.
236 */
237 return apply_filters( 'pods_form_ui_field_paragraph_display_value', $value, static::$type, $name, $options, $pod, $id );
238 }
239
240 /**
241 * {@inheritdoc}
242 */
243 public function input( $name, $value = null, $options = null, $pod = null, $id = null ) {
244
245 $options = ( is_array( $options ) || is_object( $options ) ) ? $options : (array) $options;
246 $form_field_type = PodsForm::$field_type;
247
248 $value = $this->normalize_value_for_input( $value, $options, "\n" );
249
250 if ( isset( $options['name'] ) && ! pods_permission( $options ) ) {
251 if ( pods_v( 'read_only', $options, false ) ) {
252 $options['readonly'] = true;
253 } else {
254 return;
255 }
256 } elseif ( ! pods_has_permissions( $options ) && pods_v( 'read_only', $options, false ) ) {
257 $options['readonly'] = true;
258 }
259
260 if ( ! empty( $options['disable_dfv'] ) ) {
261 return pods_view( PODS_DIR . 'ui/fields/textarea.php', compact( array_keys( get_defined_vars() ) ) );
262 }
263
264 $type = pods_v( 'type', $options, static::$type );
265
266 $args = compact( array_keys( get_defined_vars() ) );
267 $args = (object) $args;
268
269 $this->render_input_script( $args );
270
271 }
272
273 /**
274 * {@inheritdoc}
275 */
276 public function pre_save( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) {
277 $value = $this->strip_html( $value, $options );
278 $value = $this->strip_shortcodes( $value, $options );
279 $value = $this->trim_whitespace( $value, $options );
280
281 $length = (int) pods_v( static::$type . '_max_length', $options, 0 );
282
283 if ( 0 < $length && $length < pods_mb_strlen( $value ) ) {
284 $value = pods_mb_substr( $value, 0, $length );
285 }
286
287 return $value;
288 }
289
290 /**
291 * {@inheritdoc}
292 */
293 public function ui( $id, $value, $name = null, $options = null, $fields = null, $pod = null ) {
294 $value = $this->strip_html( $value, $options );
295 $value = $this->strip_shortcodes( $value, $options );
296 $value = $this->trim_whitespace( $value, $options );
297
298 return wp_trim_words( $value );
299 }
300 }
301