From eb3662801f13440957b32d7f4b23ba1e7f71bee3 Mon Sep 17 00:00:00 2001 From: arunshenoy99 Date: Tue, 11 Feb 2025 15:05:10 +0530 Subject: [PATCH 1/2] Cache: Hide Admin Bar Menu When Disabled --- includes/CacheManager.php | 9 +++++++++ includes/Performance.php | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/includes/CacheManager.php b/includes/CacheManager.php index def8872..51a9e12 100644 --- a/includes/CacheManager.php +++ b/includes/CacheManager.php @@ -109,4 +109,13 @@ public function getInstances() { return $instances; } + + /** + * Retrieves the cache level setting from the database. + * + * @return int The cache level value, ensuring an integer is returned. + */ + public static function get_cache_level() { + return (int) get_option( Performance::OPTION_CACHE_LEVEL, 0 ); + } } diff --git a/includes/Performance.php b/includes/Performance.php index f6a8887..dcdc3a2 100644 --- a/includes/Performance.php +++ b/includes/Performance.php @@ -252,7 +252,7 @@ public function adminBarMenu( \WP_Admin_Bar $wp_admin_bar ) { $wp_admin_bar->remove_node( 'epc_purge_menu' ); } - if ( current_user_can( 'manage_options' ) ) { + if ( current_user_can( 'manage_options' ) && CacheManager::get_cache_level() > 0 ) { $wp_admin_bar->add_node( array( 'id' => 'nfd_purge_menu', From 93b4537a74424783b8131409a4970ee979d7ce1e Mon Sep 17 00:00:00 2001 From: arunshenoy99 Date: Tue, 11 Feb 2025 15:06:52 +0530 Subject: [PATCH 2/2] Fix variable reference --- includes/CacheManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/CacheManager.php b/includes/CacheManager.php index 51a9e12..26c7cb1 100644 --- a/includes/CacheManager.php +++ b/includes/CacheManager.php @@ -116,6 +116,6 @@ public function getInstances() { * @return int The cache level value, ensuring an integer is returned. */ public static function get_cache_level() { - return (int) get_option( Performance::OPTION_CACHE_LEVEL, 0 ); + return (int) get_option( self::OPTION_CACHE_LEVEL, 0 ); } }