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 / Rest / Controllers / PingController.php

PingController.php in ReviewX – Multi-Criteria Reviews for WooCommerce with Google Reviews & Schema trunk, at app/Rest/Controllers/PingController.php

40 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ReviewX\Rest\Controllers;
4
5 \defined("ABSPATH") || exit;
6 use Exception;
7 use WP_REST_Response;
8 use ReviewX\Services\PingService;
9 use ReviewX\Utilities\Helper;
10 class PingController
11 {
12 protected PingService $pingService;
13 public function __construct()
14 {
15 $this->pingService = new PingService();
16 }
17 /**
18 * Ping from sass and (cached for 2 hours) return site info.
19 *
20 * @return WP_REST_Response
21 */
22 public function ping() : WP_REST_Response
23 {
24 // Cache time-to-live: 2 hours
25 $cache_duration = 3600 * 2;
26 try {
27 // Try to get cache
28 $data = \get_transient('rvx_ping_cache');
29 if (\false === $data) {
30 // Cache miss: fetch fresh data, store and return
31 $data = $this->pingService->ping();
32 \set_transient('rvx_ping_cache', $data, $cache_duration);
33 }
34 return Helper::rvxApi($data)->success(\__('Plugin Active', 'reviewx'), 200);
35 } catch (Exception $e) {
36 return Helper::rvxApi()->fails(\__('Plugin deactivated or uninstalled', 'reviewx'), 404);
37 }
38 }
39 }
40