Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question

3 Answers 3

up vote 9 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.

share|improve this answer
4  
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
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' );
share|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

This finally works:

wp_update_user( array ( 'ID' => $user_id, 'show_admin_bar_front' => 'false' ) ) ;
share|improve this answer
    
How/What does this add to the existing solutions? –  t f Nov 5 '13 at 11:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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