While I quite like the admin bar I actually want it to be OFF by default instead of ON ( I don't want to disable it altogether because I want users to be able to turn it on if they want - but but I don't want to have to manually turn it off for every user ) Is there a way to implement this.

link|improve this question

feedback

2 Answers

up vote 4 down vote accepted
add_action("user_register", "set_user_admin_bar_false_by_default", 10, 1);
function set_user_admin_bar_false_by_default($user_id) {
    update_user_meta( $user_id, 'show_admin_bar_front', 'false' );
    update_user_meta( $user_id, 'show_admin_bar_admin', 'false' );
}

Place in theme functions file or you can make into a plugin.

Once user registers it will go and set the users admin bar prefs to false. The user can then, once logged in, set this to true.

link|improve this answer
3  
why don't use update_user_meta() function? Like so: update_user_meta( $user_id, 'show_admin_bar_front', 'false' ); – Mamaduka Sep 23 '11 at 12:55
2  
double that. +1 for @Brady Should work seamless, even when nicer with Mamadukas addition. Btw: This one should become a WPSE plugin ;) – kaiser Sep 23 '11 at 12:59
Yup you are absolutely right. I was in a hurry to post and didn't research alternate methods. Ill update answer to use this instead. – Brady Sep 23 '11 at 13:02
sounds like it will work and be an interesting bit of code - thanks - i cant try it out till monday though.... edit ... blimey never heard of WPSE plugins before , what a resource will have to have a good look – byronyasgur Sep 23 '11 at 17:00
1  
wordpress.org/extend/plugins/admin-bar-default-off can now get this as a plugin. Nice to see someone has already down voted my plugin, beyond me why... – Brady Sep 26 '11 at 11:16
show 2 more comments
feedback
function wpse29210_admin_bar_toogle()
{
    add_filter( 'show_admin_bar', '__return_false' );

    $user = get_userdata( $GLOBALS['current_user'] )->data->ID;

    if ( ! is_admin() && $user->show_admin_bar_front )
        add_filter( 'show_admin_bar', '__return_true' );

    if ( is_admin() && $user->show_admin_bar_admin )
        add_filter( 'show_admin_bar', '__return_true' );

    return;
}
add_action( 'init', 'wpse29210_admin_bar_toogle' );
link|improve this answer
I thought that was the code to get rid of it altogether ? – byronyasgur Sep 22 '11 at 16:03
Please see update ... – kaiser Sep 22 '11 at 16:09
Thanks for your help but I'm not sure what that code is meant to do. What I want is for wordpress to have "Show Admin Bar when viewing site" unchecked by default when a new user is setup. – byronyasgur Sep 22 '11 at 16:20
It's meant to disable the admin bar per default. If a user saves his profile with one of the two fields checked, then the admin bar is shown. I'm sorry, but I guess you won't be able to uncheck per default unless you add some js to the admin_head to disable it. – kaiser Sep 22 '11 at 16:47
1  
Maybe you can hook into the account creation process and set show_admin_bar_front and show_admin_bar_admin to false? Just an idea – Brady Sep 22 '11 at 16:55
show 3 more comments
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.