PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 2.1.15
ShopBuilder – WooCommerce Builder For Elementor v2.1.15
3.4.1 3.4.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.3.0 All 62 releases
shopbuilder / app / Controllers / CacheController.php

CacheController.php in ShopBuilder – WooCommerce Builder For Elementor 2.1.15, at app/Controllers/CacheController.php

133 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Shortcodes Class.
4 *
5 * This class contains all the Shortcodes.
6 *
7 * @package RadiusTheme\SB
8 */
9
10 namespace RadiusTheme\SB\Controllers;
11
12 use RadiusTheme\SB\Helpers\Cache;
13 use RadiusTheme\SB\Traits\SingletonTrait;
14
15 // Do not allow directly accessing this file.
16 if ( ! defined( 'ABSPATH' ) ) {
17 exit( 'This script cannot be accessed directly.' );
18 }
19
20 /**
21 * CacheController Class.
22 */
23 class CacheController {
24 /**
25 * Singleton Trait
26 */
27 use SingletonTrait;
28
29 /**
30 * Class Constructor
31 */
32 public function __construct() {
33 // Hook to add custom item to admin bar.
34 add_action( 'admin_bar_menu', [ $this, 'admin_bar_menu' ], 9999 );
35 add_action( 'init', [ $this, 'admin_bar_menu_action' ] );
36 add_action( 'admin_notices', [ $this, 'cache_notice' ] );
37 }
38
39 /**
40 * @param object $wp_admin_bar hello.
41 * @return void
42 */
43 public function admin_bar_menu( $wp_admin_bar ) {
44 // Only add for administrators.
45 if ( ! current_user_can( 'manage_options' ) ) {
46 return;
47 }
48 // Add a top-level item.
49 $wp_admin_bar->add_node(
50 [
51 'id' => 'shop_builder',
52 'title' => 'ShopBuilder',
53 ]
54 );
55 // Add submenu items.
56 $wp_admin_bar->add_node(
57 [
58 'id' => 'clear_all_cache',
59 'parent' => 'shop_builder', // Set the parent to the top-level item ID.
60 'title' => 'Clear All Cache',
61 'href' => wp_nonce_url( add_query_arg( 'rtsb_clear_cache', 'all', add_query_arg( null, null ) ), rtsb()->nonceText ),
62 ]
63 );
64 $wp_admin_bar->add_node(
65 [
66 'id' => 'clear_object_cache',
67 'parent' => 'shop_builder', // Set the parent to the top-level item ID.
68 'title' => 'Clear Object Cache',
69 'href' => wp_nonce_url( add_query_arg( 'rtsb_clear_cache', 'data', add_query_arg( null, null ) ), rtsb()->nonceText ),
70 ]
71 );
72 $wp_admin_bar->add_node(
73 [
74 'id' => 'clear_template_cache',
75 'parent' => 'shop_builder', // Set the parent to the top-level item ID.
76 'title' => 'Clear Template Cache',
77 'href' => wp_nonce_url( add_query_arg( 'rtsb_clear_cache', 'template', add_query_arg( null, null ) ), rtsb()->nonceText ),
78 ]
79 );
80 }
81
82 /***
83 *
84 * @return mixed
85 */
86 public function admin_bar_menu_action() {
87 if ( ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ?? '' ) ), rtsb()->nonceText ) ) {
88 return;
89 }
90 if ( ! current_user_can( 'manage_options' ) ) {
91 return;
92 }
93 $clear_cache = sanitize_text_field( wp_unslash( $_GET['rtsb_clear_cache'] ?? '' ) );
94 if ( empty( $clear_cache ) ) {
95 return;
96 }
97 switch ( $clear_cache ) {
98 case 'all':
99 Cache::clear_all_cache();
100 break;
101 case 'data':
102 Cache::clear_data_cache();
103 break;
104 case 'template':
105 Cache::clear_template_cache();
106 break;
107 }
108 // Set the notice flag.
109 set_transient( 'rtsb_cache_cleared_notice', true, 30 );
110
111 $ref_pram = wp_parse_url( wp_get_referer() );
112 $path = $ref_pram['path'] ?? '/';
113 parse_str( ( $ref_pram['query'] ?? '' ), $query_array );
114 $the_query_arg = add_query_arg( $query_array, home_url( $path ) );
115 $params[] = '_wpnonce';
116 $redirect_url = urldecode( remove_query_arg( $params, $the_query_arg ) );
117 wp_safe_redirect( $redirect_url );
118 exit;
119 }
120
121 /**
122 * @return void
123 */
124 public function cache_notice() {
125 if ( get_transient( 'rtsb_cache_cleared_notice' ) ) {
126 echo '<div class="notice notice-success is-dismissible">';
127 echo '<p>' . esc_html__( 'Shopbuilder cache has been successfully cleared.', 'shopbuilder' ) . '</p>';
128 echo '</div>';
129 delete_transient( 'rtsb_cache_cleared_notice' );
130 }
131 }
132 }
133