Created
May 10, 2021 22:38
-
-
Save ScottDeLuzio/dfdcf91a9ac3386b92c10d5a09684873 to your computer and use it in GitHub Desktop.
Switch the Admin Color Scheme for a user on various multisite subsites
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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