elementor
1 year ago
logs
1 month ago
strong-testimonials-beaver-block
1 year ago
submodules
8 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
1 month ago
class-strong-testimonials-form.php
1 month ago
class-strong-testimonials-order.php
1 year ago
class-strong-testimonials-privacy.php
1 year ago
class-strong-testimonials-render.php
1 month ago
class-strong-testimonials-templates.php
1 year ago
class-strong-testimonials-view-shortcode.php
1 week ago
class-strong-testimonials-view-widget.php
1 year ago
class-strong-view-display.php
2 days ago
class-strong-view-form.php
2 days ago
class-strong-view-slideshow.php
2 days ago
class-strong-view.php
2 days ago
class-walker-strong-category-checklist-front.php
1 year ago
deprecated.php
1 year ago
filters.php
1 month ago
functions-activation.php
1 month ago
functions-content.php
11 months ago
functions-image.php
5 months ago
functions-rating.php
1 year ago
functions-template-form.php
1 week ago
functions-template.php
4 months ago
functions-views.php
1 year ago
functions.php
1 month ago
l10n-polylang.php
1 year ago
l10n-wpml.php
1 year ago
post-types.php
1 week ago
retro.php
1 year ago
scripts.php
1 month ago
functions-rating.php
159 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Print the star rating form. |
| 5 | * |
| 6 | * @since 2.12.0 |
| 7 | * @since 2.23.2 $field_array |
| 8 | * |
| 9 | * @param array|string $field |
| 10 | * @param int $value |
| 11 | * @param string $wrapper_class |
| 12 | * @param bool $should_echo |
| 13 | * @param string $field_array If included, set field name in array. In post editor meta box. |
| 14 | * |
| 15 | * @return string |
| 16 | */ |
| 17 | function wpmtst_star_rating_form( $field, $value, $wrapper_class, $should_echo = true, $field_array = '' ) { |
| 18 | $value = (int) $value; |
| 19 | if ( $field && is_array( $field ) && isset( $field['name'] ) ) { |
| 20 | $name = $field['name']; |
| 21 | if ( $field_array ) { |
| 22 | $name = $field_array . '[' . $name . ']'; |
| 23 | } |
| 24 | } else { |
| 25 | $name = 'rating'; |
| 26 | } |
| 27 | $star_solid = wpmtst_get_star_svg( 'star_solid' ); |
| 28 | $star_regular = wpmtst_get_star_svg( 'star_regular' ); |
| 29 | |
| 30 | $star_regular = '<svg aria-hidden="true" focusable="false" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="-12 -12 590 526"> |
| 31 | <path class="star_regular" 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> |
| 32 | <path class="star_solid" 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> |
| 33 | </svg>'; |
| 34 | $random = wp_rand( 1, 9999 ); |
| 35 | $svg_args = array( |
| 36 | 'svg' => array( |
| 37 | 'class' => true, |
| 38 | 'aria-hidden' => true, |
| 39 | 'aria-labelledby' => true, |
| 40 | 'role' => true, |
| 41 | 'xmlns' => true, |
| 42 | 'width' => true, |
| 43 | 'height' => true, |
| 44 | 'viewbox' => true, // <= Must be lower case! |
| 45 | 'id' => true, |
| 46 | ), |
| 47 | 'g' => array( 'fill' => true ), |
| 48 | 'title' => array( 'title' => true ), |
| 49 | 'path' => array( |
| 50 | 'd' => true, |
| 51 | 'fill' => true, |
| 52 | 'class' => true, |
| 53 | ), |
| 54 | 'style' => array( 'type' => true ), |
| 55 | ); |
| 56 | ob_start(); ?> |
| 57 | <div class="strong-rating-wrapper field-wrap <?php echo esc_attr( $wrapper_class ); ?>"><!-- cheap trick to collapse whitespace around inline-blocks |
| 58 | --><fieldset contenteditable=false |
| 59 | id="wpmtst_<?php echo esc_attr( $field['name'] ); ?>" |
| 60 | name="<?php echo esc_attr( $field['name'] ); ?>" |
| 61 | class="strong-rating" |
| 62 | data-field-type="rating" |
| 63 | tabindex="0"> |
| 64 | <legend><?php esc_html_e( 'rating fields', 'strong-testimonials' ); ?></legend><!-- |
| 65 | |
| 66 | --><input type="radio" id="<?php echo esc_attr( $field['name'] ); ?>-star0-<?php echo absint( $random ); ?>" name="<?php echo esc_attr( $name ); ?>" value="0" <?php checked( $value, 0 ); ?> /><!-- |
| 67 | --><label for="<?php echo esc_attr( $field['name'] ); ?>-star0-<?php echo absint( $random ); ?>" title="No stars"></label><!-- |
| 68 | |
| 69 | --><input type="radio" id="<?php echo esc_attr( $field['name'] ); ?>-star1-<?php echo absint( $random ); ?>" name="<?php echo esc_attr( $name ); ?>" value="1" <?php checked( $value, 1 ); ?> /><!-- |
| 70 | --><label for="<?php echo esc_attr( $field['name'] ); ?>-star1-<?php echo absint( $random ); ?>" class="star" title="1 star"><?php echo wp_kses( $star_regular, $svg_args ); ?></label><!-- |
| 71 | |
| 72 | --><input type="radio" id="<?php echo esc_attr( $field['name'] ); ?>-star2-<?php echo absint( $random ); ?>" name="<?php echo esc_attr( $name ); ?>" value="2" <?php checked( $value, 2 ); ?> /><!-- |
| 73 | --><label for="<?php echo esc_attr( $field['name'] ); ?>-star2-<?php echo absint( $random ); ?>" class="star" title="2 stars"><?php echo wp_kses( $star_regular, $svg_args ); ?></label><!-- |
| 74 | |
| 75 | --><input type="radio" id="<?php echo esc_attr( $field['name'] ); ?>-star3-<?php echo absint( $random ); ?>" name="<?php echo esc_attr( $name ); ?>" value="3" <?php checked( $value, 3 ); ?> /><!-- |
| 76 | --><label for="<?php echo esc_attr( $field['name'] ); ?>-star3-<?php echo absint( $random ); ?>" class="star" title="3 stars"><?php echo wp_kses( $star_regular, $svg_args ); ?></label><!-- |
| 77 | |
| 78 | --><input type="radio" id="<?php echo esc_attr( $field['name'] ); ?>-star4-<?php echo absint( $random ); ?>" name="<?php echo esc_attr( $name ); ?>" value="4" <?php checked( $value, 4 ); ?> /><!-- |
| 79 | --><label for="<?php echo esc_attr( $field['name'] ); ?>-star4-<?php echo absint( $random ); ?>" class="star" title="4 stars"><?php echo wp_kses( $star_regular, $svg_args ); ?></label><!-- |
| 80 | |
| 81 | --><input type="radio" id="<?php echo esc_attr( $field['name'] ); ?>-star5-<?php echo absint( $random ); ?>" name="<?php echo esc_attr( $name ); ?>" value="5" <?php checked( $value, 5 ); ?> /><!-- |
| 82 | --><label for="<?php echo esc_attr( $field['name'] ); ?>-star5-<?php echo absint( $random ); ?>" class="star" title="5 stars"><?php echo wp_kses( $star_regular, $svg_args ); ?></label><!-- |
| 83 | |
| 84 | --></fieldset><!-- |
| 85 | --></div> |
| 86 | <?php |
| 87 | $html = ob_get_contents(); |
| 88 | ob_end_clean(); |
| 89 | $html = preg_replace( '/<!--(.|\s)*?-->/', '', $html ); |
| 90 | |
| 91 | if ( $should_echo ) { |
| 92 | echo $html; |
| 93 | return true; |
| 94 | } |
| 95 | |
| 96 | return $html; |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * @param int $value |
| 101 | * @param $wrapper_class |
| 102 | * @param bool $should_echo |
| 103 | * |
| 104 | * @return bool|string |
| 105 | */ |
| 106 | function wpmtst_star_rating_display( $value = 0, $wrapper_class = 'in-view', $should_echo = true ) { |
| 107 | $value = (int) $value; |
| 108 | $star_solid = wpmtst_get_star_svg( 'star_solid' ); |
| 109 | $star_regular = wpmtst_get_star_svg( 'star_regular' ); |
| 110 | $svg_args = array( |
| 111 | 'svg' => array( |
| 112 | 'class' => true, |
| 113 | 'aria-hidden' => true, |
| 114 | 'aria-labelledby' => true, |
| 115 | 'role' => true, |
| 116 | 'xmlns' => true, |
| 117 | 'width' => true, |
| 118 | 'height' => true, |
| 119 | 'viewbox' => true, // <= Must be lower case! |
| 120 | 'id' => true, |
| 121 | ), |
| 122 | 'g' => array( 'fill' => true ), |
| 123 | 'title' => array( 'title' => true ), |
| 124 | 'path' => array( |
| 125 | 'd' => true, |
| 126 | 'fill' => true, |
| 127 | ), |
| 128 | 'style' => array( 'type' => true ), |
| 129 | 'span' => array( |
| 130 | 'style' => array(), |
| 131 | 'class' => array(), |
| 132 | ), |
| 133 | ); |
| 134 | |
| 135 | ob_start(); |
| 136 | ?> |
| 137 | <span class="strong-rating-wrapper <?php echo esc_attr( $wrapper_class ); ?>"> |
| 138 | <span class="strong-rating"><!-- cheap trick to collapse whitespace around inline-blocks |
| 139 | --><span class="star" style="display: none;"></span><!-- |
| 140 | --><span class="star" style="display: inline-block;"><?php echo ( 1 <= $value ) ? wp_kses( $star_solid, $svg_args ) : wp_kses( $star_regular, $svg_args ); ?></span><!-- |
| 141 | --><span class="star" style="display: inline-block;"><?php echo ( 2 <= $value ) ? wp_kses( $star_solid, $svg_args ) : wp_kses( $star_regular, $svg_args ); ?></span><!-- |
| 142 | --><span class="star" style="display: inline-block;"><?php echo ( 3 <= $value ) ? wp_kses( $star_solid, $svg_args ) : wp_kses( $star_regular, $svg_args ); ?></span><!-- |
| 143 | --><span class="star" style="display: inline-block;"><?php echo ( 4 <= $value ) ? wp_kses( $star_solid, $svg_args ) : wp_kses( $star_regular, $svg_args ); ?></span><!-- |
| 144 | --><span class="star" style="display: inline-block;"><?php echo ( 5 <= $value ) ? wp_kses( $star_solid, $svg_args ) : wp_kses( $star_regular, $svg_args ); ?></span><!-- |
| 145 | --></span> |
| 146 | </span> |
| 147 | <?php |
| 148 | $html = ob_get_contents(); |
| 149 | ob_end_clean(); |
| 150 | $html = preg_replace( '/<!--(.|\s)*?-->/', '', $html ); |
| 151 | |
| 152 | if ( $should_echo ) { |
| 153 | echo $html; |
| 154 | return true; |
| 155 | } |
| 156 | |
| 157 | return $html; |
| 158 | } |
| 159 |