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 / heading.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
heading.php
200 lines
1 <?php
2
3 use Pods\Whatsit\Field;
4
5 /**
6 * @package Pods\Fields
7 */
8 class PodsField_Heading extends PodsField {
9
10 /**
11 * {@inheritdoc}
12 */
13 public static $group = 'Layout Elements';
14
15 /**
16 * {@inheritdoc}
17 */
18 public static $type = 'heading';
19
20 /**
21 * {@inheritdoc}
22 */
23 public static $label = 'Heading';
24
25 /**
26 * {@inheritdoc}
27 */
28 public static $prepare = '%s';
29
30 /**
31 * {@inheritdoc}
32 */
33 public function setup() {
34 static::$group = __( 'Layout Elements', 'pods' );
35 static::$label = __( 'Heading', 'pods' );
36 }
37
38 /**
39 * {@inheritdoc}
40 */
41 public function options() {
42 return [
43 static::$type . '_tag' => [
44 'label' => __( 'Heading HTML Tag', 'pods' ),
45 'type' => 'pick',
46 'data' => [
47 'h1' => 'h1',
48 'h2' => 'h2',
49 'h3' => 'h3',
50 'h4' => 'h4',
51 'h5' => 'h5',
52 'h6' => 'h6',
53 'p' => 'p',
54 'div' => 'div',
55 ],
56 'default' => 'h2',
57 'description' => __( 'Leave this empty to use the default heading tag for the form context the heading appears in.', 'pods' ),
58 'help' => __( 'This is the heading HTML tag to use for the heading text. Example "h2" will output your heading as <code>&lt;h2&gt;Heading Text&lt;/h2&gt;</code>', 'pods' ),
59 ],
60 'output_options' => [
61 'label' => __( 'Output Options', 'pods' ),
62 'type' => 'boolean_group',
63 'boolean_group' => [
64 static::$type . '_allow_html' => [
65 'label' => __( 'Allow HTML', 'pods' ),
66 'default' => 1,
67 'type' => 'boolean',
68 'dependency' => true,
69 ],
70 static::$type . '_sanitize_html' => [
71 'label' => __( 'Sanitize HTML', 'pods' ),
72 'default' => 1,
73 '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' ),
74 'type' => 'boolean',
75 'dependency' => true,
76 ],
77 static::$type . '_wptexturize' => [
78 'label' => __( 'Enable wptexturize', 'pods' ),
79 'default' => 1,
80 'type' => 'boolean',
81 'help' => [
82 __( 'Transforms less-beautiful text characters into stylized equivalents.', 'pods' ),
83 'http://codex.wordpress.org/Function_Reference/wptexturize',
84 ],
85 ],
86 static::$type . '_allow_shortcode' => [
87 'label' => __( 'Allow Shortcodes', 'pods' ),
88 'default' => 0,
89 'type' => 'boolean',
90 'dependency' => true,
91 'help' => [
92 __( 'Embed [shortcodes] that help transform your static content into dynamic content.', 'pods' ),
93 'http://codex.wordpress.org/Shortcode_API',
94 ],
95 ],
96 ],
97 ],
98 ];
99 }
100
101 /**
102 * {@inheritdoc}
103 */
104 public function schema( $options = null ) {
105 return false;
106 }
107
108 /**
109 * {@inheritdoc}
110 */
111 public function input( $name, $value = null, $options = null, $pod = null, $id = null ) {
112 $options = ( is_array( $options ) || is_object( $options ) ) ? $options : (array) $options;
113
114 $options[ static::$type . '_tag' ] = static::get_heading_tag( $options );
115
116 // Format content.
117 $options[ 'label' ] = $this->display( $options[ 'label' ], $name, $options, $pod, $id );
118
119 if ( isset( $options['_field_object'] ) && $options['_field_object'] instanceof Field ) {
120 $options['_field_object']->set_arg( 'label', $options[ 'label' ] );
121 }
122
123 $type = pods_v( 'type', $options, static::$type );
124
125 $args = compact( array_keys( get_defined_vars() ) );
126 $args = (object) $args;
127
128 $this->render_input_script( $args );
129 }
130
131 /**
132 * {@inheritdoc}
133 */
134 public function display( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
135 // Support passing label into the options for custom HTML option layouts.
136 if ( empty( $value ) && ! empty( $options[ 'label' ] ) ) {
137 $value = $options[ 'label' ];
138 }
139
140 $value = $this->strip_html( $value, $options );
141 $value = $this->strip_shortcodes( $value, $options );
142 $value = $this->trim_whitespace( $value, $options );
143
144 if ( 1 === (int) pods_v( static::$type . '_wptexturize', $options, 1 ) ) {
145 $value = wptexturize( $value );
146 }
147
148 if ( 1 === (int) pods_v( static::$type . '_allow_shortcode', $options, 0 ) ) {
149 $value = do_shortcode( $value );
150 }
151
152 return $value;
153 }
154
155 /**
156 * {@inheritdoc}
157 */
158 public function ui( $id, $value, $name = null, $options = null, $fields = null, $pod = null ) {
159 $value = $this->strip_html( $value, $options );
160 $value = $this->strip_shortcodes( $value, $options );
161 $value = $this->trim_whitespace( $value, $options );
162
163 return wp_trim_words( $value );
164 }
165
166 /**
167 * Get the heading tag from the field options and ensure it's allowed.
168 *
169 * @since 3.2.7.1
170 *
171 * @param array|Field $options The field data.
172 * @param null|string $default The default heading tag to use.
173 *
174 * @return string The heading tag.
175 */
176 public static function get_heading_tag( $options, ?string $default = null ): string {
177 // Only allow specific HTML tags.
178 $allowed_html_tags = [
179 'h1' => 'h1',
180 'h2' => 'h2',
181 'h3' => 'h3',
182 'h4' => 'h4',
183 'h5' => 'h5',
184 'h6' => 'h6',
185 'p' => 'p',
186 'div' => 'div',
187 ];
188
189 $heading_tag = 'h2';
190
191 if ( ! empty( $options[ static::$type . '_tag' ] ) && isset( $allowed_html_tags[ $options[ static::$type . '_tag' ] ] ) ) {
192 $heading_tag = $options[ static::$type . '_tag' ];
193 } elseif ( ! empty( $default ) && isset( $allowed_html_tags[ $default ] ) ) {
194 $heading_tag = $default;
195 }
196
197 return $heading_tag;
198 }
199 }
200