PluginProbe ʕ •ᴥ•ʔ
Strong Testimonials / 2.35
Strong Testimonials v2.35
3.3.1 trunk 1.0.1 2.30.9 2.31.10 2.32 2.32.1 2.32.2 2.32.3 2.32.4 2.33 2.34 2.35 2.36 2.37 2.38 2.38.1 2.39 2.39.1 2.39.2 2.39.3 2.40.0 2.40.1 2.40.2 2.40.3 2.40.4 2.40.5 2.40.6 2.40.7 2.41.0 2.41.1 2.50.0 2.50.1 2.50.2 2.50.3 2.50.4 2.51.0 2.51.1 2.51.2 2.51.3 2.51.4 2.51.5 2.51.6 2.51.7 2.51.8 2.51.9 3.0.0 3.0.1 3.0.2 3.0.3 3.1.0 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.17 3.1.18 3.1.19 3.1.2 3.1.20 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.10 3.2.11 3.2.12 3.2.13 3.2.14 3.2.15 3.2.16 3.2.17 3.2.18 3.2.19 3.2.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 3.3.0
strong-testimonials / includes / functions.php
strong-testimonials / includes Last commit date
integrations 7 years ago class-strong-form.php 7 years ago class-strong-log.php 7 years ago class-strong-mail.php 7 years ago class-strong-templates.php 7 years ago class-strong-testimonials-order.php 7 years ago class-strong-testimonials-privacy.php 7 years ago class-strong-testimonials-render.php 7 years ago class-strong-testimonials-shortcode-average.php 7 years ago class-strong-testimonials-shortcode-count.php 7 years ago class-strong-testimonials-shortcode.php 7 years ago class-strong-view-display.php 7 years ago class-strong-view-form.php 7 years ago class-strong-view-slideshow.php 7 years ago class-strong-view.php 7 years ago class-walker-strong-category-checklist-front.php 7 years ago deprecated.php 7 years ago filters.php 7 years ago functions-activation.php 7 years ago functions-content.php 7 years ago functions-image.php 7 years ago functions-rating.php 7 years ago functions-template-form.php 7 years ago functions-template.php 7 years ago functions-views.php 7 years ago functions.php 7 years ago l10n-polylang.php 7 years ago l10n-wpml.php 7 years ago post-types.php 7 years ago retro.php 7 years ago scripts.php 7 years ago widget2.php 7 years ago
functions.php
884 lines
1 <?php
2 /**
3 * Functions
4 */
5
6 function wpmtst_support_url() {
7 return esc_url( '#' );
8 }
9
10 /**
11 * Return default translation from po/mo files if no active translation plugin.
12 *
13 * @since 2.23.2
14 * @param $string
15 *
16 * @return string
17 */
18 function wpmtst_l10n_default( $string ) {
19 return esc_html( $string );
20 }
21 add_filter( 'wpmtst_l10n', 'wpmtst_l10n_default' );
22
23 /**
24 * Append custom fields to post object.
25 * Add thumbnail if included in field group.
26 *
27 * @param $post
28 *
29 * @return mixed
30 */
31 function wpmtst_get_post( $post ) {
32 $custom = get_post_custom( $post->ID );
33 $fields = wpmtst_get_custom_fields();
34
35 foreach ( $fields as $key => $field ) {
36 $name = $field['name'];
37
38 if ( 'featured_image' == $name ) {
39 $post->thumbnail_id = get_post_thumbnail_id( $post->ID );
40 } else {
41 if ( isset( $custom[ $name ] ) ) {
42 $post->$name = $custom[ $name ][0];
43 } else {
44 $post->$name = '';
45 }
46 }
47 }
48
49 return $post;
50 }
51
52 /**
53 * Helper: Format URL
54 *
55 * @param $url
56 * @return string
57 */
58 function wpmtst_get_website( $url ) {
59 if ( ! preg_match( '~^(?:f|ht)tps?://~i', $url ) ) {
60 $url = 'https://' . $url;
61 }
62
63 return $url;
64 }
65
66 /**
67 * Check whether a common script is already registered by file name
68 * instead of handle.
69 *
70 * === Used in older versions to check for Cycle script. ===
71 *
72 * Why? Plugins are loaded before themes. Our plugin includes the Cycle
73 * slider. Some themes include it too. We only want to load it once.
74 *
75 * Load jQuery Cycle plugin (http://jquery.malsup.com/cycle/) only if
76 * any version of Cycle is not already registered by a theme or another
77 * plugin. Both versions of Cycle use same function name so we can't load
78 * both but either version will work for our purposes.
79 * http://jquery.malsup.com/cycle2/faq/
80 *
81 * The WordPress function `wp_script_is` checks by *handle* within a plugin
82 * or theme but handles can be different so it misses it.
83 * wp_script_is( 'jquery-cycle', 'registered' )
84 * http://codex.wordpress.org/Function_Reference/wp_script_is
85 *
86 * Jetpack's slideshow shortcode simply enqueues its own version of Cycle
87 * without registering first if and when the shortcode is rendered. No way
88 * to check for that. It does not seem to create a conflict now. (1.16)
89 *
90 * @param array $filenames possible versions of one script,
91 * e.g. plugin.js, plugin-min.js, plugin-1.2.js
92 * @return string
93 */
94 function wpmtst_is_registered( $filenames ) {
95 global $wp_scripts;
96
97 // Bail if called too early.
98 if ( ! $wp_scripts ) {
99 return false;
100 }
101
102 $script_handle = '';
103
104 foreach ( $wp_scripts->registered as $handle => $script ) {
105 if ( in_array( basename( $script->src ), $filenames ) ) {
106 $script_handle = $handle;
107 break;
108 }
109 }
110
111 return $script_handle;
112 }
113
114 if ( ! function_exists( 'get_page_by_slug' ) ) {
115 /**
116 * Get page ID by slug.
117 *
118 * Thanks http://wordpress.stackexchange.com/a/102845/32076
119 * Does not require parent slug.
120 *
121 * @since 1.11.0
122 */
123 function get_page_by_slug( $page_slug, $output = OBJECT, $post_type = 'page' ) {
124 global $wpdb;
125 $page = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_name = %s AND post_type= %s AND post_status = 'publish'", $page_slug, $post_type ) );
126 if ( $page ) {
127 return get_post( $page, $output );
128 } else {
129 return null;
130 }
131 }
132 }
133
134 /**
135 * Reverse auto-p wrap shortcodes that stand alone
136 *
137 * @since 1.11.0
138 */
139 if ( ! function_exists( 'reverse_wpautop' ) ) {
140 function reverse_wpautop( $s ) {
141 // remove any new lines already in there
142 $s = str_replace( "\n", '', $s );
143
144 // remove all <p>
145 $s = str_replace( '<p>', '', $s );
146
147 // remove <br>
148 $s = str_replace( array( '<br />', '<br/>', '<br>' ), '', $s );
149
150 // remove </p>
151 $s = str_replace( '</p>', '', $s );
152
153 return $s;
154 }
155 }
156
157 /**
158 * Sort array based on 'order' element.
159 *
160 * @since 1.13
161 */
162 function wpmtst_uasort( $a, $b ) {
163 if ( $a['order'] == $b['order'] ) {
164 return 0;
165 }
166 return ( $a['order'] < $b['order'] ) ? -1 : 1;
167 }
168
169 function wpmtst_get_custom_form_count() {
170 $forms = get_option( 'wpmtst_custom_forms' );
171 return count( $forms );
172 }
173
174 function wpmtst_get_form_fields( $form_id = 1 ) {
175 $forms = get_option( 'wpmtst_custom_forms' );
176 if ( isset( $forms[ $form_id ] ) ) {
177 $form = $forms[ $form_id ];
178 } else {
179 $form = $forms[1];
180 }
181 $fields = $form['fields'];
182
183 return $fields;
184 }
185
186 /**
187 * Get only custom fields from all field groups.
188 *
189 * Used in post editor.
190 *
191 * @return array
192 */
193 function wpmtst_get_custom_fields() {
194 $all_fields = array();
195 $forms = get_option( 'wpmtst_custom_forms' );
196 if ( ! $forms ) {
197 return $all_fields;
198 }
199
200 // use default group as base
201 $fields = $forms[1]['fields'];
202 if ( ! $fields ) {
203 return $all_fields;
204 }
205
206 // replace key with field name
207 foreach ( $fields as $field ) {
208 if ( 'post' != $field['record_type'] ) {
209 $all_fields[ $field['name'] ] = $field;
210 }
211 }
212
213 // merge remaining form fields
214 foreach ( $forms as $form ) {
215 $custom_fields = array();
216 $fields = $form['fields'];
217 foreach ( $fields as $field ) {
218 if ( 'post' != $field['record_type'] ) {
219 $custom_fields[ $field['name'] ] = $field;
220 }
221 }
222 $all_fields = array_merge( $all_fields, $custom_fields );
223 }
224
225 return $all_fields;
226 }
227
228 /**
229 * Get all fields from all field groups.
230 *
231 * Used for admin list columns.
232 *
233 * @return array
234 */
235 function wpmtst_get_all_fields() {
236 $forms = get_option( 'wpmtst_custom_forms' );
237 $all_fields = array();
238
239 /**
240 * Use first custom form as the base because if we use 'default'
241 * and a field has 'admin_table' enabled in 'default'
242 * but not in any custom form, the column will still be shown.
243 */
244 $fields = $forms[1]['fields'];
245
246 // replace key with field name
247 foreach ( $fields as $field ) {
248 $all_fields[ $field['name'] ] = $field;
249 }
250
251 // merge remaining form fields
252 foreach ( $forms as $form ) {
253 $custom_fields = array();
254 $fields = $form['fields'];
255 foreach ( $fields as $field ) {
256 $custom_fields[ $field['name'] ] = $field;
257 }
258 $all_fields = array_merge( $all_fields, $custom_fields );
259 }
260
261 return $all_fields;
262 }
263
264 /**
265 * Get the built-in fields.
266 *
267 * @since 2.29.0
268 */
269 function wpmtst_get_builtin_fields() {
270 return array(
271 'post_date' => array(
272 'name' => 'post_date',
273 'label' => 'Post Date',
274 'input_type' => 'date',
275 'type' => 'date',
276 'record_type' => 'builtin',
277 ),
278 'submit_date' => array(
279 'name' => 'submit_date',
280 'label' => 'Submit Date',
281 'input_type' => 'date',
282 'type' => 'date',
283 'record_type' => 'builtin',
284 ),
285 'category' => array(
286 'name' => 'category',
287 'label' => 'Category',
288 'input_type' => 'category',
289 'type' => 'category',
290 'record_type' => 'builtin',
291 ),
292 );
293 }
294
295 /**
296 * Get defined images sizes.
297 *
298 * @link http://codex.wordpress.org/Function_Reference/get_intermediate_image_sizes
299 * @since 1.21.0
300 * @param string $size
301 *
302 * @return array|bool|mixed
303 */
304 /*
305 wpmtst_get_image_sizes = Array
306 (
307 [widget-thumbnail] => Array
308 (
309 [width] => 75
310 [height] => 75
311 [crop] =>
312 [label] => widget-thumbnail - 75 x 75
313 )
314 [thumbnail] => Array
315 (
316 [width] => 150
317 [height] => 150
318 [crop] => 1
319 [label] => thumbnail - 150 x 150
320 )
321 [medium] => Array
322 (
323 [width] => 300
324 [height] => 300
325 [crop] =>
326 [label] => medium - 300 x 300
327 )
328 [post-thumbnail] => Array
329 (
330 [width] => 825
331 [height] => 510
332 [crop] => 1
333 [label] => post-thumbnail - 825 x 510
334 )
335 [large] => Array
336 (
337 [width] => 1024
338 [height] => 1024
339 [crop] =>
340 [label] => large - 1024 x 1024
341 )
342 [full] => Array
343 (
344 [label] => original size uploaded
345 [width] => 0
346 [height] => 0
347 )
348 [custom] => Array
349 (
350 [label] => enter dimensions:
351 [width] => 0
352 [height] => 0
353 )
354 )
355 */
356 function wpmtst_get_image_sizes( $size = '' ) {
357
358 global $_wp_additional_image_sizes;
359
360 $sizes = array();
361 $get_intermediate_image_sizes = get_intermediate_image_sizes();
362
363 /**
364 * Catch possibility of missing standard sizes.
365 * @since 2.2.5
366 */
367 if ( $get_intermediate_image_sizes ) {
368 // Create the full array with sizes and crop info
369 foreach ( $get_intermediate_image_sizes as $_size ) {
370
371 if ( in_array( $_size, array( 'thumbnail', 'medium', 'large' ) ) ) {
372
373 $sizes[ $_size ]['width'] = get_option( $_size . '_size_w' );
374 $sizes[ $_size ]['height'] = get_option( $_size . '_size_h' );
375 $sizes[ $_size ]['crop'] = (bool) get_option( $_size . '_crop' );
376 } elseif ( isset( $_wp_additional_image_sizes[ $_size ] ) ) {
377
378 $sizes[ $_size ] = array(
379 'width' => $_wp_additional_image_sizes[ $_size ]['width'],
380 'height' => $_wp_additional_image_sizes[ $_size ]['height'],
381 'crop' => $_wp_additional_image_sizes[ $_size ]['crop'],
382 );
383
384 }
385 }
386
387 // Sort by width
388 uasort( $sizes, 'wpmtst_compare_width' );
389
390 // Add option labels
391 foreach ( $sizes as $key => $dimensions ) {
392 $sizes[ $key ]['label'] = sprintf( '%s - %d x %d', $key, $dimensions['width'], $dimensions['height'] );
393 }
394 }
395
396 // Add extra options
397 $sizes['full'] = array(
398 'label' => 'original size uploaded',
399 'width' => 0,
400 'height' => 0,
401 );
402 $sizes['custom'] = array(
403 'label' => 'custom size',
404 'width' => 0,
405 'height' => 0,
406 );
407
408 // Get only one size if found
409 if ( $size ) {
410 if ( isset( $sizes[ $size ] ) ) {
411 return $sizes[ $size ];
412 } else {
413 return false;
414 }
415 }
416
417 return $sizes;
418 }
419
420 /**
421 * @param $a
422 * @param $b
423 *
424 * @return int
425 */
426 function wpmtst_compare_width( $a, $b ) {
427 if ( $a['width'] == $b['width'] ) {
428 return 0;
429 }
430 return ( $a['width'] < $b['width'] ) ? -1 : 1;
431 }
432
433 /**
434 * @return int
435 */
436 function wpmtst_get_cat_count() {
437 return count( get_terms( 'wpm-testimonial-category', array( 'hide_empty' => false ) ) );
438 }
439
440 /**
441 * Return a list of categories after removing any orderby filters.
442 *
443 * @since 2.2.3 If WPML is active, will find corresponding term ID in current language.
444 *
445 * @param int $parent
446 *
447 * @return array|int|WP_Error
448 */
449 function wpmtst_get_cats( $parent = 0 ) {
450 return get_terms(
451 'wpm-testimonial-category',
452 array(
453 'hide_empty' => false,
454 'parent' => $parent,
455 )
456 );
457 }
458
459 /**
460 * @param $value
461 * @param int $parent
462 * @param int $level
463 */
464 function wpmtst_nested_cats( $value, $parent = 0, $level = 0 ) {
465 $cats = wpmtst_get_cats( $parent );
466 if ( $cats ) {
467 foreach ( $cats as $cat ) {
468 $selected = in_array( $cat->term_id, $value ) ? ' selected' : '';
469 printf( '<option value="%s"%s>%s%s</option>', esc_attr( $cat->term_id ), esc_attr( $selected ), esc_html( str_repeat( '&nbsp;&nbsp;&nbsp;', $level ) ), esc_html( $cat->name ) );
470 wpmtst_nested_cats( $value, $cat->term_id, $level + 1 );
471 }
472 }
473 }
474
475 function wpmtst_sort_array_by_name( $a, $b ) {
476 if ( $a['name'] == $b['name'] ) {
477 return 0;
478 }
479
480 return ( $a['name'] < $b['name'] ) ? -1 : 1;
481 }
482
483 /**
484 * Allow disabling of client-side form validation via filter.
485 *
486 * @since 1.21.0
487 * @deprecated since 2.18.1
488 */
489 function wpmtst_using_form_validation_script() {
490 return true;
491 }
492
493 /**
494 * Set iframe width of embedded videos.
495 *
496 * @since 2.6.0
497 * @param $dimensions
498 * @param $url
499 *
500 * @return array
501 */
502 function wpmtst_embed_size( $dimensions, $url ) {
503 $options = get_option( 'wpmtst_options' );
504 $width = (int) $options['embed_width'];
505 if ( $width ) {
506 $dimensions = array(
507 'width' => $width,
508 'height' => min( ceil( $width * 1.5 ), 1000 ),
509 );
510 }
511
512 return $dimensions;
513 }
514
515 /**
516 * Allow empty posts.
517 *
518 * @since 2.6.0
519 * @param $maybe_empty
520 * @param $postarr
521 *
522 * @return bool
523 */
524 function wpmtst_insert_post_empty_content( $maybe_empty, $postarr ) {
525 if ( 'wpm-testimonial' == $postarr['post_type'] ) {
526 return false;
527 }
528
529 return $maybe_empty;
530 }
531 add_filter( 'wp_insert_post_empty_content', 'wpmtst_insert_post_empty_content', 10, 2 );
532
533 /**
534 * Display submit_date in Publish meta box under Published date.
535 *
536 * @param $post @since WordPress 4.4
537 * @since 2.12.0
538 */
539 function wpmtst_post_submitbox_misc_actions( $post ) {
540 if ( ! $post ) {
541 global $post;
542 }
543
544 if ( 'wpm-testimonial' == $post->post_type ) {
545 echo '<div class="wpmtst-pub-section">';
546 echo '<span id="submit-timestamp">&nbsp;';
547 $submit_date = get_post_meta( $post->ID, 'submit_date', true );
548 if ( $submit_date ) {
549 echo 'Submitted on: <strong>' . wp_kses_post( date_i18n( __( 'M j, Y @ H:i' ), strtotime( $submit_date ) ) ) . '</strong>';
550 } else {
551 echo 'No submit date';
552 }
553 echo '</span>';
554 echo '</div>';
555 }
556 }
557 add_action( 'post_submitbox_misc_actions', 'wpmtst_post_submitbox_misc_actions' );
558
559 /**
560 * @return mixed
561 */
562 function wpmtst_get_background_defaults() {
563 return apply_filters(
564 'wpmtst_default_template_background',
565 array(
566 'color' => '',
567 'type' => '',
568 'preset' => '',
569 'gradient1' => '',
570 'gradient2' => '',
571 )
572 );
573 }
574
575 /**
576 * @param null $preset
577 *
578 * TODO Move to options and add a filter.
579 * @return array|bool
580 */
581 function wpmtst_get_background_presets( $preset = null ) {
582 $presets = array(
583 'light-blue-gradient' => array(
584 'label' => __( 'light blue gradient', 'strong-testimonials' ),
585 'color' => '#E7EFFE',
586 'color2' => '#B8CFFB',
587 ),
588 'light-gray-gradient' => array(
589 'label' => __( 'light gray gradient', 'strong-testimonials' ),
590 'color' => '#FBFBFB',
591 'color2' => '#EDEDED',
592 ),
593 'light-green-mist-gradient' => array(
594 'label' => __( 'light green mist gradient', 'strong-testimonials' ),
595 'color' => '#F2FBE9',
596 'color2' => '#E0F7CC',
597 ),
598 'light-latte-gradient' => array(
599 'label' => __( 'light latte gradient', 'strong-testimonials' ),
600 'color' => '#F8F3EC',
601 'color2' => '#E0C8AB',
602 ),
603 'light-plum-gradient' => array(
604 'label' => __( 'light plum gradient', 'strong-testimonials' ),
605 'color' => '#F7EEF7',
606 'color2' => '#E9D0E9',
607 ),
608 'sky-blue-gradient' => array(
609 'label' => __( 'sky blue gradient', 'strong-testimonials' ),
610 'color' => '#E9F6FB',
611 'color2' => '#C8E9F6',
612 ),
613 );
614
615 if ( $preset ) {
616 if ( isset( $presets[ $preset ] ) ) {
617 return $presets[ $preset ];
618 } else {
619 return wpmtst_get_background_defaults();
620 }
621 }
622
623 return $presets;
624 }
625
626 /**
627 * Return the form success message.
628 *
629 * @since 2.18.0
630 *
631 * @return mixed
632 */
633 function wpmtst_get_success_message() {
634 $message = wpautop( do_shortcode( wpmtst_get_form_message( 'submission-success' ) ) );
635 $message = sprintf( '<div class="%s">%s</div>', 'testimonial-success', $message );
636
637 return apply_filters( 'wpmtst_form_success_message', $message );
638 }
639
640 /**
641 * Does callback exist?
642 *
643 * @param $callback
644 * @since 2.18.0
645 *
646 * @return bool
647 */
648 // TODO Move to Utils class
649 function wpmtst_callback_exists( $callback ) {
650 if ( is_array( $callback ) ) {
651 $exists = method_exists( $callback[0], $callback[1] );
652 } else {
653 $exists = function_exists( $callback );
654 }
655
656 return $exists;
657 }
658
659 /**
660 * Check for Divi Builder plugin.
661 *
662 * Its plugin version constant is inaccurate so get the version from the file header.
663 *
664 * @since 2.22.0
665 *
666 * @return bool
667 */
668 function wpmtst_divi_builder_active() {
669 $active = false;
670 if ( wpmtst_is_plugin_active( 'divi-builder/divi-builder.php' ) ) {
671 $plugin = get_file_data( WP_PLUGIN_DIR . '/divi-builder/divi-builder.php', array( 'version' => 'Version' ) );
672 if ( isset( $plugin['version'] ) && version_compare( $plugin['version'], '2' ) > 0 ) {
673 $active = true;
674 }
675 }
676
677 return $active;
678 }
679
680 /**
681 * Append custom fields to testimonial content in theme's single post template.
682 *
683 * @param $content
684 * @since 2.22.0
685 *
686 * @return string
687 */
688 function wpmtst_single_template_add_content( $content ) {
689 if ( is_singular( 'wpm-testimonial' ) || is_tax( 'wpm-testimonial-category' ) ) {
690 $content .= wpmtst_single_template_client();
691 }
692
693 return $content;
694 }
695 add_filter( 'the_content', 'wpmtst_single_template_add_content' );
696
697 /**
698 * Frequent plugin checks.
699 *
700 * A combination of an array of frequent plugin names, and core's is_plugin_active functions
701 * which are not available in front-end without loading plugin.php which is uncecessary.
702 *
703 * @param $plugin
704 *
705 * @return bool
706 */
707 function wpmtst_is_plugin_active( $plugin = '' ) {
708 if ( ! $plugin ) {
709 return false;
710 }
711
712 $plugins = array(
713 'wpml' => 'sitepress-multilingual-cms/sitepress.php',
714 'polylang' => 'polylang/polylang.php',
715 'lazy-loading-responsive-images' => 'lazy-loading-responsive-images/lazy-load-responsive-images.php',
716 );
717 if ( isset( $plugins[ $plugin ] ) ) {
718 $plugin = $plugins[ $plugin ];
719 }
720
721 if ( in_array( $plugin, (array) get_option( 'active_plugins', array() ) ) ) {
722 return true;
723 }
724
725 if ( ! is_multisite() ) {
726 return false;
727 }
728
729 $plugins = get_site_option( 'active_sitewide_plugins' );
730 if ( isset( $plugins[ $plugin ] ) ) {
731 return true;
732 }
733
734 return false;
735 }
736
737 /**
738 * Sanitize a textarea from user input. Based on sanitize_text_field.
739 *
740 * Check for invalid UTF-8,
741 * Convert single < characters to entity,
742 * strip all tags,
743 * strip octets.
744 *
745 * @since 2.11.8
746 *
747 * @param string $text
748 *
749 * @return string
750 */
751 function wpmtst_sanitize_textarea( $text ) {
752 $filtered = wp_check_invalid_utf8( $text );
753
754 if ( strpos( $filtered, '<' ) !== false ) {
755 $filtered = wp_pre_kses_less_than( $filtered );
756 // This will NOT strip extra whitespace.
757 $filtered = wp_strip_all_tags( $filtered, false );
758 }
759
760 while ( preg_match( '/%[a-f0-9]{2}/i', $filtered, $match ) ) {
761 $filtered = str_replace( $match[0], '', $filtered );
762 }
763
764 /**
765 * Filter a sanitized textarea string.
766 *
767 * @param string $filtered The sanitized string.
768 * @param string $str The string prior to being sanitized.
769 */
770 return apply_filters( 'wpmtst_sanitize_textarea', $filtered, $text );
771 }
772
773 /**
774 * Store values as 1 or 0 (never blank).
775 *
776 * Checked checkbox value is "on" but unchecked checkboxes are _not_ submitted.
777 *
778 * @param $input
779 * @param $key string Must be explicit. Do not simply loop through an input array.
780 *
781 * @return int
782 */
783 function wpmtst_sanitize_checkbox( $input, $key ) {
784 if ( isset( $input[ $key ] ) ) {
785 if ( 'on' == $input[ $key ] ) { // checked checkbox
786 return true;
787 } else { // hidden input
788 return $input[ $key ] ? true : false; // 0 or 1
789 }
790 } else { // unchecked checkbox
791 return false;
792 }
793 }
794
795 /**
796 * Trims a entire array recursively.
797 *
798 * @since 2.26.6
799 *
800 * @props Jonas John
801 * @version 0.2
802 * @link http://www.jonasjohn.de/snippets/php/trim-array.htm
803 * @param $input array|string
804 *
805 * @return array|string
806 */
807 function wpmtst_trim_array( $input ) {
808 if ( ! is_array( $input ) ) {
809 return trim( $input );
810 }
811
812 return array_map( 'wpmtst_trim_array', $input );
813 }
814
815 if ( ! function_exists( 'normalize_empty_atts' ) ) {
816 /**
817 * Normalize empty shortcode attributes.
818 *
819 * Turns atts into tags - brilliant!
820 * Thanks http://wordpress.stackexchange.com/a/123073/32076
821 *
822 * @param $atts
823 *
824 * @return mixed
825 */
826 function normalize_empty_atts( $atts ) {
827 if ( ! empty( $atts ) ) {
828 foreach ( $atts as $attribute => $value ) {
829 if ( is_int( $attribute ) ) {
830 $atts[ strtolower( $value ) ] = true;
831 unset( $atts[ $attribute ] );
832 }
833 }
834 }
835
836 return $atts;
837 }
838 }
839
840 if ( ! function_exists( 'wpmtst_round_to_half' ) ) {
841 /**
842 * Round to the nearest half.
843 *
844 * @param $value
845 *
846 * @since 2.31.0
847 * @return float|int
848 */
849 function wpmtst_round_to_half( $value ) {
850 if ( is_string( $value ) ) {
851 $value = (float) str_replace( ',', '.', $value );
852 }
853 return round( (float) $value * 2 ) / 2;
854 }
855 }
856
857
858 if ( ! function_exists( 'wpmtst_strip_whitespace' ) ) {
859 /**
860 * Remove whitespace from HTML output.
861 *
862 * @param $html
863 *
864 * @return string
865 */
866 function wpmtst_strip_whitespace( $html ) {
867 return preg_replace( '~>\s+<~', '><', trim( $html ) );
868 }
869 }
870
871 if ( ! function_exists( 'wpmtst_current_url' ) ) {
872 /**
873 * Assemble and return the current URL.
874 *
875 * @since 2.31.0
876 * @return string
877 */
878 function wpmtst_current_url() {
879 global $wp;
880
881 return home_url( add_query_arg( array(), $wp->request ) );
882 }
883 }
884