admin管理员组文章数量:1130349
How do I hide/remove the admin bar that is displayed when a user with specific role is logged in? I figured I have to do something with remove_menu(), but not exactly what and how.
Codex
How do I hide/remove the admin bar that is displayed when a user with specific role is logged in? I figured I have to do something with remove_menu(), but not exactly what and how.
Codex
Share Improve this question edited Sep 22, 2013 at 17:28 Joren asked Sep 22, 2013 at 17:12 JorenJoren 3171 gold badge5 silver badges23 bronze badges 2- A simple googling can answer you. Why not you tried that first? :) – Mayeenul Islam Commented Sep 22, 2013 at 17:21
- 3 Agreed, this is easy to find. But, @Christine's answer is a quality summary. +1 for that... – Johannes P. Commented Sep 22, 2013 at 17:29
2 Answers
Reset to default 6Add the following to your functions.php file as detailed here.
Disable Admin Bar for everyone:
// Disable Admin Bar for everyone
if (!function_exists('disable_admin_bar')) {
function disable_admin_bar() {
// for the admin page
remove_action('admin_footer', 'wp_admin_bar_render', 1000);
// for the front-end
remove_action('wp_footer', 'wp_admin_bar_render', 1000);
// css override for the admin page
function remove_admin_bar_style_backend() {
echo '<style>body.admin-bar #wpcontent, body.admin-bar #adminmenu { padding-top: 0px !important; }</style>';
}
add_filter('admin_head','remove_admin_bar_style_backend');
// css override for the frontend
function remove_admin_bar_style_frontend() {
echo '<style type="text/css" media="screen">
html { margin-top: 0px !important; }
* html body { margin-top: 0px !important; }
</style>';
}
add_filter('wp_head','remove_admin_bar_style_frontend', 99);
}
}
add_action('init','disable_admin_bar');
Disable Admin Bar for everyone but administrators:
// Disable Admin Bar for everyone but administrators
if (!function_exists('disable_admin_bar')) {
function disable_admin_bar() {
if (!current_user_can('manage_options')) {
// for the admin page
remove_action('admin_footer', 'wp_admin_bar_render', 1000);
// for the front-end
remove_action('wp_footer', 'wp_admin_bar_render', 1000);
// css override for the admin page
function remove_admin_bar_style_backend() {
echo '<style>body.admin-bar #wpcontent, body.admin-bar #adminmenu { padding-top: 0px !important; }</style>';
}
add_filter('admin_head','remove_admin_bar_style_backend');
// css override for the frontend
function remove_admin_bar_style_frontend() {
echo '<style type="text/css" media="screen">
html { margin-top: 0px !important; }
* html body { margin-top: 0px !important; }
</style>';
}
add_filter('wp_head','remove_admin_bar_style_frontend', 99);
}
}
}
add_action('init','disable_admin_bar');
Disable WP Admin Bar for specific users via user id:
// Disable Admin Bar for specific user
if (!function_exists('disable_admin_bar')) {
function disable_admin_bar() {
// we're getting current user ID
$user = get_current_user_id();
// and removeing admin bar for user with ID 123
if ($user == 123) {
// for the admin page
remove_action('admin_footer', 'wp_admin_bar_render', 1000);
// for the front-end
remove_action('wp_footer', 'wp_admin_bar_render', 1000);
// css override for the admin page
function remove_admin_bar_style_backend() {
echo '<style>body.admin-bar #wpcontent, body.admin-bar #adminmenu { padding-top: 0px !important; }</style>';
}
add_filter('admin_head','remove_admin_bar_style_backend');
// css override for the frontend
function remove_admin_bar_style_frontend() {
echo '<style type="text/css" media="screen">
html { margin-top: 0px !important; }
* html body { margin-top: 0px !important; }
</style>';
}
add_filter('wp_head','remove_admin_bar_style_frontend', 99);
}
}
}
add_action('init','disable_admin_bar');
Here is a 6 lines code nugget that will remove the admin bar for non contributor users :
add_action( 'init', 'fb_remove_admin_bar', 0 );
function fb_remove_admin_bar() {
if (!current_user_can('edit_posts')) { // you can change the test here depending on what you want
add_filter( 'show_admin_bar', '__return_false', PHP_INT_MAX );
}
}
Put that in your function.php file or in your custom plugin.
How do I hide/remove the admin bar that is displayed when a user with specific role is logged in? I figured I have to do something with remove_menu(), but not exactly what and how.
Codex
How do I hide/remove the admin bar that is displayed when a user with specific role is logged in? I figured I have to do something with remove_menu(), but not exactly what and how.
Codex
Share Improve this question edited Sep 22, 2013 at 17:28 Joren asked Sep 22, 2013 at 17:12 JorenJoren 3171 gold badge5 silver badges23 bronze badges 2- A simple googling can answer you. Why not you tried that first? :) – Mayeenul Islam Commented Sep 22, 2013 at 17:21
- 3 Agreed, this is easy to find. But, @Christine's answer is a quality summary. +1 for that... – Johannes P. Commented Sep 22, 2013 at 17:29
2 Answers
Reset to default 6Add the following to your functions.php file as detailed here.
Disable Admin Bar for everyone:
// Disable Admin Bar for everyone
if (!function_exists('disable_admin_bar')) {
function disable_admin_bar() {
// for the admin page
remove_action('admin_footer', 'wp_admin_bar_render', 1000);
// for the front-end
remove_action('wp_footer', 'wp_admin_bar_render', 1000);
// css override for the admin page
function remove_admin_bar_style_backend() {
echo '<style>body.admin-bar #wpcontent, body.admin-bar #adminmenu { padding-top: 0px !important; }</style>';
}
add_filter('admin_head','remove_admin_bar_style_backend');
// css override for the frontend
function remove_admin_bar_style_frontend() {
echo '<style type="text/css" media="screen">
html { margin-top: 0px !important; }
* html body { margin-top: 0px !important; }
</style>';
}
add_filter('wp_head','remove_admin_bar_style_frontend', 99);
}
}
add_action('init','disable_admin_bar');
Disable Admin Bar for everyone but administrators:
// Disable Admin Bar for everyone but administrators
if (!function_exists('disable_admin_bar')) {
function disable_admin_bar() {
if (!current_user_can('manage_options')) {
// for the admin page
remove_action('admin_footer', 'wp_admin_bar_render', 1000);
// for the front-end
remove_action('wp_footer', 'wp_admin_bar_render', 1000);
// css override for the admin page
function remove_admin_bar_style_backend() {
echo '<style>body.admin-bar #wpcontent, body.admin-bar #adminmenu { padding-top: 0px !important; }</style>';
}
add_filter('admin_head','remove_admin_bar_style_backend');
// css override for the frontend
function remove_admin_bar_style_frontend() {
echo '<style type="text/css" media="screen">
html { margin-top: 0px !important; }
* html body { margin-top: 0px !important; }
</style>';
}
add_filter('wp_head','remove_admin_bar_style_frontend', 99);
}
}
}
add_action('init','disable_admin_bar');
Disable WP Admin Bar for specific users via user id:
// Disable Admin Bar for specific user
if (!function_exists('disable_admin_bar')) {
function disable_admin_bar() {
// we're getting current user ID
$user = get_current_user_id();
// and removeing admin bar for user with ID 123
if ($user == 123) {
// for the admin page
remove_action('admin_footer', 'wp_admin_bar_render', 1000);
// for the front-end
remove_action('wp_footer', 'wp_admin_bar_render', 1000);
// css override for the admin page
function remove_admin_bar_style_backend() {
echo '<style>body.admin-bar #wpcontent, body.admin-bar #adminmenu { padding-top: 0px !important; }</style>';
}
add_filter('admin_head','remove_admin_bar_style_backend');
// css override for the frontend
function remove_admin_bar_style_frontend() {
echo '<style type="text/css" media="screen">
html { margin-top: 0px !important; }
* html body { margin-top: 0px !important; }
</style>';
}
add_filter('wp_head','remove_admin_bar_style_frontend', 99);
}
}
}
add_action('init','disable_admin_bar');
Here is a 6 lines code nugget that will remove the admin bar for non contributor users :
add_action( 'init', 'fb_remove_admin_bar', 0 );
function fb_remove_admin_bar() {
if (!current_user_can('edit_posts')) { // you can change the test here depending on what you want
add_filter( 'show_admin_bar', '__return_false', PHP_INT_MAX );
}
}
Put that in your function.php file or in your custom plugin.
本文标签: plugin developmentCompletely remove WPAdminBar for specific user roles
版权声明:本文标题:plugin development - Completely remove WP_Admin_Bar for specific user roles 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749081989a2313189.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论