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 / CacheController.php

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

63 lines 2.8 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 use ReviewX\Services\CacheServices;
6 use WP_REST_Request;
7 use WP_REST_Response;
8 use ReviewX\Utilities\Helper;
9 class CacheController
10 {
11 protected CacheServices $cacheService;
12 public function __construct()
13 {
14 $this->cacheService = new CacheServices();
15 }
16 public function clearAdminCache(WP_REST_Request $request) : WP_REST_Response
17 {
18 $this->cacheService->removeCache();
19 return Helper::rest(['success' => \true])->success('Admin API cache cleared successfully.');
20 }
21 public function clearProductCache(WP_REST_Request $request) : WP_REST_Response
22 {
23 $productId = $request->get_param('product_id');
24 if ($productId === 'all') {
25 global $wpdb;
26 $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_rvx_%_latest_reviews%'");
27 $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_timeout_rvx_%_latest_reviews%'");
28 return Helper::rest(['success' => \true])->success('All product caches cleared.');
29 }
30 if ($productId) {
31 $this->cacheService->removeProductCache($productId);
32 return Helper::rest(['success' => \true])->success('Product cache cleared.');
33 }
34 return Helper::rest(['success' => \false])->fails('Product ID is required.');
35 }
36 public function clearShortcodeCache(WP_REST_Request $request) : WP_REST_Response
37 {
38 $type = $request->get_param('type');
39 if ($type === 'all') {
40 \delete_transient('rvx_review_shortcode');
41 \delete_transient('rvx_shortcode_transient');
42 \delete_transient('rvx_shortcode_all_reviews');
43 global $wpdb;
44 $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_rvx_google_reviews_cache_%'");
45 $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_timeout_rvx_google_reviews_cache_%'");
46 return Helper::rest(['success' => \true])->success('All shortcode caches cleared.');
47 }
48 if ($type) {
49 if ($type === 'google_review_list') {
50 global $wpdb;
51 $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_rvx_google_reviews_cache_%'");
52 $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_timeout_rvx_google_reviews_cache_%'");
53 } else {
54 \delete_transient('rvx_review_shortcode');
55 \delete_transient('rvx_shortcode_transient');
56 \delete_transient('rvx_shortcode_all_reviews');
57 }
58 return Helper::rest(['success' => \true])->success('Specific shortcode cache cleared.');
59 }
60 return Helper::rest(['success' => \false])->fails('Type is required.');
61 }
62 }
63