Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to get the stylesheet of the currently active admin color scheme to style a plugin to fit into the color context.

As mentioned in this post I had a look at the implementation of admin_color_scheme_picker() in wp-admin/includes/misc.php:564. They use a global variable called $_wp_admin_css_colors but when I try to access (var_dump()) it, it's NULL.

Is there any way to access to actual CSS code?

Why is the global variable NULL? I did a grep -n '$_wp_admin_css_colors' -r . and couldn't find any line where it gets destroyed...

EDIT

I see it wasn't clear what I exactly want. I don't want to access the actual CSS code, but the color codes that gets parsed into CSS. In wp-includes/general-template.php:2117 the default themes are registered like this:

wp_admin_css_color( 'fresh', _x( 'Default', 'admin color scheme' ),
    admin_url( "css/colors$suffix.css" ),
    array( '#222', '#333', '#0074a2', '#2ea2cc' ),
    array( 'base' => '#999', 'focus' => '#2ea2cc', 'current' => '#fff' )
);

And I'd like to access the variables like this in PHP. Copying the definition is not an option, since other plugins and themes could add their theme themselves.

share|improve this question

2 Answers 2

I actually made it!

In my script file, at the to I define a new variable and copy the $_wp_admin_css_colors variable into it using the admin_head hook, since the variable gets destroyed at some later point:

<?php
    global $admin_colors; // only needed if colors must be available in classes
    add_action('admin_head', function() {
        global $_wp_admin_css_colors;
        global $admin_colors; // only needed if colors must be available in classes
        $admin_colors = $_wp_admin_css_colors;
    });

    // more script content...
?>
share|improve this answer

The color scheme is stored as user meta:

$color = get_user_meta(get_current_user_id(), 'admin_color', true);

However, the CSS file seems to be generated when having chosen another scheme.

So you just need this:

$admin_css_file = wp_admin_css_uri('css/colors');
share|improve this answer
1  
Please re-read my answer, I clarified, what I really wanted :) –  Julian Jan 23 at 17:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.