PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 2.8.23.5
Pods – Custom Content Types and Fields v2.8.23.5
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 days ago boolean.php 2 days ago code.php 2 days ago color.php 2 days ago comment.php 2 days ago currency.php 2 days ago date.php 2 days ago datetime.php 2 days ago email.php 2 days ago file.php 2 days ago heading.php 2 days ago html.php 2 days ago link.php 2 days ago number.php 2 days ago oembed.php 2 days ago paragraph.php 2 days ago password.php 2 days ago phone.php 2 days ago pick.php 2 days ago slug.php 2 days ago taxonomy.php 2 days ago text.php 2 days ago time.php 2 days ago website.php 2 days ago wysiwyg.php 2 days ago
paragraph.php
275 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
46 $options = array(
47 static::$type . '_repeatable' => array(
48 'label' => __( 'Repeatable Field', 'pods' ),
49 'default' => 0,
50 'type' => 'boolean',
51 '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' ),
52 'boolean_yes_label' => '',
53 'dependency' => true,
54 'developer_mode' => true,
55 ),
56 'output_options' => array(
57 'label' => __( 'Output Options', 'pods' ),
58 'type' => 'boolean_group',
59 'boolean_group' => array(
60 static::$type . '_trim' => array(
61 'label' => __( 'Trim extra whitespace before/after contents', 'pods' ),
62 'default' => 1,
63 'type' => 'boolean',
64 'dependency' => true,
65 ),
66 static::$type . '_allow_html' => array(
67 'label' => __( 'Allow HTML', 'pods' ),
68 'default' => 1,
69 'type' => 'boolean',
70 'dependency' => true,
71 ),
72 static::$type . '_oembed' => array(
73 'label' => __( 'Enable oEmbed', 'pods' ),
74 'default' => 0,
75 'type' => 'boolean',
76 'help' => array(
77 __( 'Embed videos, images, tweets, and other content.', 'pods' ),
78 'https://wordpress.org/support/article/embeds/',
79 ),
80 ),
81 static::$type . '_wptexturize' => array(
82 'label' => __( 'Enable wptexturize', 'pods' ),
83 'default' => 1,
84 'type' => 'boolean',
85 'help' => array(
86 __( 'Transforms less-beautiful text characters into stylized equivalents.', 'pods' ),
87 'https://developer.wordpress.org/reference/functions/wptexturize/',
88 ),
89 ),
90 static::$type . '_convert_chars' => array(
91 'label' => __( 'Enable convert_chars', 'pods' ),
92 'default' => 1,
93 'type' => 'boolean',
94 'help' => array(
95 __( 'Converts text into valid XHTML and Unicode', 'pods' ),
96 'https://developer.wordpress.org/reference/functions/convert_chars/',
97 ),
98 ),
99 static::$type . '_wpautop' => array(
100 'label' => __( 'Enable wpautop', 'pods' ),
101 'default' => 1,
102 'type' => 'boolean',
103 'help' => array(
104 __( 'Changes double line-breaks in the text into HTML paragraphs', 'pods' ),
105 'https://developer.wordpress.org/reference/functions/wpautop/',
106 ),
107 ),
108 static::$type . '_allow_shortcode' => array(
109 'label' => __( 'Allow Shortcodes', 'pods' ),
110 'default' => 0,
111 'type' => 'boolean',
112 'dependency' => true,
113 'help' => array(
114 __( 'Embed [shortcodes] that help transform your static content into dynamic content.', 'pods' ),
115 'https://codex.wordpress.org/Shortcode_API',
116 ),
117 ),
118 ),
119 ),
120 static::$type . '_allowed_html_tags' => array(
121 'label' => __( 'Allowed HTML Tags', 'pods' ),
122 'depends-on' => array( static::$type . '_allow_html' => true ),
123 'default' => 'strong em a ul ol li b i',
124 'type' => 'text',
125 'help' => __( 'Format: strong em a ul ol li b i', 'pods' ),
126 ),
127 static::$type . '_max_length' => array(
128 'label' => __( 'Maximum Length', 'pods' ),
129 'default' => -1,
130 'type' => 'number',
131 'help' => __( 'Set to -1 for no limit', 'pods' ),
132 ),
133 static::$type . '_placeholder' => array(
134 'label' => __( 'HTML Placeholder', 'pods' ),
135 'default' => '',
136 'type' => 'text',
137 'help' => array(
138 __( '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' ),
139 'https://www.w3.org/WAI/tutorials/forms/instructions/#placeholder-text',
140 ),
141 ),
142 );
143
144 if ( function_exists( 'Markdown' ) ) {
145 $options['output_options']['boolean_group'][ static::$type . '_allow_markdown' ] = array(
146 'label' => __( 'Allow Markdown Syntax', 'pods' ),
147 'default' => 0,
148 'type' => 'boolean',
149 );
150 }
151
152 return $options;
153 }
154
155 /**
156 * {@inheritdoc}
157 */
158 public function schema( $options = null ) {
159
160 $length = (int) pods_v( static::$type . '_max_length', $options, 0 );
161
162 $schema = 'LONGTEXT';
163
164 if ( 0 < $length ) {
165 $schema = 'VARCHAR(' . $length . ')';
166 }
167
168 return $schema;
169 }
170
171 /**
172 * {@inheritdoc}
173 */
174 public function display( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
175 $value = $this->strip_html( $value, $options );
176 $value = $this->strip_shortcodes( $value, $options );
177 $value = $this->trim_whitespace( $value, $options );
178
179 if ( 1 === (int) pods_v( static::$type . '_oembed', $options, 0 ) ) {
180 $embed = $GLOBALS['wp_embed'];
181 $value = $embed->run_shortcode( $value );
182 $value = $embed->autoembed( $value );
183 }
184
185 if ( 1 === (int) pods_v( static::$type . '_wptexturize', $options, 1 ) ) {
186 $value = wptexturize( $value );
187 }
188
189 if ( 1 === (int) pods_v( static::$type . '_convert_chars', $options, 1 ) ) {
190 $value = convert_chars( $value );
191 }
192
193 if ( 1 === (int) pods_v( static::$type . '_wpautop', $options, 1 ) ) {
194 $value = wpautop( $value );
195 }
196
197 if ( 1 === (int) pods_v( static::$type . '_allow_shortcode', $options, 0 ) ) {
198 if ( 1 === (int) pods_v( static::$type . '_wpautop', $options, 1 ) ) {
199 $value = shortcode_unautop( $value );
200 }
201
202 $value = do_shortcode( $value );
203 }
204
205 if ( function_exists( 'Markdown' ) && 1 === (int) pods_v( static::$type . '_allow_markdown', $options ) ) {
206 $value = Markdown( $value );
207 }
208
209 return $value;
210 }
211
212 /**
213 * {@inheritdoc}
214 */
215 public function input( $name, $value = null, $options = null, $pod = null, $id = null ) {
216
217 $options = ( is_array( $options ) || is_object( $options ) ) ? $options : (array) $options;
218 $form_field_type = PodsForm::$field_type;
219
220 if ( is_array( $value ) ) {
221 $value = implode( "\n", $value );
222 }
223
224 if ( isset( $options['name'] ) && ! pods_permission( $options ) ) {
225 if ( pods_v( 'read_only', $options, false ) ) {
226 $options['readonly'] = true;
227 } else {
228 return;
229 }
230 } elseif ( ! pods_has_permissions( $options ) && pods_v( 'read_only', $options, false ) ) {
231 $options['readonly'] = true;
232 }
233
234 if ( ! empty( $options['disable_dfv'] ) ) {
235 return pods_view( PODS_DIR . 'ui/fields/textarea.php', compact( array_keys( get_defined_vars() ) ) );
236 }
237
238 $type = pods_v( 'type', $options, static::$type );
239
240 $args = compact( array_keys( get_defined_vars() ) );
241 $args = (object) $args;
242
243 $this->render_input_script( $args );
244
245 }
246
247 /**
248 * {@inheritdoc}
249 */
250 public function pre_save( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) {
251 $value = $this->strip_html( $value, $options );
252 $value = $this->strip_shortcodes( $value, $options );
253 $value = $this->trim_whitespace( $value, $options );
254
255 $length = (int) pods_v( static::$type . '_max_length', $options, 0 );
256
257 if ( 0 < $length && $length < pods_mb_strlen( $value ) ) {
258 $value = pods_mb_substr( $value, 0, $length );
259 }
260
261 return $value;
262 }
263
264 /**
265 * {@inheritdoc}
266 */
267 public function ui( $id, $value, $name = null, $options = null, $fields = null, $pod = null ) {
268 $value = $this->strip_html( $value, $options );
269 $value = $this->strip_shortcodes( $value, $options );
270 $value = $this->trim_whitespace( $value, $options );
271
272 return wp_trim_words( $value );
273 }
274 }
275