PluginProbe ʕ •ᴥ•ʔ
NitroPack – Performance, Page Speed & Cache Plugin for Core Web Vitals, CDN & Image Optimization / trunk
NitroPack – Performance, Page Speed & Cache Plugin for Core Web Vitals, CDN & Image Optimization vtrunk
1.19.8 1.19.7 1.19.6 1.19.5 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.11.0 1.12.0 1.13.0 1.14.0 1.15.0 1.15.1 1.15.2 1.15.3 1.16.0 1.16.1 1.16.2 1.16.3 1.16.4 1.16.5 1.16.6 1.16.7 1.16.8 1.17.0 1.17.6 1.17.7 1.17.8 1.17.9 1.18.0 1.18.1 1.18.2 1.18.3 1.18.4 1.18.5 1.18.6 1.18.7 1.18.8 1.18.9 1.19.0 1.19.1 1.19.2 1.19.3 1.19.4 1.3.19 1.3.20 1.4.0 1.4.1 1.5.0 1.5.1 1.5.10 1.5.11 1.5.12 1.5.13 1.5.14 1.5.15 1.5.16 1.5.17 1.5.18 1.5.19 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.7.0 1.7.1 1.8.0 1.8.1 1.8.3 1.9.0 1.9.1 1.9.2
nitropack / classes / WordPress / Settings / CartCache.php
nitropack / classes / WordPress / Settings Last commit date
AutoPurge.php 4 months ago BeaverBuilder.php 4 months ago CPTOptimization.php 1 month ago CacheWarmup.php 1 month ago CartCache.php 4 months ago Components.php 1 month ago EditorClearCache.php 1 month ago GeneratePreview.php 7 months ago HTMLCompression.php 3 months ago Logger.php 4 months ago OptimizationLevel.php 3 days ago Optimizations.php 1 month ago PurgeCache.php 3 days ago Shortcodes.php 4 months ago StockRefresh.php 2 months ago Subscription.php 4 months ago SystemReport.php 4 months ago TestMode.php 1 month ago
CartCache.php
137 lines
1 <?php
2
3 namespace NitroPack\WordPress\Settings;
4 use Nitropack\WordPress\NitroPack;
5
6 class CartCache {
7
8 public function __construct() {
9 add_action( 'wp_ajax_nitropack_set_cart_cache_ajax', [ $this, 'nitropack_set_cart_cache_ajax' ] );
10 }
11
12 /**
13 * AJAX handler when toggling the setting in the Dashboard
14 * @return void
15 */
16 public function nitropack_set_cart_cache_ajax() {
17 nitropack_verify_ajax_nonce( $_REQUEST );
18 if ( get_nitropack()->isConnected() && class_exists( 'WooCommerce' ) ) {
19 $cartCacheStatus = (int) ( ! empty( $_POST["cartCacheStatus"] ) );
20
21 if ( $cartCacheStatus == 1 ) {
22 $this->enable_cart_cache();
23 } else {
24 $this->disable_cart_cache();
25 }
26 }
27 nitropack_json_and_exit( array(
28 "type" => "error",
29 "message" => nitropack_admin_toast_msgs( 'error' )
30 ) );
31 }
32 public function enable_cart_cache() {
33 if ( null !== $nitro = get_nitropack_sdk() ) {
34 try {
35 $nitro->enableCartCache();
36 NitroPack::getInstance()->getLogger()->notice( 'Cart cache is enabled' );
37 nitropack_json_and_exit( array(
38 "type" => "success",
39 "message" => nitropack_admin_toast_msgs( 'success' )
40 ) );
41 } catch (\Exception $e) {
42 NitroPack::getInstance()->getLogger()->error( 'Cart cache cannot be enabled. Error: ' . $e );
43 }
44 }
45
46 nitropack_json_and_exit( array(
47 "type" => "error",
48 "message" => nitropack_admin_toast_msgs( 'error' )
49 ) );
50 }
51
52 public function disable_cart_cache() {
53 if ( null !== $nitro = get_nitropack_sdk() ) {
54 try {
55 $nitro->disableCartCache();
56 NitroPack::getInstance()->getLogger()->notice( 'Cart cache is disabled' );
57 nitropack_json_and_exit( array(
58 "type" => "success",
59 "message" => nitropack_admin_toast_msgs( 'success' )
60 ) );
61 } catch (\Exception $e) {
62 NitroPack::getInstance()->getLogger()->error( 'Cart cache cannot be disabled. Error: ' . $e );
63 }
64 }
65
66 nitropack_json_and_exit( array(
67 "type" => "error",
68 "message" => nitropack_admin_toast_msgs( 'error' )
69 ) );
70 }
71 public function nitropack_is_cart_cache_active() {
72 $nitro = get_nitropack()->getSdk();
73 if ( $nitro ) {
74 $config = $nitro->getConfig();
75 if ( ! empty( $config->StatefulCache->Status ) && ! empty( $config->StatefulCache->CartCache ) ) {
76 return $this->nitropack_is_cart_cache_available();
77 }
78 }
79 return false;
80 }
81 public function nitropack_is_cart_cache_available() {
82 $nitro = get_nitropack()->getSdk();
83 if ( $nitro ) {
84 $config = $nitro->getConfig();
85 if ( ! empty( $config->StatefulCache->isCartCacheAvailable ) ) {
86 return true;
87 }
88 }
89 return false;
90 }
91 /**
92 * Renders the Cart Cache option in the Dashboard
93 * @return void
94 */
95 public function render() {
96 if ( class_exists( 'WooCommerce' ) ) { ?>
97 <div class="nitro-option" id="cart-cache-widget">
98 <div class="nitro-option-main">
99 <div class="text-box">
100 <h6><?php esc_html_e( 'Cart cache', 'nitropack' ); ?></h6>
101 <p>
102 <?php esc_html_e( 'Your visitors will enjoy full site speed while browsing with items in cart. Fully optimized page cache will be served.', 'nitropack' ); ?>
103 </p>
104 </div>
105 <?php $components = new Components();
106 $components->render_toggle( 'cart-cache-status', $this->nitropack_is_cart_cache_active(), [ 'disabled' => ! $this->nitropack_is_cart_cache_available() ] ); ?>
107 </div>
108 <?php if ( ! $this->nitropack_is_cart_cache_available() ) : ?>
109 <div class="msg-container bg-success paid-msg">
110 <p><svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg"
111 class="text-success">
112 <g clip-path="url(#clip0_1244_36215)">
113 <path
114 d="M10.0001 18.3333C14.6025 18.3333 18.3334 14.6023 18.3334 9.99996C18.3334 5.39759 14.6025 1.66663 10.0001 1.66663C5.39771 1.66663 1.66675 5.39759 1.66675 9.99996C1.66675 14.6023 5.39771 18.3333 10.0001 18.3333Z"
115 stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path>
116 <path d="M13.3334 9.99996L10.0001 6.66663L6.66675 9.99996" stroke="currentColor" stroke-width="1.5"
117 stroke-linecap="round" stroke-linejoin="round"></path>
118 <path d="M10 13.3333V6.66663" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"
119 stroke-linejoin="round"></path>
120 </g>
121 <defs>
122 <clipPath id="clip0_1244_36215">
123 <rect width="20" height="20" fill="white"></rect>
124 </clipPath>
125 </defs>
126 </svg>
127 <?php esc_html_e( 'This feature is available on Plus plan and above.', 'nitropack' ); ?>
128 <a href="https://app.nitropack.io/subscription/buy" class="text-primary"
129 target="_blank"><b><?php esc_html_e( 'Upgrade here', 'nitropack' ); ?></b></a>
130 </p>
131 </div>
132 <?php endif; ?>
133 </div>
134 <?php
135 }
136 }
137 }