Skip to content

Instantly share code, notes, and snippets.

@jennlee20
Last active May 3, 2021 08:07
Show Gist options
  • Save jennlee20/7e9cf24af2b1284c268be120a18d2e95 to your computer and use it in GitHub Desktop.
Save jennlee20/7e9cf24af2b1284c268be120a18d2e95 to your computer and use it in GitHub Desktop.
<?php
/**Remove Admin Bar Button**/
add_action( 'admin_bar_menu', 'me_remove_admin_bar', 999 );
function me_remove_admin_bar( $wp_admin_bar ) {
if( is_user_logged_in() ) {
$user = wp_get_current_user();
$roles = ( array ) $user->roles;
if (in_array('editor',$roles)) {
//to check what nodes
/*foreach($wp_admin_bar->get_nodes() as $nodes) {
echo '<pre>';
var_dump($nodes->id);
echo '</pre>';
}*/
$wp_admin_bar->remove_node( 'new-content' );
$wp_admin_bar->remove_node( 'wpseo-menu' );
}
}
}
/**Remove Admin Menu**/
add_action( 'admin_menu', 'me_remove_menus', 999 );
/**Remove Admin Menu**/
add_action( 'admin_menu', 'trustkad_remove_menus', 999 );
function trustkad_remove_menus() {
if( is_user_logged_in() ) {
//if do not know which menu to remove, can uncomment below
// then see the array index 2 and remove like this >>remove_menu_page('jet-engine');
// echo '<pre>' . print_r( $GLOBALS[ 'menu' ], TRUE) . '</pre>';
$user = wp_get_current_user();
$roles = ( array ) $user->roles;
$menu_remained = [
'edit.php?post_type=namecards',
'edit.php?post_type=companies',
'profile.php',
];
if (in_array('editor',$roles)) {
global $menu;
foreach ( $menu as $i => $item ) {
$menu_slug = $item[2];
//var_dump($menu_slug);
if(!in_array($menu_slug, $menu_remained)) {
remove_menu_page($menu_slug);
}
}
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment