Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * [glsr_summary] shortcode
- *
- * Most of the [site_reviews] options can be used in this shortcode
- * Additional options specific to this shortcode are:
- * - display: Allowed values are "rating", "recommend", "count". The recommend value is the percentage of your 4-5 star reviews from the total
- * - class: Here you can add CSS classes to the parent div
- * - style: Here you can add CSS styles to the parent div
- * - text: Here you can add some text to display under the heading
- *
- * Examples:
- * [glsr_summary display="count" text="Reviews from people like you"]
- * [glsr_summary display="rating" text="Out of 5"]
- * [glsr_summary display="recommend" text="Would recommend to a friend"]
- */
- add_shortcode('glsr_summary', function ($atts) {
- $atts = wp_parse_args($atts, [
- 'display' => 'rating',
- 'class' => '',
- 'style' => '',
- 'text' => '',
- ]);
- if (!function_exists('glsr_get_ratings') || !function_exists('glsr_star_rating')) {
- return 'This shortcode requires Site Reviews.';
- }
- $ratingInfo = glsr_get_ratings($atts);
- $text = wpautop($atts['text']);
- if ('count' === $atts['display']) {
- $heading = $ratingInfo->reviews;
- } elseif ('recommend' === $atts['display']) {
- $positive = $ratingInfo->ratings[4] + $ratingInfo->ratings[5];
- $percent = round(($positive / $ratingInfo->reviews) * 100);
- $heading = sprintf('%d%%', $percent);
- } else {
- $heading = number_format($ratingInfo->average, 1);
- $text .= glsr_star_rating($ratingInfo->average, $ratingInfo->reviews);
- }
- return sprintf('<div class="glsr %s" style="%s"><h3>%s</h3>%s</div>',
- $atts['class'],
- $atts['style'],
- $heading,
- $text
- );
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement