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