Admin Color Scheme per User Role
Gives each role its own admin color scheme, for example blue for editors and coffee for shop managers, so people instantly see which kind of account they are using.
Opens WPIDE on
Code
// Role => admin color scheme.
$wpide_role_colors = array(
'administrator' => 'midnight',
'editor' => 'blue',
'author' => 'ocean',
'shop_manager' => 'coffee',
);
add_filter( 'get_user_option_admin_color', function ( $color, $option, $user ) use ( $wpide_role_colors ) {
if ( ! $user instanceof WP_User ) {
return $color;
}
foreach ( (array) $user->roles as $role ) {
if ( isset( $wpide_role_colors[ $role ] ) ) {
return $wpide_role_colors[ $role ];
}
}
return $color;
}, 10, 3 );
Notes
Roles not listed keep each user's own choice; scheme names: fresh, light, modern, blue, coffee, ectoplasm, midnight, ocean, sunrise.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.