| @@ -9,8 +9,9 @@ | ||
| 9 | 9 | |
| 10 | 10 | namespace RadiusTheme\SB\Controllers; |
| 11 | 11 | |
| 12 | 12 | use RadiusTheme\SB\Helpers\Cache; |
| 13 | +use RadiusTheme\SB\Helpers\Fns; | |
| 13 | 14 | use RadiusTheme\SB\Traits\SingletonTrait; |
| 14 | 15 | |
| 15 | 16 | // Do not allow directly accessing this file. |
| 16 | 17 | if ( ! defined( 'ABSPATH' ) ) { |
| @@ -56,17 +57,29 @@ | ||
| 56 | 57 | $wp_admin_bar->add_node( |
| 57 | 58 | [ |
| 58 | 59 | 'id' => 'clear_all_cache', |
| 59 | 60 | 'parent' => 'shop_builder', // Set the parent to the top-level item ID. |
| 60 | - 'title' => 'Clear All Cache', | |
| 61 | + 'title' => esc_html__( 'Purge All Cache', 'shopbuilder' ), | |
| 61 | 62 | 'href' => wp_nonce_url( add_query_arg( 'rtsb_clear_cache', 'all', add_query_arg( null, null ) ), rtsb()->nonceText ), |
| 62 | 63 | ] |
| 63 | 64 | ); |
| 65 | + | |
| 66 | + if ( Fns::is_optimization_enabled() ) { | |
| 67 | + $wp_admin_bar->add_node( | |
| 68 | + [ | |
| 69 | + 'id' => 'clear_asset_cache', | |
| 70 | + 'parent' => 'shop_builder', | |
| 71 | + 'title' => esc_html__( 'Purge Asset Cache', 'shopbuilder' ), | |
| 72 | + 'href' => wp_nonce_url( add_query_arg( 'rtsb_clear_cache', 'asset', add_query_arg( null, null ) ), rtsb()->nonceText ), | |
| 73 | + ] | |
| 74 | + ); | |
| 75 | + } | |
| 76 | + | |
| 64 | 77 | $wp_admin_bar->add_node( |
| 65 | 78 | [ |
| 66 | 79 | 'id' => 'clear_object_cache', |
| 67 | - 'parent' => 'shop_builder', // Set the parent to the top-level item ID. | |
| 68 | - 'title' => 'Clear Object Cache', | |
| 80 | + 'parent' => 'shop_builder', | |
| 81 | + 'title' => esc_html__( 'Purge Object Cache', 'shopbuilder' ), | |
| 69 | 82 | 'href' => wp_nonce_url( add_query_arg( 'rtsb_clear_cache', 'data', add_query_arg( null, null ) ), rtsb()->nonceText ), |
| 70 | 83 | ] |
| 71 | 84 | ); |
| 72 | 85 | $wp_admin_bar->add_node( |
| @@ -71,16 +84,17 @@ | ||
| 71 | 84 | ); |
| 72 | 85 | $wp_admin_bar->add_node( |
| 73 | 86 | [ |
| 74 | 87 | 'id' => 'clear_template_cache', |
| 75 | - 'parent' => 'shop_builder', // Set the parent to the top-level item ID. | |
| 76 | - 'title' => 'Clear Template Cache', | |
| 88 | + 'parent' => 'shop_builder', | |
| 89 | + 'title' => esc_html__( 'Purge Template Cache', 'shopbuilder' ), | |
| 77 | 90 | 'href' => wp_nonce_url( add_query_arg( 'rtsb_clear_cache', 'template', add_query_arg( null, null ) ), rtsb()->nonceText ), |
| 78 | 91 | ] |
| 79 | 92 | ); |
| 80 | 93 | } |
| 81 | 94 | |
| 82 | - /*** | |
| 95 | + | |
| 96 | + /** | |
| 83 | 97 | * |
| 84 | 98 | * @return mixed |
| 85 | 99 | */ |
| 86 | 100 | public function admin_bar_menu_action() { |
| @@ -89,12 +103,14 @@ | ||
| 89 | 103 | } |
| 90 | 104 | if ( ! current_user_can( 'manage_options' ) ) { |
| 91 | 105 | return; |
| 92 | 106 | } |
| 107 | + | |
| 93 | 108 | $clear_cache = sanitize_text_field( wp_unslash( $_GET['rtsb_clear_cache'] ?? '' ) ); |
| 94 | 109 | if ( empty( $clear_cache ) ) { |
| 95 | 110 | return; |
| 96 | 111 | } |
| 112 | + | |
| 97 | 113 | switch ( $clear_cache ) { |
| 98 | 114 | case 'all': |
| 99 | 115 | Cache::clear_all_cache(); |
| 100 | 116 | break; |
| @@ -103,19 +119,24 @@ | ||
| 103 | 119 | break; |
| 104 | 120 | case 'template': |
| 105 | 121 | Cache::clear_template_cache(); |
| 106 | 122 | break; |
| 123 | + case 'asset': | |
| 124 | + Cache::clear_asset_cache(); | |
| 125 | + break; | |
| 107 | 126 | } |
| 108 | 127 | // Set the notice flag. |
| 109 | 128 | 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 ); | |
| 129 | + $referrer = wp_get_referer(); // Get the referrer URL. | |
| 130 | + if ( $referrer ) { | |
| 131 | + // Rebuild the URL with the original path and query string. | |
| 132 | + $redirect_url = $referrer; | |
| 133 | + // Redirect to the referrer URL with its query string intact. | |
| 134 | + wp_safe_redirect( $redirect_url ); | |
| 135 | + exit; | |
| 136 | + } | |
| 137 | + // Fallback: if referrer is not available, redirect to home_url(). | |
| 138 | + wp_safe_redirect( home_url() ); | |
| 118 | 139 | exit; |
| 119 | 140 | } |
| 120 | 141 | |
| 121 | 142 | /** |