7

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.

3 Answers 3

14
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.

8
  • 5
    why don't use update_user_meta() function? Like so: update_user_meta( $user_id, 'show_admin_bar_front', 'false' );
    – Mamaduka
    Commented Sep 23, 2011 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
    Commented Sep 23, 2011 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.
    – Scott
    Commented Sep 23, 2011 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 Commented Sep 23, 2011 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...
    – Scott
    Commented Sep 26, 2011 at 11:16
2
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' );
8
  • I thought that was the code to get rid of it altogether ? Commented Sep 22, 2011 at 16:03
  • Please see update ...
    – kaiser
    Commented Sep 22, 2011 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. Commented Sep 22, 2011 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
    Commented Sep 22, 2011 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
    – Scott
    Commented Sep 22, 2011 at 16:55
-1

This finally works:

wp_update_user( array ( 'ID' => $user_id, 'show_admin_bar_front' => 'false' ) ) ;
1
  • How/What does this add to the existing solutions?
    – tfrommen
    Commented Nov 5, 2013 at 11:35

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