Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Registers the [site_review] shortcode
- * This shortcode displays a single review
- *
- * Shortcode options are as follows:
- * - [site_reviews form=""] Optional. Allowed values: the Post ID of a custom review form
- * - [site_reviews hide=""] Optional. Allowed values are same as in the [site_reviews] shortcode.
- * - [site_reviews post_id=""] Optional. Allowed values: the Post ID of a review
- * - [site_reviews theme=""] Optional. Allowed values: the Post ID of a custom review theme
- *
- * Paste this in your active theme's functions.php file
- * @param array $atts
- * @return string|void
- */
- add_shortcode('site_review', function ($atts) {
- $atts = wp_parse_args($atts, [
- 'form' => '',
- 'hide' => '',
- 'post_id' => '',
- 'theme' => '',
- ]);
- if (!empty($atts['post_id'])) {
- $reviews = apply_filters('glsr_get_reviews', null, [
- 'per_page' => 1,
- 'post__in' => (array) $atts['post_id'],
- ]);
- }
- if (!empty($reviews)) {
- $reviews->args['form'] = $atts['form'];
- $reviews->args['hide'] = array_map('trim', explode(',', $atts['hide']));
- $reviews->args['theme'] = $atts['theme'];
- $html = $reviews->build();
- return sprintf('<div class="%s">%s</div>', $html->style, $html);
- }
- });
RAW Paste Data
Copied