Skip to content

Instantly share code, notes, and snippets.

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 rniswonger/36a13b9218181bc5ccc5e348dcfcdfb0 to your computer and use it in GitHub Desktop.
Save rniswonger/36a13b9218181bc5ccc5e348dcfcdfb0 to your computer and use it in GitHub Desktop.
WordPress: Change admin color scheme based on environment and user. Because I got tired of doing it manually when I re-cloned my local/staging db.
/**
* Change admin color scheme for specific users based on the environment type. Overrides user selection.
* Color scheme options: fresh, light, modern, blue, midnight, sunrise, ectoplasm, ocean, coffee
*/
add_filter(
'admin_init',
function () {
$user_ids = array( 1 ); // Array of user IDs
$current_user_id = get_current_user_id();
$environment_colors = array(
'local' => 'sunrise',
'staging' => 'ectoplasm',
'development' => 'ocean',
'production' => 'fresh',
);
$environment_type = wp_get_environment_type();
// set the color scheme
if ( in_array( $current_user_id, $user_ids, true ) ) :
if ( array_key_exists( $environment_type, $environment_colors ) ) :
$color = $environment_colors[ $environment_type ];
update_user_option( $current_user_id, 'admin_color', $color );
endif;
endif;
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment