From 86c82c77fc434d0ddc4e0197c029e192ad472338 Mon Sep 17 00:00:00 2001 From: Nicolas Lemoine Date: Fri, 17 Jan 2025 11:17:52 +0100 Subject: [PATCH] Add a filter to provide fine grained control over user caps --- wp-environment-switcher.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/wp-environment-switcher.php b/wp-environment-switcher.php index 5f39e36..eefd8f2 100644 --- a/wp-environment-switcher.php +++ b/wp-environment-switcher.php @@ -83,8 +83,15 @@ function get_translated_url( string $environment_url ): string { * Register the admin environment switcher in the admin bar. */ function register_admin_bar(): void { + /** + * Filter the ability to show the environment switcher in the admin bar. + * + * @param bool $can_show_menu The current environment. + */ + $can_show_menu = (bool) apply_filters( 'wp_environment_switcher_can_show_menu', current_user_can( 'view_environment_switcher' ) ); + // Check if the user has permission to view the switcher. - if ( ! current_user_can( 'view_environment_switcher' ) ) { + if ( ! $can_show_menu ) { return; }