Need hide admin bar for current_user_can...

I want to hide the admin bar for all users who have not paid for our membership. We are able to hide the Main Menu visibility with this: current_user_can('memberpress_product_authorized_9106')

But now need to hide the admin bar from all partial registered until they have paid for subscription. The Membership software I have is allowing registration before payment which allows people to end the registration process and access parts of the site. I need the admin bar hidden until they are full members.

Can someone help me using the information above?

  • Milan
    • WordPress Wizard

    Hello @paulthinkgrow,

    I hope you are well today and thanks for asking us. :slight_smile:

    It seems to me that you are using a Memberpress plugin which is third party paid product. Dear member I want to inform you that we are not covering support for third party products. So its my recommendation to you is that you ask for your this requirement to their support staff. I am pretty sure they will give you better solution as they are completely aware about their product.

    But if you have already asked them and they are not able to derive solution for you, please send me in your ftp and wp credentials via our secure contact form.

    Send in:

    Subject: "Attn: Milan Savaliya"
    -WordPress admin username
    -WordPress admin password
    -login url
    -FTP credentials (host/username/password)
    -link back to this thread for reference
    -any other relevant urls

    Select "I have a different question" for your topic - this and the subject line ensures that it gets assigned to me

    https://premium.wpmudev.org/contact/

    Look forward to hearing back. :slight_smile:

    Cheers,
    Milan

  • Adam Czajczyk
    • Support Gorilla

    Hello Paul,

    I hope you're well today!

    Actually, I think that the code you proposed should work (I'm assuming that the 'memberpress_product_authorized_9106' is a proper capability to check). The issue though is that it will only work for front-end as WordPress does't allow you to hide admin bar which is now called Toolbar) from dashboard anymore.

    Therefore, in case you'd like to hide admin toolbar from both front- and back-end you could give this code a try:

    if (!current_user_can('memberpress_product_authorized_9106')) {
    //hide admin toolbar from front-end
    add_filter('show_admin_bar', '__return_false');
    //hide admin toolbar from dashboard
    add_action('admin_head', 'wpmu_hide_dashboard_toolbar');
    function wpmu_hide_dashboard_toolbar() {
    	echo '<style>
    		#wpadminbar {display:none;}
    	</style>';
    }
    }

    I hope that helps :slight_smile:

    Best regards,
    Adam

  • Dimitris
    • Support Star

    Hi there Paul, hope you're doing well! :slight_smile:

    Any help if I want to add a second authorisation to this?

    Do you mean a second conditional? You can always combine them inside the if statement like:

    if ( !current_user_can('memberpress_product_authorized_9106') || !current_user_can('memberpress_product_authorized_9809') ) {
    //hide admin toolbar from front-end
    add_filter('show_admin_bar', '__return_false');
    //hide admin toolbar from dashboard
    add_action('admin_head', 'wpmu_hide_dashboard_toolbar');
    function wpmu_hide_dashboard_toolbar() {
    	echo '<style>
    		#wpadminbar {display:none;}
    	</style>';
    }
    }

    Please notice the OR statement ( || ) which can be changed to AND ( replace || with && ).

    Hope that helps,
    Dimitris

  • Paul
    • The Crimson Coder

    If I'm currently using this code:

    // show admin bar only for admins and subscribers
    if (!current_user_can('memberpress_product_authorized_9106')) {
    add_filter('show_admin_bar', '__return_false');
    }

    But looks like the code you provided with the && works perfectly.

    Thank you!

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.