latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Disable admin bar 4all except admin and lvl 1

Home Forums Community Forum Disable admin bar 4all except admin and lvl 1

This topic contains 7 replies, has 3 voices. Last updated by  Boris Uhlig 3 years, 5 months ago.

Topic Author Topic
Posted: Wednesday Dec 5th, 2012 at 6:14 pm #33629

Hello! Coding newbie here! So I’m only using levels 0 and 1 and I’d like to disable the admin bar for free users (basically for all except admins and lvl 1s).

I want to use the bar so users can easily navigate to the members only content on my website. I’ve been successful in disabling it for all except admins, but it’s not working for level 1s. Here’s what I’ve got:

/* Disable WordPress Admin Bar for all users but admins. */
if (!current_user_can('administrator','s2member_level1')):
  show_admin_bar(false);
endif;

What am doing wrong?
Thanks in advance!

List Of Topic Replies

Viewing 7 replies - 1 through 7 (of 7 total)
Author Replies
Author Replies
Posted: Wednesday Dec 5th, 2012 at 10:44 pm #33659
Eduan
Username: Eduan
Moderator

Could you try this instead?:

/* Disable WordPress Admin Bar for all users but admins and users s2Member level 1. */
if (!current_user_can('administrator','access_s2member_level1')):
  show_admin_bar(false);
endif;

If you prefer, or the above doesn’t work, you can use the following:

/* Disable WordPress Admin Bar for all users but admins and users s2Member level 1. */
if (!current_user_can('administrator') || !current_user_can('access_s2member_level1')):
  show_admin_bar(false);
endif;

Hope this helps. :)

Posted: Thursday Dec 6th, 2012 at 6:42 am #33683

Wow Eduan, I don’t think I’ve ever met a person as helpful and active on plugin forums as yourself. Thank you!
I had allready tried the first option. Unfortunately, neither of them work. :(

Posted: Thursday Dec 6th, 2012 at 10:23 pm #33836
Eduan
Username: Eduan
Moderator

That’s very strange, I don’t know what could cause it. You say this works flawlessly for admin users right?

– Eduan

Posted: Friday Dec 7th, 2012 at 5:21 am #33847

Yes.

Posted: Friday Dec 7th, 2012 at 8:48 pm #33947
Eduan
Username: Eduan
Moderator

Then I’m not sure what could be wrong. :/

You can check under Dashboard -› s2Member® -› API / Scripting -› Advanced PHP Conditionals and Dashboard -› s2Member® -› API / Scripting -› PHP/API Constants and see if you can figure out something better than what I came up with, since my idea was just a quick idea.

– Eduan

Posted: Saturday Jul 27th, 2013 at 5:58 pm #54247
Boris Uhlig
Username: buhlig

Well, this topic seems not solved yet, isn’t it? Even studied WP core, but couldn’t come up with a solution, despite by modifying the CSS of my (Child-) Theme (customs.css):

html { margin-top: 0px !important; }
* html body { margin-top: 0px !important; }
#wpadminbar { height: 0px; display: none; }

#top {margin-top: -28px !Important; }

As with my Theme (Canvas from Woo) the first object is #Top I had to redefine that, but in your theme it might be i.e. #wrapper!

However, would still love to see a solution to basically disable the admin, as this is more secure!

-Boris

Posted: Saturday Jul 27th, 2013 at 6:16 pm #54248
Boris Uhlig
Username: buhlig

Found a solution which is doing the trick better:

I introduced another option = custom_admin_bar_disable (boolean) and added a checkbox to my Themeoptions:

$custom_admin_bar_disable = get_option( ‘custom_admin_bar_disable’ );

if ( $custom_admin_bar_disable == ‘true’ ) {
add_filter( ‘show_admin_bar’, ‘__return_false’ );

add_action( ‘admin_print_scripts-profile.php’, ‘custom_hide_admin_bar_prefs’ );

function custom_hide_admin_bar_prefs () { ?>

.show-admin-bar { display: none; }

<?php
} // End custom_hide_admin_bar_prefs()
}

Hope it will work out for you as well as for my!
Cheers!

Viewing 7 replies - 1 through 7 (of 7 total)

This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.