I know how to print the current color scheme by using:

echo get_user_option( 'admin_color', get_current_user_id() );

or

echo get_user_meta(get_current_user_id(), 'admin_color', true);

but I need to print a specific color of this scheme. In other words I want the $colors array of this function:

<?php wp_admin_css_color( $key, $name, $url, $colors, $icons ); ?>

I have to use colors in the setting page of my plugin but I want to be coherent. Any solution is greatly appreciated!

1 Answer
1

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 Reply

Your email address will not be published. Required fields are marked *