Membership 2 - Hide Test Memberships button from Lesser Logins?

On this screen capture: http://gyazo.com/5659f540516a4d333c8c837fe237bb70, in the administrative bar, see the blue "Test Memberships" button? Well, on another support question, a Staff member said that that button, regardless of whether or not I'm in live mode or test mode or what not, should never show up for a user type that is less than Admin level. What you're looking at here is Contributor level. I do not want that button showing up for any login but Admin. How do I achieve this?

Also, If I see that button, then it means M2 is not "live"? Because most of the settings I have set up appear to be functioning without that being depressed. When I depress it, most of everything disappears for the Super Admin account and still doesn't look right for other levels. I guess I'm having setup issues lol. Please help.

  • Aicee Taguilaso

    Hi @Tracy Renee! :slight_smile:

    Yes, that is true, Test Memberships button will not show up to non-admin users. I also tested this on my site with a user with Contributor role, and I'm not seeing the button. But yes, I can confirm the issue on your site.

    Could you please try create an mu-plugin with this code, name the plugin to whatever you want, and put it inside your /wp-content/mu-plugins folder, if you haven't had one, just create that folder (mu-plugins):

    <?php
    add_action( 'admin_head', 'hide_test_memberships_to_all_but_admin_users', 1 );
    function hide_test_memberships_to_all_but_admin_users() {
    
        if (!current_user_can('update_core')) {
            ?>
            <style>
                li#wp-admin-bar-ms-test-memberships {
    	    	display: none;
    	}
            </style>
            <?php
        }
    }

    Let me know if that would work for you! :slight_smile:

    Cheers,
    Aicee

  • Ash

    Hello @Tracy Renee

    Please try the following:

    <?php
    add_action( 'admin_head', 'hide_test_memberships_to_all_but_admin_users', 1 );
    add_action( 'wp_head', 'hide_test_memberships_to_all_but_admin_users', 1 );
    function hide_test_memberships_to_all_but_admin_users() {
    
        if (!current_user_can('update_core')) {
            ?>
            <style>
                li#wp-admin-bar-ms-test-memberships {
    	    	display: none;
    	}
            </style>
            <?php
        }
    }

    Hope it helps :slight_smile: Please feel free to ask more question if you have any.

    Cheers
    Ash

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.