admin管理员组文章数量:1391937
How do I make it so that a menu on the WP Admin menu bar is only visible to specified user roles?
I have this code which works to remove WP Admin menu items from all users. Is there any way to customize it so that only certain user roles can view these menu item? Thank you!
function shapeSpace_remove_toolbar_menu() {
global $wp_admin_bar;
$wp_admin_bar->remove_menu('site-name');
}
add_action('wp_before_admin_bar_render', 'shapeSpace_remove_toolbar_menu', 999);
How do I make it so that a menu on the WP Admin menu bar is only visible to specified user roles?
I have this code which works to remove WP Admin menu items from all users. Is there any way to customize it so that only certain user roles can view these menu item? Thank you!
function shapeSpace_remove_toolbar_menu() {
global $wp_admin_bar;
$wp_admin_bar->remove_menu('site-name');
}
add_action('wp_before_admin_bar_render', 'shapeSpace_remove_toolbar_menu', 999);
Share
Improve this question
asked Mar 8, 2020 at 1:38
deleted-userdeleted-user
312 bronze badges
1
|
1 Answer
Reset to default 1function shapeSpace_remove_toolbar_menu() {
global $wp_admin_bar;
// remove menu for editor and author
if( current_user_can( 'editor' ) || current_user_can( 'author' ) ){
$wp_admin_bar->remove_menu('site-name');
}
}
add_action('wp_before_admin_bar_render', 'shapeSpace_remove_toolbar_menu', 999);
All Roles:
current_user_can( 'administrator' )
current_user_can( 'editor' )
current_user_can( 'author' )
current_user_can( 'contributor' )
current_user_can( 'subscriber' )
本文标签: Remove WP Admin Menu Items by User Role
版权声明:本文标题:Remove WP Admin Menu Items by User Role 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744685570a2619676.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
if ( ! current_user_can('manage_options') ) { $wp_admin_bar->remove_menu( 'site-name' ); }
will display the Site name menu item to only the administrator users. – Mayeenul Islam Commented Mar 8, 2020 at 4:13