PluginProbe ʕ •ᴥ•ʔ
Strong Testimonials / 3.2.8
Strong Testimonials v3.2.8
3.3.6 3.3.5 3.3.4 3.3.3 3.3.2 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
elementor 1 year ago logs 1 year ago strong-testimonials-beaver-block 1 year ago submodules 1 year ago class-strong-gutemberg.php 1 year ago class-strong-log.php 1 year ago class-strong-mail.php 1 year ago class-strong-testimonials-average-shortcode.php 1 year ago class-strong-testimonials-count-shortcode.php 1 year ago class-strong-testimonials-form.php 1 year ago class-strong-testimonials-order.php 1 year ago class-strong-testimonials-privacy.php 1 year ago class-strong-testimonials-render.php 1 year ago class-strong-testimonials-templates.php 1 year ago class-strong-testimonials-view-shortcode.php 1 year ago class-strong-testimonials-view-widget.php 1 year ago class-strong-view-display.php 1 year ago class-strong-view-form.php 1 year ago class-strong-view-slideshow.php 1 year ago class-strong-view.php 1 year ago class-walker-strong-category-checklist-front.php 1 year ago deprecated.php 1 year ago filters.php 1 year ago functions-activation.php 1 year ago functions-content.php 1 year ago functions-image.php 1 year ago functions-rating.php 1 year ago functions-template-form.php 1 year ago functions-template.php 1 year ago functions-views.php 1 year ago functions.php 1 year ago l10n-polylang.php 1 year ago l10n-wpml.php 1 year ago post-types.php 1 year ago retro.php 1 year ago scripts.php 1 year ago
functions.php
885 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( $l10n_string ) {
19 return $l10n_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, true ) ) {
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
177 if ( isset( $forms[ $form_id ] ) ) {
178 $form = $forms[ $form_id ];
179 } elseif ( isset( $forms[1] ) ) {
180 $form = $forms[1];
181 } else {
182 $form = reset( $forms );
183 }
184
185 $fields = $form['fields'];
186
187 return $fields;
188 }
189
190 /**
191 * Get only custom fields from all field groups.
192 *
193 * Used in post editor.
194 *
195 * @return array
196 */
197 function wpmtst_get_custom_fields() {
198 $all_fields = array();
199 $forms = get_option( 'wpmtst_custom_forms' );
200
201 if ( ! $forms ) {
202 return $all_fields;
203 }
204 // merge remaining form fields.
205 foreach ( $forms as $form ) {
206
207 $custom_fields = array();
208 if ( isset( $form['fields'] ) ) {
209 $fields = $form['fields'];
210 foreach ( $fields as $field ) {
211 if ( 'post' !== $field['record_type'] ) {
212 $custom_fields[ $field['name'] ] = $field;
213 }
214 }
215 }
216 $all_fields = array_merge( $all_fields, $custom_fields );
217 }
218
219 return $all_fields;
220 }
221
222 /**
223 * Get all fields from all field groups.
224 *
225 * Used for admin list columns.
226 *
227 * @return array
228 */
229 function wpmtst_get_all_fields() {
230 $forms = get_option( 'wpmtst_custom_forms' );
231 $all_fields = array();
232
233 /**
234 * Use first custom form as the base because if we use 'default'
235 * and a field has 'admin_table' enabled in 'default'
236 * but not in any custom form, the column will still be shown.
237 */
238 $key = array_key_exists( 1, $forms ) ? 1 : array_key_first( $forms );
239 $fields = $forms[ $key ]['fields'];
240
241 // replace key with field name
242 foreach ( $fields as $field ) {
243 $all_fields[ $field['name'] ] = $field;
244 }
245
246 // merge remaining form fields
247 foreach ( $forms as $form ) {
248 $custom_fields = array();
249 $fields = $form['fields'];
250 foreach ( $fields as $field ) {
251 $custom_fields[ $field['name'] ] = $field;
252 }
253 $all_fields = array_merge( $all_fields, $custom_fields );
254 }
255
256 return $all_fields;
257 }
258
259 /**
260 * Get all rating fields
261 *
262 * @return array
263 */
264 function wpmtst_get_all_rating_fields() {
265
266 $all_fields = wpmtst_get_all_fields();
267
268 $rating_fields = array();
269
270 foreach ( $all_fields as $key => $field ) :
271 if ( 'rating' !== $field['input_type'] ) {
272 continue;
273 }
274 $rating_fields[] = $field;
275 endforeach;
276
277 return $rating_fields;
278 }
279
280 /**
281 * Get the built-in fields.
282 *
283 * @since 2.29.0
284 */
285 function wpmtst_get_builtin_fields() {
286 $builtin_fields = array(
287 'post_date' => array(
288 'name' => 'post_date',
289 'label' => 'Post Date',
290 'input_type' => 'date',
291 'type' => 'date',
292 'record_type' => 'builtin',
293 ),
294 'submit_date' => array(
295 'name' => 'submit_date',
296 'label' => 'Submit Date',
297 'input_type' => 'date',
298 'type' => 'date',
299 'record_type' => 'builtin',
300 ),
301 'category' => array(
302 'name' => 'category',
303 'label' => 'Category',
304 'input_type' => 'category',
305 'type' => 'category',
306 'record_type' => 'builtin',
307 ),
308 );
309
310 $options = get_option( 'wpmtst_options' );
311 if ( isset( $options['include_platform'] ) && true === $options['include_platform'] ) {
312 $builtin_fields[] = array(
313 'name' => 'platform',
314 'label' => 'Platform',
315 'input_type' => 'platform',
316 'type' => 'platform',
317 'record_type' => 'builtin',
318 );
319 }
320
321 return $builtin_fields;
322 }
323
324 function wpmtst_get_image_sizes( $size = '' ) {
325
326 global $_wp_additional_image_sizes;
327
328 $sizes = array();
329 $get_intermediate_image_sizes = get_intermediate_image_sizes();
330
331 /**
332 * Catch possibility of missing standard sizes.
333 * @since 2.2.5
334 */
335 if ( $get_intermediate_image_sizes ) {
336 // Create the full array with sizes and crop info
337 foreach ( $get_intermediate_image_sizes as $_size ) {
338
339 if ( in_array( $_size, array( 'thumbnail', 'medium', 'large' ), true ) ) {
340
341 $sizes[ $_size ]['width'] = get_option( $_size . '_size_w' );
342 $sizes[ $_size ]['height'] = get_option( $_size . '_size_h' );
343 $sizes[ $_size ]['crop'] = (bool) get_option( $_size . '_crop' );
344 } elseif ( isset( $_wp_additional_image_sizes[ $_size ] ) ) {
345
346 $sizes[ $_size ] = array(
347 'width' => $_wp_additional_image_sizes[ $_size ]['width'],
348 'height' => $_wp_additional_image_sizes[ $_size ]['height'],
349 'crop' => $_wp_additional_image_sizes[ $_size ]['crop'],
350 );
351
352 }
353 }
354
355 // Sort by width
356 uasort( $sizes, 'wpmtst_compare_width' );
357
358 // Add option labels
359 foreach ( $sizes as $key => $dimensions ) {
360 $sizes[ $key ]['label'] = sprintf( '%s - %d x %d', $key, $dimensions['width'], $dimensions['height'] );
361 }
362 }
363
364 // Add extra options
365 $sizes['full'] = array(
366 'label' => 'original size uploaded',
367 'width' => 0,
368 'height' => 0,
369 );
370 $sizes['custom'] = array(
371 'label' => 'custom size',
372 'width' => 0,
373 'height' => 0,
374 );
375
376 // Get only one size if found
377 if ( $size ) {
378 if ( isset( $sizes[ $size ] ) ) {
379 return $sizes[ $size ];
380 } else {
381 return false;
382 }
383 }
384
385 return $sizes;
386 }
387
388 /**
389 * @param $a
390 * @param $b
391 *
392 * @return int
393 */
394 function wpmtst_compare_width( $a, $b ) {
395 if ( $a['width'] === $b['width'] ) {
396 return 0;
397 }
398 return ( $a['width'] < $b['width'] ) ? -1 : 1;
399 }
400
401 /**
402 * @return int
403 */
404 function wpmtst_get_cat_count() {
405 return count( get_terms( 'wpm-testimonial-category', array( 'hide_empty' => false ) ) );
406 }
407
408 /**
409 * Return a list of categories after removing any orderby filters.
410 *
411 * @since 2.2.3 If WPML is active, will find corresponding term ID in current language.
412 *
413 * @param int $cat_parent
414 *
415 * @return array|int|WP_Error
416 */
417 function wpmtst_get_cats( $cat_parent = 0 ) {
418 return get_terms(
419 'wpm-testimonial-category',
420 array(
421 'hide_empty' => false,
422 'parent' => $cat_parent,
423 )
424 );
425 }
426
427 /**
428 * @param $value
429 * @param int $cat_parent
430 * @param int $level
431 */
432 function wpmtst_nested_cats( $value, $cat_parent = 0, $level = 0 ) {
433 $cats = wpmtst_get_cats( $cat_parent );
434 if ( $cats ) {
435 foreach ( $cats as $cat ) {
436 $selected = in_array( $cat->term_id, $value, true ) ? ' selected' : '';
437 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 ) );
438 wpmtst_nested_cats( $value, $cat->term_id, $level + 1 );
439 }
440 }
441 }
442
443 function wpmtst_sort_array_by_name( $a, $b ) {
444 if ( $a['name'] === $b['name'] ) {
445 return 0;
446 }
447
448 return ( $a['name'] < $b['name'] ) ? -1 : 1;
449 }
450
451 /**
452 * Allow disabling of client-side form validation via filter.
453 *
454 * @since 1.21.0
455 * @deprecated since 2.18.1
456 */
457 function wpmtst_using_form_validation_script() {
458 return true;
459 }
460
461 /**
462 * Set iframe width of embedded videos.
463 *
464 * @since 2.6.0
465 * @param $dimensions
466 * @param $url
467 *
468 * @return array
469 */
470 function wpmtst_embed_size( $dimensions, $url ) {
471 $options = get_option( 'wpmtst_options' );
472 $width = (int) $options['embed_width'];
473 if ( $width ) {
474 $dimensions = array(
475 'width' => $width,
476 'height' => min( ceil( $width * 1.5 ), 1000 ),
477 );
478 }
479
480 return $dimensions;
481 }
482
483 /**
484 * Allow empty posts.
485 *
486 * @since 2.6.0
487 * @param $maybe_empty
488 * @param $postarr
489 *
490 * @return bool
491 */
492 function wpmtst_insert_post_empty_content( $maybe_empty, $postarr ) {
493 if ( 'wpm-testimonial' === $postarr['post_type'] ) {
494 return false;
495 }
496
497 return $maybe_empty;
498 }
499 add_filter( 'wp_insert_post_empty_content', 'wpmtst_insert_post_empty_content', 10, 2 );
500
501 /**
502 * Display submit_date in Publish meta box under Published date.
503 *
504 * @param $post @since WordPress 4.4
505 * @since 2.12.0
506 */
507 function wpmtst_post_submitbox_misc_actions( $post ) {
508 if ( ! $post ) {
509 global $post;
510 }
511
512 if ( 'wpm-testimonial' === $post->post_type ) {
513 echo '<div class="wpmtst-pub-section">';
514 echo '<span id="submit-timestamp">&nbsp;';
515 $submit_date = get_post_meta( $post->ID, 'submit_date', true );
516 if ( $submit_date ) {
517 echo 'Submitted on: <strong>' . wp_kses_post( date_i18n( 'M j, Y @ H:i', strtotime( $submit_date ) ) ) . '</strong>';
518 } else {
519 esc_html_e( 'No submit date', 'strong-testimonials' );
520 }
521 echo '</span>';
522 echo '</div>';
523 }
524 }
525 add_action( 'post_submitbox_misc_actions', 'wpmtst_post_submitbox_misc_actions' );
526
527 /**
528 * @return mixed
529 */
530 function wpmtst_get_background_defaults() {
531 return apply_filters(
532 'wpmtst_default_template_background',
533 array(
534 'color' => '',
535 'type' => '',
536 'preset' => '',
537 'gradient1' => '',
538 'gradient2' => '',
539 )
540 );
541 }
542
543 /**
544 * @param null $preset
545 *
546 * TODO Move to options and add a filter.
547 * @return array|bool
548 */
549 function wpmtst_get_background_presets( $preset = null ) {
550 $presets = array(
551 'light-blue-gradient' => array(
552 'label' => esc_html__( 'light blue gradient', 'strong-testimonials' ),
553 'color' => '#E7EFFE',
554 'color2' => '#B8CFFB',
555 ),
556 'light-gray-gradient' => array(
557 'label' => esc_html__( 'light gray gradient', 'strong-testimonials' ),
558 'color' => '#FBFBFB',
559 'color2' => '#EDEDED',
560 ),
561 'light-green-mist-gradient' => array(
562 'label' => esc_html__( 'light green mist gradient', 'strong-testimonials' ),
563 'color' => '#F2FBE9',
564 'color2' => '#E0F7CC',
565 ),
566 'light-latte-gradient' => array(
567 'label' => esc_html__( 'light latte gradient', 'strong-testimonials' ),
568 'color' => '#F8F3EC',
569 'color2' => '#E0C8AB',
570 ),
571 'light-plum-gradient' => array(
572 'label' => esc_html__( 'light plum gradient', 'strong-testimonials' ),
573 'color' => '#F7EEF7',
574 'color2' => '#E9D0E9',
575 ),
576 'sky-blue-gradient' => array(
577 'label' => esc_html__( 'sky blue gradient', 'strong-testimonials' ),
578 'color' => '#E9F6FB',
579 'color2' => '#C8E9F6',
580 ),
581 );
582
583 if ( $preset ) {
584 if ( isset( $presets[ $preset ] ) ) {
585 return $presets[ $preset ];
586 } else {
587 return wpmtst_get_background_defaults();
588 }
589 }
590
591 return $presets;
592 }
593
594 /**
595 * Return the form success message.
596 *
597 * @since 2.18.0
598 *
599 * @return mixed
600 */
601 function wpmtst_get_success_message( $atts = false ) {
602 $message = wpautop( do_shortcode( wpmtst_get_form_message( 'submission-success' ) ) );
603 $message = sprintf( '<div class="%s">%s</div>', 'wpmtst-testimonial-success', $message );
604
605 return apply_filters( 'wpmtst_form_success_message', $message, $atts );
606 }
607
608 /**
609 * Does callback exist?
610 *
611 * @param $callback
612 * @since 2.18.0
613 *
614 * @return bool
615 */
616 // TODO Move to Utils class
617 function wpmtst_callback_exists( $callback ) {
618 if ( is_array( $callback ) ) {
619 $exists = method_exists( $callback[0], $callback[1] );
620 } else {
621 $exists = function_exists( $callback );
622 }
623
624 return $exists;
625 }
626
627 /**
628 * Check for Divi Builder plugin.
629 *
630 * Its plugin version constant is inaccurate so get the version from the file header.
631 *
632 * @since 2.22.0
633 *
634 * @return bool
635 */
636 function wpmtst_divi_builder_active() {
637 $active = false;
638 if ( wpmtst_is_plugin_active( 'divi-builder/divi-builder.php' ) ) {
639 $plugin = get_file_data( WP_PLUGIN_DIR . '/divi-builder/divi-builder.php', array( 'version' => 'Version' ) );
640 if ( isset( $plugin['version'] ) && version_compare( $plugin['version'], '2' ) > 0 ) {
641 $active = true;
642 }
643 }
644
645 return $active;
646 }
647
648 /**
649 * Append custom fields to testimonial content in theme's single post template.
650 *
651 * @param $content
652 * @since 2.22.0
653 *
654 * @return string
655 */
656 function wpmtst_single_template_add_content( $content ) {
657 if ( is_singular( 'wpm-testimonial' ) || is_tax( 'wpm-testimonial-category' ) ) {
658 $content .= wpmtst_single_template_client();
659 }
660
661 return $content;
662 }
663 add_filter( 'the_content', 'wpmtst_single_template_add_content' );
664
665 /**
666 * Frequent plugin checks.
667 *
668 * A combination of an array of frequent plugin names, and core's is_plugin_active functions
669 * which are not available in front-end without loading plugin.php which is uncecessary.
670 *
671 * @param $plugin
672 *
673 * @return bool
674 */
675 function wpmtst_is_plugin_active( $plugin = '' ) {
676 if ( ! $plugin ) {
677 return false;
678 }
679
680 $plugins = array(
681 'wpml' => 'sitepress-multilingual-cms/sitepress.php',
682 'polylang' => 'polylang/polylang.php',
683 'lazy-loading-responsive-images' => 'lazy-loading-responsive-images/lazy-load-responsive-images.php',
684 );
685 if ( isset( $plugins[ $plugin ] ) ) {
686 $plugin = $plugins[ $plugin ];
687 }
688
689 if ( in_array( $plugin, (array) get_option( 'active_plugins', array() ), true ) ) {
690 return true;
691 }
692
693 if ( ! is_multisite() ) {
694 return false;
695 }
696
697 $plugins = get_site_option( 'active_sitewide_plugins' );
698 if ( isset( $plugins[ $plugin ] ) ) {
699 return true;
700 }
701
702 return false;
703 }
704
705 /**
706 * Sanitize a textarea from user input. Based on sanitize_text_field.
707 *
708 * Check for invalid UTF-8,
709 * Convert single < characters to entity,
710 * strip all tags,
711 * strip octets.
712 *
713 * @since 2.11.8
714 *
715 * @param string $text
716 *
717 * @return string
718 */
719 function wpmtst_sanitize_textarea( $text ) {
720 $filtered = wp_check_invalid_utf8( $text );
721
722 if ( strpos( $filtered, '<' ) !== false ) {
723 $filtered = wp_pre_kses_less_than( $filtered );
724 // This will NOT strip extra whitespace.
725 $filtered = wp_strip_all_tags( $filtered, false );
726 }
727
728 while ( preg_match( '/%[a-f0-9]{2}/i', $filtered, $match ) ) {
729 $filtered = str_replace( $match[0], '', $filtered );
730 }
731
732 /**
733 * Filter a sanitized textarea string.
734 *
735 * @param string $filtered The sanitized string.
736 * @param string $str The string prior to being sanitized.
737 */
738 return apply_filters( 'wpmtst_sanitize_textarea', $filtered, $text );
739 }
740
741 /**
742 * Store values as 1 or 0 (never blank).
743 *
744 * Checked checkbox value is "on" but unchecked checkboxes are _not_ submitted.
745 *
746 * @param $input
747 * @param $key string Must be explicit. Do not simply loop through an input array.
748 *
749 * @return int
750 */
751 function wpmtst_sanitize_checkbox( $input, $key ) {
752 if ( isset( $input[ $key ] ) ) {
753 if ( 'on' === $input[ $key ] ) { // checked checkbox
754 return true;
755 } else { // hidden input
756 return $input[ $key ] ? true : false; // 0 or 1
757 }
758 } else { // unchecked checkbox
759 return false;
760 }
761 }
762
763 /**
764 * Trims a entire array recursively.
765 *
766 * @since 2.26.6
767 *
768 * @props Jonas John
769 * @version 0.2
770 * @link http://www.jonasjohn.de/snippets/php/trim-array.htm
771 * @param $input array|string
772 *
773 * @return array|string
774 */
775 function wpmtst_trim_array( $input ) {
776 if ( ! is_array( $input ) ) {
777 return trim( $input );
778 }
779
780 return array_map( 'wpmtst_trim_array', $input );
781 }
782
783 if ( ! function_exists( 'normalize_empty_atts' ) ) {
784 /**
785 * Normalize empty shortcode attributes.
786 *
787 * Turns atts into tags - brilliant!
788 * Thanks http://wordpress.stackexchange.com/a/123073/32076
789 *
790 * @param $atts
791 *
792 * @return mixed
793 */
794 function normalize_empty_atts( $atts ) {
795 if ( ! empty( $atts ) ) {
796 foreach ( $atts as $attribute => $value ) {
797 if ( is_int( $attribute ) ) {
798 $atts[ strtolower( $value ) ] = true;
799 unset( $atts[ $attribute ] );
800 }
801 }
802 }
803
804 return $atts;
805 }
806 }
807
808 // @todo : check in addons to see if function is called somewhere, else delete it
809 if ( ! function_exists( 'wpmtst_round_to_half' ) ) {
810 /**
811 * Round to the nearest half.
812 *
813 * @param $value
814 *
815 * @since 2.31.0
816 * @return float|int
817 */
818 function wpmtst_round_to_half( $value ) {
819 if ( is_string( $value ) ) {
820 $value = (float) str_replace( ',', '.', $value );
821 }
822 return round( (float) $value * 2 ) / 2;
823 }
824 }
825
826
827 if ( ! function_exists( 'wpmtst_strip_whitespace' ) ) {
828 /**
829 * Remove whitespace from HTML output.
830 *
831 * @param $html
832 *
833 * @return string
834 */
835 function wpmtst_strip_whitespace( $html ) {
836 return preg_replace( '~>\s+<~', '><', trim( $html ) );
837 }
838 }
839
840 if ( ! function_exists( 'wpmtst_current_url' ) ) {
841 /**
842 * Assemble and return the current URL.
843 *
844 * @since 2.31.0
845 * @return string
846 */
847 function wpmtst_current_url() {
848 global $wp;
849
850 return home_url( add_query_arg( array(), $wp->request ) );
851 }
852 }
853 if ( ! function_exists( 'get_formatted_views' ) ) {
854
855 function get_formatted_views() {
856 $views = wpmtst_get_views();
857
858 $view_array = array( 'none' => esc_html__( 'None', 'strong-testimonials' ) );
859 foreach ( $views as $view ) {
860 $view_array[ $view['id'] ] = esc_html( $view['name'] );
861 }
862 return $view_array;
863 }
864 }
865
866 /**
867 * Get stars svg
868 *
869 * @return string
870 * @since 3.1.9
871 */
872 function wpmtst_get_star_svg( $type = 'star_solid' ) {
873 $star = array();
874
875 $star['star_solid'] = '<svg class="star_solid" aria-hidden="true" focusable="false" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="-8 -8 584 520"><path d="M259.3 17.8L194 150.2 47.9 171.5c-26.2 3.8-36.7 36.1-17.7 54.6l105.7 103-25 145.5c-4.5 26.3 23.2 46 46.4 33.7L288 439.6l130.7 68.7c23.2 12.2 50.9-7.4 46.4-33.7l-25-145.5 105.7-103c19-18.5 8.5-50.8-17.7-54.6L382 150.2 316.7 17.8c-11.7-23.6-45.6-23.9-57.4 0z"></path></svg>';
876 $star['star_regular'] = '<svg class="star_regular" aria-hidden="true" focusable="false" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="-8 -8 584 520"><path d="M528.1 171.5L382 150.2 316.7 17.8c-11.7-23.6-45.6-23.9-57.4 0L194 150.2 47.9 171.5c-26.2 3.8-36.7 36.1-17.7 54.6l105.7 103-25 145.5c-4.5 26.3 23.2 46 46.4 33.7L288 439.6l130.7 68.7c23.2 12.2 50.9-7.4 46.4-33.7l-25-145.5 105.7-103c19-18.5 8.5-50.8-17.7-54.6zM388.6 312.3l23.7 138.4L288 385.4l-124.3 65.3 23.7-138.4-100.6-98 139-20.2 62.2-126 62.2 126 139 20.2-100.6 98z"></path></svg>';
877 $star['star_half'] = '<svg class="star_half" aria-hidden="true" focusable="false" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="-8 -8 584 520"><path d="M508.55 171.51L362.18 150.2 296.77 17.81C290.89 5.98 279.42 0 267.95 0c-11.4 0-22.79 5.9-28.69 17.81l-65.43 132.38-146.38 21.29c-26.25 3.8-36.77 36.09-17.74 54.59l105.89 103-25.06 145.48C86.98 495.33 103.57 512 122.15 512c4.93 0 10-1.17 14.87-3.75l130.95-68.68 130.94 68.7c4.86 2.55 9.92 3.71 14.83 3.71 18.6 0 35.22-16.61 31.66-37.4l-25.03-145.49 105.91-102.98c19.04-18.5 8.52-50.8-17.73-54.6zm-121.74 123.2l-18.12 17.62 4.28 24.88 19.52 113.45-102.13-53.59-22.38-11.74.03-317.19 51.03 103.29 11.18 22.63 25.01 3.64 114.23 16.63-82.65 80.38z"></path></svg>';
878
879 if ( isset( $star[ $type ] ) ) {
880 return $star[ $type ];
881 }
882
883 return '';
884 }
885