PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 3.3.4
Pods – Custom Content Types and Fields v3.3.4
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 3 years ago boolean.php 3 years ago code.php 2 years ago color.php 1 year ago comment.php 4 years ago currency.php 9 months ago date.php 2 years ago datetime.php 1 year ago email.php 1 year ago file.php 11 months ago heading.php 1 year ago html.php 2 years ago link.php 1 year ago number.php 9 months ago oembed.php 1 year ago paragraph.php 2 years ago password.php 1 year ago phone.php 1 year ago pick.php 11 months ago slug.php 3 years ago taxonomy.php 4 years ago text.php 2 years ago time.php 2 years ago website.php 11 months ago wysiwyg.php 1 year ago
paragraph.php
302 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->maybe_sanitize_output( $value, $options );
249 $value = $this->normalize_value_for_input( $value, $options, "\n" );
250
251 if ( isset( $options['name'] ) && ! pods_permission( $options ) ) {
252 if ( pods_v( 'read_only', $options, false ) ) {
253 $options['readonly'] = true;
254 } else {
255 return;
256 }
257 } elseif ( ! pods_has_permissions( $options ) && pods_v( 'read_only', $options, false ) ) {
258 $options['readonly'] = true;
259 }
260
261 if ( ! empty( $options['disable_dfv'] ) ) {
262 return pods_view( PODS_DIR . 'ui/fields/textarea.php', compact( array_keys( get_defined_vars() ) ) );
263 }
264
265 $type = pods_v( 'type', $options, static::$type );
266
267 $args = compact( array_keys( get_defined_vars() ) );
268 $args = (object) $args;
269
270 $this->render_input_script( $args );
271
272 }
273
274 /**
275 * {@inheritdoc}
276 */
277 public function pre_save( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) {
278 $value = $this->strip_html( $value, $options );
279 $value = $this->strip_shortcodes( $value, $options );
280 $value = $this->trim_whitespace( $value, $options );
281
282 $length = (int) pods_v( static::$type . '_max_length', $options, 0 );
283
284 if ( 0 < $length && $length < pods_mb_strlen( $value ) ) {
285 $value = pods_mb_substr( $value, 0, $length );
286 }
287
288 return $value;
289 }
290
291 /**
292 * {@inheritdoc}
293 */
294 public function ui( $id, $value, $name = null, $options = null, $fields = null, $pod = null ) {
295 $value = $this->strip_html( $value, $options );
296 $value = $this->strip_shortcodes( $value, $options );
297 $value = $this->trim_whitespace( $value, $options );
298
299 return wp_trim_words( $value );
300 }
301 }
302