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