[PRO SITES] hide menu item base on level

I would like to display a menu item in the dashboard according to the level in Pro Sites. Is this possible at all please?

For example: I would like for instance the Pages menu to be shown only if the Pro Site user was on a certain level.
I found this one:
https://gist.github.com/aristath/5566730
line 57 but not sure will this work with the current version of Pro Site and what will be correct code to hide pages.

  • Nithin
    • Support Wizard

    Hi chairleg,

    Hope you are doing good today. :slight_smile:

    I would like for instance the Pages menu to be shown only if the Pro Site user was on a certain level.
    I found this one:
    https://gist.github.com/aristath/5566730
    line 57 but not sure will this work with the current version of Pro Site and what will be correct code to hide pages.

    I gave a quick test, and the code works fine without any issue with the latest version of Pro Sites. However, the code applies even for the super admin too.

    If you don't want the changes to be hidden for super admin the following should help:

    <?php
    
    function wpmudev_hide_on_level() {
    
      global $wpdb;
      $blog_id = $wpdb->blogid;
      $sql = "SELECT level FROM {$wpdb->base_prefix}pro_sites WHERE blog_ID = '$blog_id'";
      $level = $wpdb->get_var($sql);
    
      if ($level == 3 && !is_super_admin() ){
        echo '<style>#menu-pages {
        	display: none;
        }</style>';
      }
    }
    add_action('admin_head', 'wpmudev_hide_on_level');

    Please check, and see whether it helps. You can implement the code as a mu-plugins as mentioned in here:
    https://premium.wpmudev.org/manuals/wpmu-manual-2/using-mu-plugins/

    If you still have further query, please do enable support access to your website, and also point out which exact menus, and for which Pro site levels in your website dashboard are you looking to hide or display.

    You can grant access from WPMU DEV > Support > Support Access > Grant Access, or check this manual: https://premium.wpmudev.org/docs/getting-started/getting-support/#chapter-5

    Please let us know once you enable access so that we could get this sorted. Have a nice day. :slight_smile:

    Kind Regards,
    Nithin

  • chairleg
    • Site Builder, Child of Zeus

    Nithin

    Thank you for coming back to me so quickly.

    I would like the menu items to be displayed as follows

    Survey Questions (hidden at Level 1, displayed at Level 2)
    Match Settings (hidden at Level 1, displayed at Level 2)
    Top Matches Pro (hidden at Level 1, displayed at Level 2)
    Top Matches (hidden at Level 2, displayed at Level 1)

    at

    https://pairingpeople.com/pairingpeopleplatform/wp-admin/

    Would you be able to give me the code at all?

    Thank you very much
    Marc

  • Ash
    • WordPress Hacker

    Hello chairleg

    To make the code for those specific menus, I need to see the items from the admin panel.

    Please sent me following details:
    1. Site admin URL (I get this: https://pairingpeople.com/pairingpeopleplatform/wp-admin/ ? )
    2. Site super admin username and password
    3. A test site URL (or I can create one for testing)
    4. FTP host, username, password, port and path

    Please send me privately in the following format:
    1. Please go to https://premium.wpmudev.org/contact/#i-have-a-different-question
    2. Select "I have a different question" if not selected
    3. In subject line put "Attn-Ashok" (this will ensure that the email is assigned to me)
    4. Provide the wanted details.
    5. Add the thread link in the message so that I can track.

    Have a nice day!

    Cheers,
    Ash

  • Ash
    • WordPress Hacker

    Hello chairleg

    Please check now. Currently, used code is below:

    add_action( 'admin_init', function() {
        global $psts;
    
        if( $psts->get_level() == 1 ) {
            ?>
            <style>
                #adminmenu li:nth-child(3),
                #adminmenu li:nth-child(4),
                #adminmenu li:nth-child(5),
                #adminmenu li:nth-child(8) {
                    display: none !important;
                }
            </style>
            <?php
        }else if( $psts->get_level() == 2 ) {
            ?>
            <style>
                #adminmenu li:nth-child(7) {
                    display: none !important;
                }
            </style>
            <?php
        }
    
    }, 999 );

    Hope it helps! Please feel free to more question if you have any regarding this.

    Cheers,
    Ash

  • chairleg
    • Site Builder, Child of Zeus

    Ash

    I signed up for a Free site from http://www.pairingpeople.com and

    Survey Questions
    Match Settings
    Top Matches Pro
    Top Matches

    were all shown

    Survey Questions
    Match Settings
    Top Matches Pro

    should not be there

    When I went i as admin and upgrade to a Pro site the options were correct

    Survey Questions
    Match Settings
    Top Matches Pro

    Top Matches had gone :slight_smile:

    Please can you check the free level again?

    Thank you for your time
    Marc

  • Ash
    • WordPress Hacker

    Hello chairleg

    When you say free level, I thought you meant about FREE level you created. But now I think, you meant the sites which is not under any pro level, right?

    If so, please try the following code:

    <?php
    
    add_action( 'admin_init', function() {
        global $psts;
    
        if( $psts->get_level() == 2 ) {
            ?>
            <style>
                #adminmenu li:nth-child(7) {
                    display: none !important;
                }
            </style>
            <?php
        }
        else {
            ?>
            <style>
                #adminmenu li:nth-child(3),
                #adminmenu li:nth-child(4),
                #adminmenu li:nth-child(5),
                #adminmenu li:nth-child(8) {
                    display: none !important;
                }
            </style>
            <?php
        }
    
    }, 999 );

    Please go to /public_html/wp-content/mu-plugins/mu.php, open the file and replace everything with the above code. I tried to do that but in filezilla I am getting the following error:

    Status:      	Starting upload of /Users/bappi/Desktop/Chalan/mu.php
    Status:      	Skipping upload of /Users/bappi/Desktop/Chalan/mu.php
    Status:      	File transfer skipped

    So, I could not proceed.

    Please update the code and let us know if it works.

    Have a nice day!

    Cheers,
    Ash

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.