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 :)

About

A geek who likes to cook with wp ingredients!

8 thoughts on “Set the WordPress admin colour scheme for different users and roles

  1. 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 in user_can( $user, $capability ) or current_user_can( $capability, $args ) .

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

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>