Skip to content

Instantly share code, notes, and snippets.

@andykillen
Created January 29, 2024 10:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andykillen/75f2d11d80ae17cf73a185a7d08b06af to your computer and use it in GitHub Desktop.
Save andykillen/75f2d11d80ae17cf73a185a7d08b06af to your computer and use it in GitHub Desktop.
<?php
/**
* Plugin Name: Servebolt Hide Admin Menus
* Description: Hides the admin menus for role(s) that they are not wanted for.
* Author: Servebolt
* Author URI: https://servebolt.com
* Version: 1.0
* @author Servebolt
* @package Servebolt Hide Admin Menus
**/
add_filter('sb_optimizer_display_admin_bar_menu', 'sb_admin_bar_filter', 10);
/**
* Stop the Servebolt Admin menus (side and top) from showing.
*/
function sb_admin_bar_filter($default_value) {
$role_that_should_not_see_the_menu = 'editor';
if(in_array($role_that_should_not_see_the_menu, sb_get_current_user_roles())) {
return false;
}
return $default_value;
}
/**
* Get an array of roles, its empty if they are not logged in.
*
* @return array
*/
function sb_get_current_user_roles() {
if( is_user_logged_in() ) {
$user = wp_get_current_user();
$roles = ( array ) $user->roles;
return $roles;
}
return [];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment