How to Get the Admin Color Scheme From a WordPress User’s Profile

While designing the new MD Admin Panel I needed to come up with a way to make the panel look a little creative without going too over-the-top on the design.

Then it dawned on me that WordPress introduced multiple admin color schemes not too long ago and I went off to the races to figure out how I could use that color data myself to reuse.

After digging around, it turns out it’s pretty easy:

<?php
    global $_wp_admin_css_colors;

    $admin_color = get_user_option( 'admin_color' );
    $colors      = $_wp_admin_css_colors[$admin_color]->colors;
?>

For use in any PHP function or file. Mind your php tags.

Let’s break it down a little bit:

  1. Call the $_wp_admin_css_colors global variable to get Admin Color Scheme data.
  2. Get the user’s current color scheme choice as set in their profile and store it in the $admin_color variable.
  3. Using the $admin_color variable, trickle down the object to get a list of the admin colors hex codes and store in the $colors variable:
Array
(
    [0] => #222
    [1] => #333
    [2] => #0073aa
    [3] => #00a0d2
)

See for yourself: <?php print_r( $colors ); ?>

From there you can pick any color down the list by echo’ing the Array item:

<?php echo $color[2]; ?>

The best part is that the colors will update based on a user’s color choice, so your colors will always stay consistent with any Admin Color Scheme.

About Alex

The 26 year old creator of Marketers Delight.

Skin in the Game

Read: June 2018

Get this book

Skin in The Game

by Nassim Nicholas Taleb

When I bought Skin in the Game by Nicholas Taleb, I didn’t fully understand what the book was about as I was more drawn to Taleb’s personality and witty insights from Twitter. But shortly after reading the most informative Preface of a book I’ve ever picked up, I realized what an important book Skin in the Game is for anybody who makes decisions or creates something in the modern world.

The basic idea of having Skin in the Game is that you have a personal investment tied to the outcome of an opinion, a business, and decisions over others; that if you are to make decisions that affect others, you are best and most fairly suited to do so where the results directly impact you.

Taleb illustrates these concepts brilliantly with examples ranging from the “politicians in the air-conditioned rooms” to looking deeper at the famous Golden Rule and why the Silver Rule may be a more robust way to treat others.

As of writing this (June 28, 2018) I’m about halfway through the book and know I will reread this many times in my life as the ideas are refreshingly new but have implications that will help you navigate the world in a more realistic and honest way.

×