Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Use the Code Snippets (https://wordpress.org/plugins/code-snippets/)
- * plugin to add this shortcode to your website.
- *
- * Example usage:
- * [reviewer_experience assigned_posts="post_id" text="{positive}% are positive reviews, {negative}% are negative reviews."]
- */
- add_shortcode('reviewer_experience', function ($content = '') {
- $args = wp_parse_args($content, [
- 'text' => '{positive}% of reviewers reported a positive experience, while {negative}% reported a negative experience.',
- ]);
- $results = glsr_get_ratings($args);
- $negative = $results->ratings[0] + $results->ratings[1] + $results->ratings[2];
- $positive = $results->ratings[3] + $results->ratings[4] + $results->ratings[5];
- if ($negative > 0) {
- $negative = round($negative / $results->reviews * 100);
- }
- if ($positive > 0) {
- $positive = round($positive / $results->reviews * 100);
- }
- return str_replace(['{positive}', '{negative}'], [$positive, $negative], $args['text']);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement