我有一个会员网站。我需要禁用订阅者的管理栏。
我在下面使用了以下代码:
add_action('after_setup_theme', 'remove_admin_bar');
function remove_admin_bar() {
if (!current_user_can('administrator') && !is_admin()) {
  show_admin_bar(false);
}
}它从订阅服务器的前端移除管理栏,但是当它们转到它们的配置文件页面wp/profile.php时,管理栏仍然显示在那里。
我正在使用付费会员专业插件,我认为这使得代码不能在后台为订户工作。
此外,我还使用这段代码从任何地方删除管理栏:
if (!function_exists('disableAdminBar')) {
    function disableAdminBar(){
    remove_action( 'admin_footer', 'wp_admin_bar_render', 1000 );
    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');
  }
}
add_filter('admin_head','remove_admin_bar_style_backend');但是这个代码也不起作用。
我只想从前端和后端页面中删除订阅者的管理栏。
我遗漏了什么特定的代码吗?我正在使用付费会员专业。
谢谢你的帮助。
发布于 2018-09-12 14:01:43
我对此做了快速的研究,我不认为您可以使用函数,就像法典中所说的那样。
注意:在查看管理屏幕时,不再可能隐藏工具栏,但用户可以在其配置文件屏幕的站点前端禁用工具栏。
在前端禁用的结果与您已经做过的一样。
我建议用css来隐藏它。
#wpadminbar {
    display: none;
}
html {
    padding-top: 0; // Move up the page's content by the bar's height
}发布于 2019-07-22 13:26:20
若要向非管理员用户隐藏管理栏,请将以下代码添加到functions.php文件中
// show admin bar only for admins
if (!current_user_can('manage_options')) {
    add_filter('show_admin_bar', '__return_false');
}
// show admin bar only for admins and editors
if (!current_user_can('edit_posts')) {
    add_filter('show_admin_bar', '__return_false');
}发布于 2018-11-22 00:16:17
PMPro团队为此制作了一个插件:https://wordpress.org/plugins/hide-admin-bar-from-non-admins/
其中包括完全隐藏管理栏:https://plugins.svn.wordpress.org/hide-admin-bar-from-non-admins/trunk/hide-admin-bar-from-non-admins.php所需的PHP和CSS代码。
function habfna_hide_admin_bar_settings()
{
?>
    <style type="text/css">
        .show-admin-bar {
            display: none;
        }
    </style>
<?php
}
function habfna_disable_admin_bar()
{
    if(!current_user_can('administrator'))
    {
        add_filter( 'show_admin_bar', '__return_false' );
        add_action( 'admin_print_scripts-profile.php', 'habfna_hide_admin_bar_settings' );
    }
}
add_action('init', 'habfna_disable_admin_bar', 9);https://wordpress.stackexchange.com/questions/313993
复制相似问题