Set the WordPress admin colour scheme for different users and roles
Now, under no circumstances should this lovely new feature (3.8) be taken away from users and really this is just for fun however! It could be useful in the real world if you want to give your users some kind of visual representation of their role once they have logged in to a website.
So without any further ado this is how to set the WordPress admin colour scheme for different users and roles:
// note it is a very sad thing to remove these // color options but useful for roles function change_admin_color () { $users = get_users(); foreach ($users as $user) { if (user_can( $user->ID, 'administrator' )) { // Editor and below update_user_meta($user->ID, 'admin_color', 'coffee'); } if (user_can( $user->ID, 'editor' )) { // Editor and below update_user_meta($user->ID, 'admin_color', 'sunrise'); } if (user_can( $user->ID, 'author' )) { // Author update_user_meta($user->ID, 'admin_color', 'ocean'); } if (user_can( $user->ID, 'contributor' )) { // Contributor and below update_user_meta($user->ID, 'admin_color', 'light'); } if (user_can( $user->ID, 'subscriber' )) { // Subscriber and below update_user_meta($user->ID, 'admin_color', 'ectoplasm'); } } if (!current_user_can('manage_options')) { remove_action('admin_color_scheme_picker','admin_color_scheme_picker'); } } add_action('after_setup_theme','change_admin_color');
Again this is really for fun but I hope you can see how useful this might be in the real world 🙂
It is completely beyond me why you use a function that has been deprecated since WordPress 2.0 (?!) to enhance a site running on WordPress 3.8!
Instead of
user_level
you should obviously use Roles/Capabilities as inuser_can( $user, $capability )
orcurrent_user_can( $capability, $args )
.You are absolutely right Piet! Thanks for pointing that out – now amended.
cool, thanks for the quick follow-up/through 🙂
Great idea – Is there somewhere I can find a list of wordpress admin colour schemes? Or does this snippet just apply a CSS class across the board allowing me to create my own styles?
Out of the box there are eight colours to choose from under Dashboard > Users – there is also the Admin Color Schemes plugin that add’s an additional eight new colors. The backbone of the color schemes is just a handful of variables included in its scss file, defining the base, highlight, notification and action colors. You need to compile your own scss file into a corresponding CSS file to make it work though.
Sounds like something to try out on an in-house project! cheers
..Oh.. and Merry Christmas 🙂
Same to you to Paul 🙂