Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WordPress: set default admin color scheme and get current or all admin color schemes.
<?php
/**
* Set the default admin color scheme for WordPress user.
*/
add_filter('get_user_option_admin_color', 'set_default_admin_color');
function set_default_admin_color($result)
{
// set new default admin color scheme
$result = 'midnight';
// return the new default color
return $result;
}
/**
* Get the current admin color scheme from WordPress user.
*/
add_filter('get_user_option_admin_color', 'get_current_admin_color');
function get_current_admin_color($result)
{
global $_wp_admin_css_colors;
// get current admin color scheme name
$current_color_scheme = $result;
// get all available colors from scheme name
$colors = $_wp_admin_css_colors[$current_color_scheme];
// now you can use this colors or store it
// var_dump($colors);
// important: we should return the default color scheme
return $result;
}
/**
* Get all available admin colors schemes from WordPress user.
*/
add_filter('get_user_option_admin_color', 'get_all_admin_colors');
function get_all_admin_colors($result)
{
global $_wp_admin_css_colors;
// get all available color schemes
$colors = $_wp_admin_css_colors;
// now you can use this color schemes or store it
// var_dump($colors);
// important: we should return the default color scheme
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment