Hiding WP panel with Pro Sites.

So I am trying to customize my WP menu for Pro Site users so that they only see a couple of tabs – preferably the Appointments+ Tab and the Users tab (for now – I may add more later). Is there a way to limit the tabs that are seen by Pro Site users? Since this is run on WPMS and my website, http://www.booklyonline.com, is on the network I find that if I limit anything it will also limit what I see on my dashboard – and I need to see everything.

Would I be better off using a domain that is not on the MS network to create as the platform where people sign up for the service? Not sure if that is even possible. I hope that this question makes sense, if not please let me know and I can explain further.

  • Ash
    • Code Norris

    Hello @Michael

    Welcome to WPMU community!

    I hope you are well today and thanks for asking the question.

    Let me show you some code and add it in mu-plugins folder. You can add those codes in your functions.php in the theme, if you think your theme won’t be changed. Otherwise mu-plugins is the best solution. To use mu-plugins, go to /wp-content/ and find the folder with name ‘mu-plugins’. If there is no folder in that name, then create a folder, name it ‘mu-plugins’, create a file inside that, give any name you like and paste the code in their. You don’t need to activate that plugin. Mu-plugins means must use plugins, so it will be activated automatically always.

    function my_remove_menu() {
    if(is_pro_site($blog_id, $level)) {
    remove_menu_page('tools.php');
    remove_menu_page('import.php');
    remove_menu_page('export.php');
    remove_menu_page('ms-delete-site.php');
    }
    }
    add_action( 'admin_init', 'my_remove_menu' );

    function no_permission_admin_redirect() {
    if(is_pro_site($blog_id, $level)) {
    if (stripos($_SERVER['REQUEST_URI'],'tools.php') !== false
    || stripos($_SERVER['REQUEST_URI'],'import.php') !== false
    || stripos($_SERVER['REQUEST_URI'],'export.php') !== false
    || stripos($_SERVER['REQUEST_URI'],'ms-delete-site.php') !== false) {
    wp_redirect(get_option('siteurl') . '/wp-admin/index.php?permissions_error=true');
    }
    }
    }
    add_action('admin_menu','no_permission_admin_redirect');

    function no_permissions_admin_notice() {
    echo "<div id='permissions-warning' class='error fade'><p><strong>".__('You do not have permission to access that page.')."</strong></p></div>";
    }

    function no_permissions_show_notice() {
    if(isset($_GET['permissions_error']) && $_GET['permissions_error']) {
    add_action('admin_notices', 'no_permissions_admin_notice');
    }
    }
    add_action('admin_init','no_permissions_show_notice');

    Here $blog_id is the current blog id, you can use get_current_blog_id() instead. And $level is Pro Level ID, that is 1 or 2 or 3 and so on…

    In the above example, I have made the tools and it’s submenu hidden. You can follow this to hide other menus.

    Please let me know if you find this is helpful, or if you have any further questions.

    Cheers

    Ash

  • Ash
    • Code Norris

    Hey there

    You have to use remove_menu_page('tools.php'); for all of the items you need to remove. So, if you just need to remove plugins.php, then you don’t need to use code for tools.php, just replace :slight_smile:

    Also you need to update here to show an error message:

    stripos($_SERVER['REQUEST_URI'],'plugins.php') !== false

    Hope it helps! Please feel free to ask more question if you have.

    Cheers

    Ash

  • Michael
    • WPMU DEV Initiate

    Ashok,

    Thank you that is working for me. I am having an issue with a couple of items. When I try to remove ‘upload.php’ it actually adds menu items back to the WP Admin panel. I am not sure if there is a conflict that is causing this.

    Also, I was trying to hide the ‘widgets.php’ and well as ‘customize.php’ under the appearance tab, however it would not hide them properly.

    Thank you.

  • Michael
    • WPMU DEV Initiate

    When I log into my Network account, as well as the MAIN account on booklyonline.com, I notice that some of the menu bars are also hidden for me. Am I missing something or is there a way to make sure my accounts do not get blocked?

  • Ash
    • Code Norris

    To remove media menu I used:

    remove_menu_page('upload.php');

    And it worked fine for me. See screenshot, no media-menu.

    To remove widget and customize from menu:

    remove_submenu_page('themes.php', 'widgets.php');
    remove_submenu_page('themes.php', 'customize.php');

    I notice that some of the menu bars are also hidden for me

    The code is based on site and it’s pro level. So, for that you can try the condition like this:

    if(is_pro_site($blog_id, $level) && !is_super_admin()) {

    Let me know if it works for you.

    Cheers

    Ash

  • Michael
    • WPMU DEV Initiate

    Ashok,

    Thank you…it did work. Where would this code go:

    if(is_pro_site($blog_id, $level) && !is_super_admin()) {

    Because I do not want anything hid from super admin or from my main account on BooklyOnline.com. I am assuming that the my account level on booklyonline.com is not super admin, but a regular user since it is part of the network. Kind of confused there.

    Thanks again!

  • Ash
    • Code Norris

    Hi there

    If you use this code:

    if(is_pro_site($blog_id, $level)) {

    Then it will hide the menus from all users in that site.

    But if you use this:

    if(is_pro_site($blog_id, $level) && !is_super_admin()) {

    Then it will hide the menus from all users except super admin. So, super admin should be able to view those menus :slight_smile:

    Cheers

    Ash