PluginProbe
ReviewX – Multi-Criteria Reviews for WooCommerce with Google Reviews & Schema / trunk
ReviewX – Multi-Criteria Reviews for WooCommerce with Google Reviews & Schema vtrunk
2.5.1 2.5.0 2.4.1 2.4.0 2.3.11 2.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.10 1.1.11 1.1.12 1.1.13 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 All 143 releases
reviewx / app / Shortcodes / Products / ReviewShowWIthIdsShortcode.php

ReviewShowWIthIdsShortcode.php in ReviewX – Multi-Criteria Reviews for WooCommerce with Google Reviews & Schema trunk, at app/Shortcodes/Products/ReviewShowWIthIdsShortcode.php

41 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ReviewX\Shortcodes\Products;
4
5 use ReviewX\Utilities\Auth\Client;
6 use ReviewX\Utilities\Helper;
7 use ReviewX\WPDrill\Contracts\ShortcodeContract;
8 use ReviewX\WPDrill\Facades\View;
9 class ReviewShowWIthIdsShortcode implements ShortcodeContract
10 {
11 public function render(array $attrs, ?string $content = null) : string
12 {
13 $attrs = shortcode_atts(['title' => 'false', 'review_ids' => null], $attrs);
14 // Check if both product_id and post_id are provided.
15 if (!Client::getSync()) {
16 return '<div class="warning">Error: Please complete the synchronization process of ReviewX.</div>';
17 }
18 // If review_ids is not provided, return an error.
19 if (empty($attrs['review_ids'])) {
20 return '<div class="warning">Error: Please provide "review_ids" in the shortcode.</div>';
21 }
22 $reviewsIds = $attrs['review_ids'];
23 $productIdArray = [];
24 // If review_ids is not null, process it
25 if ($reviewsIds) {
26 // Split review_ids by commas and trim whitespace
27 $productIdArray = \array_map('trim', \explode(',', $reviewsIds));
28 // Send multiple product IDs to the JavaScript variable
29 $data = $this->reviewsWiseReviewShow($productIdArray);
30 // Return the view (empty or simplified, as no review data is required)
31 return View::render('storefront/shortcode/reviewShowWIthIds', ['title' => $attrs['title'], 'data' => \json_encode($data)]);
32 }
33 return '';
34 }
35 public function reviewsWiseReviewShow($reviewsIds) : array
36 {
37 $attributes = ['ids' => $reviewsIds, 'domain' => ['baseDomain' => Helper::domainSupport(), 'baseRestUrl' => Helper::getRestAPIurl()]];
38 return $attributes;
39 }
40 }
41