隐藏wordpress后台菜单

        wordpress非管理员用户隐藏自定义帖子类型菜单项:

function wpse28782_remove_menu_items() {
    if( !current_user_can( 'administrator' ) ):
        remove_menu_page( 'edit.php?post_type=your_post_type' );
    endif;
}
add_action( 'admin_menu', 'wpse28782_remove_menu_items' );

        删除其他菜单页面:

remove_menu_page('edit.php'); // Posts
remove_menu_page('upload.php'); // Media
remove_menu_page('link-manager.php'); // Links
remove_menu_page('edit-comments.php'); // Comments
remove_menu_page('edit.php?post_type=page'); // Pages
remove_menu_page('plugins.php'); // Plugins
remove_menu_page('themes.php'); // Appearance
remove_menu_page('users.php'); // Users
remove_menu_page('tools.php'); // Tools
remove_menu_page('options-general.php'); // Settings

        删除插件菜单项:

function wpse28782_remove_plugin_admin_menu() {
    if( !current_user_can( 'administrator' ) ):
        remove_menu_page('cart66_admin');
    endif;
}
add_action( 'admin_menu', 'wpse28782_remove_plugin_admin_menu', 9999 );

        如果要隐藏该插件的菜单名称:

function wpse_28782_remove_menus() {
    remove_menu_page('cptui_main_menu');
}
add_action('admin_init', 'wpse_28782_remove_menus');
© 版权声明
THE END
喜欢就支持一下吧
点赞7 分享