Get specific color from admin color scheme

Color schemes are registered globally within $_wp_admin_css_colors (see wp-includes/general-template.php for reference).

You can return the colors for the current user depending on get_user_meta() for a specific settings page like this:

global $pagenow;
if ( $pagenow == 'options-permalink.php' ) :
  add_action( 'admin_notices', 'get_current_user_admin_color' );
  function get_current_user_admin_color() {
    global $_wp_admin_css_colors;
    $user_admin_color = get_user_meta(get_current_user_id(), 'admin_color', true);

    echo '<pre>';
    var_dump($_wp_admin_css_colors[$user_admin_color]->colors);
    echo '</pre>';
  }
endif;

Feel free to vary the action hook to fit your needs: maybe admin_notices is to specific, so you may also try something like admin_head.

Moreover $_wp_admin_css_colors[$user_admin_color] is holding even more meta data about the current admin color scheme:

  • [name] Name of the current admin color scheme
  • [url] Absolute path to the current color scheme CSS file
  • [colors] Colors of the current admin color scheme
  • [icon_colors] Icon colors of the current admin color scheme

Leave a Comment

tech