PluginProbe
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant / 1.8
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant v1.8
2.3.2 2.3.1 2.3.0 2.2.8 2.2.7 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.11.0 1.11.1 1.11.2 1.6 1.7 1.8 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 1.9.10 1.9.11 All 60 releases
merchant / inc / helpers.php

helpers.php in Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant 1.8, at inc/helpers.php

364 lines 9.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Helper functions.
5 *
6 * @package Merchant
7 */
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit; // Exit if accessed directly
11 }
12
13 /**
14 * Allowed tags general.
15 * Should be used to escape complex outputs like entire features html.
16 *
17 * @param array $extra
18 * @param bool $include_post_tags Whether to include post kses allowed tags or not. Default true.
19 *
20 * @return array $allowed_tags
21 */
22 if ( ! function_exists( 'merchant_kses_allowed_tags' ) ) {
23 function merchant_kses_allowed_tags( $extra = array(), $include_post_tags = true ) {
24 // Default
25 $allowed_tags = array_merge(
26 array(
27 // Meta
28 'meta' => array(
29 'name' => true,
30 'content' => true,
31 ),
32
33 // SVG Support
34 'svg' => array(
35 'class' => true,
36 'xmlns' => true,
37 'width' => true,
38 'height' => true,
39 'viewbox' => true,
40 'aria-hidden' => true,
41 'role' => true,
42 'focusable' => true,
43 'fill' => true,
44 'stroke' => true,
45 'stroke-linecap' => true,
46 'stroke-linejoin' => true,
47 'stroke-width' => true,
48 ),
49 'g' => array(
50 'id' => true,
51 'class' => true,
52 'clip-path' => true,
53 'style' => true,
54 ),
55 'path' => array(
56 'fill' => true,
57 'fill-rule' => true,
58 'd' => true,
59 'transform' => true,
60 'stroke' => true,
61 'stroke-width' => true,
62 'stroke-linejoin' => true,
63 'clip-rule' => true,
64 ),
65 'polyline' => array(
66 'points' => true,
67 'fill' => true,
68 'fill-rule' => true,
69 'd' => true,
70 'transform' => true,
71 'stroke' => true,
72 'stroke-width' => true,
73 'stroke-linejoin' => true,
74 ),
75 'polygon' => array(
76 'fill' => true,
77 'fill-rule' => true,
78 'points' => true,
79 'transform' => true,
80 'focusable' => true,
81 'stroke' => true,
82 'stroke-width' => true,
83 ),
84 'rect' => array(
85 'x' => true,
86 'y' => true,
87 'rx' => true,
88 'width' => true,
89 'height' => true,
90 'transform' => true,
91 'fill' => true,
92 'stroke' => true,
93 'stroke-width' => true,
94 ),
95 'circle' => array(
96 'cx' => true,
97 'cy' => true,
98 'r' => true,
99 'width' => true,
100 'height' => true,
101 'transform' => true,
102 'fill' => true,
103 'stroke' => true,
104 'stroke-width' => true,
105 ),
106 'clipPath' => array(
107 'id' => true,
108 'class' => true,
109 'style' => true,
110 ),
111 'defs' => array(
112 'id' => true,
113 ),
114 ),
115 $include_post_tags ? wp_kses_allowed_html( 'post' ) : array()
116 );
117
118 // Include schema markup tags
119 if ( in_array( 'schema_markup', $extra ) || in_array( 'all', $extra ) ) {
120 $tags = array( 'meta', 'nav', 'ul', 'li', 'a', 'span' );
121
122 foreach ( $tags as $tag ) {
123 if ( isset( $allowed_tags[ $tag ] ) ) {
124 $allowed_tags[ $tag ]['itemprop'] = true;
125 $allowed_tags[ $tag ]['itemscope'] = true;
126 $allowed_tags[ $tag ]['itemtype'] = true;
127 } else {
128 $allowed_tags[ $tag ] = array(
129 'itemprop' => true,
130 'itemscope' => true,
131 'itemtype' => true,
132 );
133 }
134 }
135 }
136
137 // Include iframe tags
138 if ( in_array( 'iframe', $extra ) || in_array( 'all', $extra ) ) {
139 $allowed_tags['iframe'] = array(
140 'src' => true,
141 'height' => true,
142 'width' => true,
143 'frameborder' => true,
144 'allowfullscreen' => true,
145 );
146 }
147
148 // Include nonce tags
149 if ( in_array( 'nonce', $extra ) || in_array( 'all', $extra ) ) {
150 $allowed_tags['input'] = array(
151 'type' => true,
152 'id' => true,
153 'name' => true,
154 'value' => true,
155 'data-name' => true,
156 );
157 }
158
159 // Include bdi tag
160 if ( in_array( 'bdi', $extra ) || in_array( 'all', $extra ) ) {
161 $allowed_tags['bdi'] = array(
162 'class' => true,
163 'id' => true,
164 'style' => true,
165 );
166 }
167
168 // Include select2
169 if ( in_array( 'select2', $extra ) || in_array( 'all', $extra ) ) {
170 $allowed_tags['select'] = array(
171 'name' => true,
172 'class' => true,
173 'id' => true,
174 'style' => true,
175 'data-name' => true,
176 'data-source' => true,
177 'multiple' => true,
178 );
179
180 $allowed_tags['option'] = array(
181 'value' => true,
182 'selected' => true,
183 );
184
185 $allowed_tags['optgroup'] = array(
186 'label' => true,
187 );
188 }
189
190 // Include dd, dt tags
191 if ( in_array( 'dd', $extra ) || in_array( 'all', $extra ) ) {
192 $allowed_tags['dd'] = array(
193 'class' => true,
194 'id' => true,
195 'style' => true,
196 );
197
198 $allowed_tags['dt'] = array(
199 'class' => true,
200 'id' => true,
201 'style' => true,
202 );
203 }
204
205 // Include forms tags.
206 if ( in_array( 'forms', $extra ) || in_array( 'all', $extra ) ) {
207 $tags = array( 'form', 'input', 'select', 'option', 'textarea' );
208
209 foreach ( $tags as $tag ) {
210 $allowed_tags[ $tag ] = array(
211 'id' => true,
212 'class' => true,
213 'style' => true,
214 'name' => true,
215 'value' => true,
216 'type' => true,
217 'placeholder' => true,
218 'data' => '*',
219 'data-source' => true,
220 'data-product_id' => true,
221 'data-product_variations' => true,
222 'data-attribute_name' => true,
223 'data-show_option_none' => true,
224 'data-name' => true,
225 'data-source' => true,
226 'step' => true,
227 'min' => true,
228 'max' => true,
229 'selected' => true,
230 'checked' => true,
231 'onchange' => true,
232 'autocomplete' => true,
233 'required' => true,
234 'action' => true,
235 'method' => true,
236 'data-name' => true,
237 'enctype' => true,
238 'size' => true,
239 'role' => true,
240 'inputmode' => true,
241 'aria-label' => true,
242 'multiple' => true,
243 );
244 }
245 }
246
247 /**
248 * Filters the allowed tags.
249 *
250 * @since 1.2.5
251 */
252 return apply_filters( 'merchant_kses_allowed_tags', $allowed_tags );
253 }
254 }
255
256 /**
257 * Allowed tags for scripts.
258 *
259 * @return array $allowed_tags
260 */
261 if ( ! function_exists( 'merchant_kses_allowed_tags_for_code_snippets' ) ) {
262 function merchant_kses_allowed_tags_for_code_snippets() {
263 return array(
264 'script' => array(
265 'type' => true,
266 ),
267 );
268 }
269 }
270
271 /**
272 * Check if WooCommerce checkout page is being rendered by block.
273 * Since WooCommerce 8.3.0 the checkout page is rendered by block.
274 *
275 * @return bool
276 */
277 if ( ! function_exists( 'merchant_is_checkout_block_layout' ) ) {
278 function merchant_is_checkout_block_layout() {
279 $checkout_page = wc_get_page_id( 'checkout' );
280
281 if ( empty( $checkout_page ) ) {
282 return false;
283 }
284
285 if ( function_exists( 'has_blocks' ) && has_blocks( $checkout_page ) ) {
286 $post = get_post( $checkout_page );
287 $blocks = parse_blocks( $post->post_content );
288
289 foreach ( $blocks as $block ) {
290 if ( 'woocommerce/checkout' === $block['blockName'] ) {
291 return true;
292 }
293 }
294 }
295
296 return false;
297 }
298 }
299
300 /**
301 * Check if WooCommerce cart page is being rendered by block.
302 * Since WooCommerce 8.3.0 the cart page is rendered by block.
303 *
304 * @return bool
305 */
306 if ( ! function_exists( 'merchant_is_cart_block_layout' ) ) {
307 function merchant_is_cart_block_layout() {
308 $cart_page = wc_get_page_id( 'cart' );
309
310 if ( empty( $cart_page ) ) {
311 return false;
312 }
313
314 if ( function_exists( 'has_blocks' ) && has_blocks( $cart_page ) ) {
315 $post = get_post( $cart_page );
316 $blocks = parse_blocks( $post->post_content );
317
318 foreach ( $blocks as $block ) {
319 if ( 'woocommerce/cart' === $block['blockName'] ) {
320 return true;
321 }
322 }
323 }
324
325 return false;
326 }
327 }
328
329 /**
330 * Get the product categories.
331 */
332 if ( ! function_exists( 'merchant_get_product_categories' ) ) {
333 function merchant_get_product_categories() {
334 $product_categories = get_terms( array(
335 'taxonomy' => 'product_cat',
336 'hide_empty' => false,
337 ) );
338 $category_names = array();
339 if ( ! empty( $product_categories ) && ! is_wp_error( $product_categories ) ) {
340 foreach ( $product_categories as $category ) {
341 $category_names[ $category->slug ] = $category->name;
342 }
343 }
344
345 return $category_names;
346 }
347 }
348
349 /**
350 * Convert array to css.
351 */
352 if ( ! function_exists( 'merchant_array_to_css' ) ) {
353 function merchant_array_to_css( $array ) {
354 $css = '';
355 if ( empty( $array ) ) {
356 return $css;
357 }
358 foreach ( $array as $key => $value ) {
359 $css .= $key . ':' . $value . ';';
360 }
361
362 return $css;
363 }
364 }