How to change admin bar color scheme in MP6 / WP 3.8 front end?

I need to change default color scheme for all users.
The admin bar on my site is vidibile for all users including guests.
The default black color scheme isn’t beauty with my design and I would like to change it with cofee scheme. Is there any way to do this?

I already found

Read More
add_filter('get_user_option_admin_color','change_admin_color');
function change_admin_color($result) {
   return 'coffee';
}

But it disable feature to choose another color scheme for users.
And first of all it work only for logged in users.

Related posts

3 comments

  1. At the moment (3.8) color schemes do not apply to admin bar at front end at all, even if user is logged in and has non-default scheme selected.

    The shortest way would probably be to force enqueue color scheme at front end:

    add_action(
        'wp_enqueue_scripts',
        function () {
            wp_enqueue_style(
                'color-admin-bar',
                admin_url( '/css/colors/coffee/colors.min.css' ),
                array( 'admin-bar' )
            );
        } );
    

    Note that core chose not to do it, so it is untested and there is risk of style incompatibilities and such.

  2. You can setup a theme on profile update, and if it present return that from the function hooking get_user_option_admin_color otherwise return the default:

    add_action('profile_update', function($user_id) {
      // on profile update save the unfiltered color choice in an additional meta
      $set = get_user_meta('admin_color', $user_id, true) ? : 'coffee';
      update_user_meta($user_id, '_setted_admin_color', $set);
    });
    
    add_filter('get_user_option_admin_color','change_admin_color');
    
    function change_admin_color($result) {
       $color = 'coffee';
       if ( is_user_logged_in() ) { // for nono logged user output default
          // get the unfiltered color meta
          $setted = get_user_meta( get_current_user_id(), '_setted_admin_color', true );
          // if present set color to that
          if ( ! empty($setted) ) $color = $setted;
       }
       return $color;
    }
    

    Code require PHP 5.3. Untested.

Comments are closed.