PluginProbe ʕ •ᴥ•ʔ
Reviews Feed – Add Testimonials and Customer Reviews From Google Reviews, Yelp, TripAdvisor, and More / 2.7.0
Reviews Feed – Add Testimonials and Customer Reviews From Google Reviews, Yelp, TripAdvisor, and More v2.7.0
2.11.0 2.10.0 2.9.0 2.8.0 2.7.0 2.6.7 2.6.8 2.6.5 2.6.4 2.6.3 2.6.2 2.6.0 2.5.5 2.5.4 2.5.3 2.5.2 trunk 1.0 1.0.1 1.0.2 1.0.3 1.1 1.1.1 1.1.2 1.2.0 2.0 2.1.0 2.1.1 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.5.0 2.5.1
reviews-feed / class / Common / Integrations / Providers / BaseProvider.php
reviews-feed / class / Common / Integrations / Providers Last commit date
BaseProvider.php 1 month ago Google.php 1 month ago Yelp.php 1 month ago
BaseProvider.php
104 lines
1 <?php
2
3 /**
4 * Base Provider
5 */
6
7 namespace SmashBalloon\Reviews\Common\Integrations\Providers;
8
9 if (! defined('ABSPATH')) {
10 exit;
11 }
12
13 use SmashBalloon\Reviews\Common\Exceptions\RelayResponseException;
14 use SmashBalloon\Reviews\Common\Integrations\SBRelay;
15 use SmashBalloon\Reviews\Common\Utils\AjaxUtil;
16 use Smashballoon\Stubs\Services\ServiceProvider;
17
18 abstract class BaseProvider extends ServiceProvider
19 {
20 protected $name;
21 protected $endpoint;
22 protected $sources_endpoint;
23 protected $sources_remove;
24 private $relay;
25 protected $uses_connect = false;
26 protected $friendly_name;
27
28 public function __construct(SBRelay $relay)
29 {
30 $this->relay = $relay;
31 $this->endpoint = 'reviews/' . $this->name;
32 $this->sources_endpoint = 'sources/' . $this->name;
33 $this->sources_remove = 'source/remove';
34 }
35
36 public function register()
37 {
38 add_action('rest_api_init', [$this, 'registerRestEndpoint']);
39 add_filter('sbr_supported_providers', [$this, 'registerProvider']);
40 }
41
42 /**
43 * @throws RelayResponseException
44 */
45 public function getAllReviews($args = []): void
46 {
47 try {
48 $response = $this->relay->call($this->endpoint, $args->get_params(), 'GET', true);
49 wp_send_json($response);
50 } catch (RelayResponseException $exception) {
51 AjaxUtil::send_json_error($exception->getMessage(), $exception->getCode());
52 }
53 }
54
55 /**
56 * @throws RelayResponseException
57 */
58 public function getSourcesInfo($args = [])
59 {
60 $response = $this->relay->call($this->sources_endpoint, $args, 'GET', true);
61 if (isset($response['success']) && false === $response['success']) {
62 return wp_json_encode($response);
63 }
64
65 if (isset($response['data']) && $response['data']) {
66 return wp_json_encode($response['data']);
67 }
68 return false;
69 }
70
71 public function registerRestEndpoint()
72 {
73 register_rest_route(SBR_REST_DOMAIN, '/' . $this->endpoint, array(
74 'methods' => 'GET',
75 'callback' => [$this, 'getAllReviews'],
76 'permission_callback' => '__return_true'
77 ));
78 }
79
80 public function registerProvider($providers)
81 {
82 $providers[] = [
83 'name' => $this->name,
84 'endpoint' => get_rest_url(null, SBR_REST_DOMAIN . '/' . $this->endpoint),
85 'uses_connect' => $this->uses_connect,
86 'friendly_name' => $this->friendly_name
87 ];
88
89 return $providers;
90 }
91
92 /**
93 * @throws RelayResponseException
94 */
95 public function removeSource($args = [])
96 {
97 $response = $this->relay->call($this->sources_remove, $args, 'POST', true);
98 if (isset($response)) {
99 return wp_json_encode($response);
100 }
101 return false;
102 }
103 }
104