正在删除管理后端顶部栏上的wp管理菜单项

时间:2020-01-31 作者:Jessica217

我已成功删除用户角色“编辑器”不需要的菜单项。现在,我在顶部栏上留下了一个项目,使编辑器添加新的帖子页面和其他我需要隐藏的项目。请检查屏幕截图,因为我指出这是什么项目。显示了此页面的链接,我尝试了,但它不想消失。

How to remove top menu item - admin backend wp

我使用了以下代码:

/** remove editor dashboard menu */ define( \'DISALLOW_FILE_EDIT\', true);

function remove_menus(){

remove_menu_page( \'upload.php\' ); //Media
remove_menu_page( \'edit.php?post_type=page\' ); //Pages
remove_menu_page( \'themes.php\' ); //Appearance
remove_menu_page( \'post.php\' ); //Remove +New
remove_menu_page( \'post-new.php\' ); //Remove +New 
remove_submenu_page( \'post-new.php\' ); //Edit Page
remove_menu_page( \'edit.php?post_type=client\' ); //Clients
remove_menu_page( \'edit.php?post_type=offer\' ); //Offers
remove_menu_page( \'edit.php?post_type=portfolio\' ); //Portfolio
remove_menu_page( \'edit.php?post_type=slide\' ); //Slides
remove_menu_page( \'edit.php?post_type=testimonial\' ); //Testimonials
remove_menu_page( \'edit.php?post_type=layout\' ); //Layouts
remove_menu_page( \'edit.php?post_type=template\' ); //Templates
remove_menu_page( \'wpcf7\' ); //Contacts
remove_menu_page( \'tools.php\' ); //Tools
remove_menu_page( \'vc-welcome\' ); //Visual Composer
remove_menu_page( \'options-general.php\' ); //Settings remove_menu_page( 
\'wpcf7\' ); //contact form

} if(current_user_can( \'editor\' )){ add_action( \'admin_menu\', \'remove_menus\' ); }
所以我尝试使用:

remove_menu_page( \'post-new.php\' ); //Remove +New 
remove_submenu_page( \'post-new.php\' ); //Edit Page
但它不起作用。如何删除此菜单项及其所有子菜单?

1 个回复
SO网友:Vitauts Stočka

Use this example

function my_admin_bar_render() {
    $user = wp_get_current_user();

    if ( in_array( \'editor\', (array) $user->roles ) ) {
        global $wp_admin_bar;
        $wp_admin_bar->remove_menu(\'new-content\');
    }
}
add_action( \'wp_before_admin_bar_render\', \'my_admin_bar_render\' );

相关推荐

使用force_ssl_admin强制使用SSL

我跟着this advice 从官方文件中强制SSL:define(\'FORCE_SSL_ADMIN\', true); if (strpos($_SERVER[\'HTTP_X_FORWARDED_PROTO\'], \'https\') !== false) $_SERVER[\'HTTPS\']=\'on\'; Wordpress在docker容器中运行。当它开始时,它说警告:未设置\\u服务器变量。默认为空字符串。Wordpress的日志显示:PHP致命错误:赋值只能发生