Last active
July 21, 2023 17:45
-
-
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.
This file contains 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
/** | |
* 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