Skip to content

Instantly share code, notes, and snippets.

@ScottDeLuzio
Created May 10, 2021 22:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ScottDeLuzio/dfdcf91a9ac3386b92c10d5a09684873 to your computer and use it in GitHub Desktop.
Save ScottDeLuzio/dfdcf91a9ac3386b92c10d5a09684873 to your computer and use it in GitHub Desktop.
Switch the Admin Color Scheme for a user on various multisite subsites
/**
* Force Admin Color Scheme on admin pages for a user account based on the site we're on.
* Valid admin_color values include:
* - fresh (Default)
* - light
* - modern
* - blue
* - coffee
* - ectoplasm
* - midnight
* - ocean
* - sunrise
*/
add_action( 'admin_init', 'update_admin_color_scheme' );
function update_admin_color_scheme() {
$current_site = get_current_blog_id();
$current_user = get_current_user_id();
if ( 2 == $current_user ) { // this is the user ID we want to change the admin color scheme for
switch ( $current_site ) {
// first site to change the color scheme for
case '16':
$color = array( 'ID' => $current_user, 'admin_color' => 'blue' );
break;
// second site to change the color scheme for
case '14':
$color = array( 'ID' => $current_user, 'admin_color' => 'coffee' );
break;
// All other sites.
default:
$color = array( 'ID' => $current_user, 'admin_color' => 'fresh' );
break;
}
}
wp_update_user( $color );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment