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