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.

My plugin displays its output into a thickbox 'window', the contents of which are generated in load-edit.php. This is a completely bare page, but I want to use some of the admin css styles so that it integrates nicely with the rest of the UI. I can't do a regular admin_enqueue_scripts because nothing from wordpress is loaded anywhere. Now I'm already polling for the user admin styles, but I then need to check whether there's a .min.css available of the stylesheet (noticed in an older version that it's not), which I could do with file_exists(), but that needs an absolute path... which I don't have. I have get_site_url() but that only give the base url, not the part that's usually called 'wp-admin' (assuming here that this is something that could be different if the user installed it differently?).

here's what I'm trying to get working:

$adminbaseurl = /* this is what I'm mising */;
if (get_user_option('admin_color') == "classic") {
    if (file_exists($adminbaseurl . 'css/colors-classic.min.css')) {
        $colorschemeurl = $adminbaseurl . 'css/colors-classic.min.css';
    } else {
        $colorschemeurl = $adminbaseurl . 'css/colors-classic.css';
    }
} else {        
    if (file_exists($adminbaseurl . 'css/colors-fresh.min.css')) {
        $colorschemeurl = $adminbaseurl . 'css/colors-fresh.min.css';
    } else {
        $colorschemeurl = $adminbaseurl . 'css/colors-fresh.css';
    }
}

to be used later as:

<link rel='stylesheet' type='text/css' href='<?php echo $colorschemeurl; ?>' />

I guess the most simple answer could be that the wp-admin folder is ALWAYS called wp-admin, but I couldn't find that out...


Edit: looks like I can't use get_site_url anyway, since file_exists only takes the local path...

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

Directly answering your question, you should be able use the function admin_url() to get the base URL for the admin folder, and ABSPATH . 'wp-admin' to get the local file path to that folder. Certainly, the WordPress code itself doesn't expect the admin folder to be named anything different.

However, you should be able to enqueue those styles by style handle (thus forgetting about file_exists() calls) if you do this in your PHP file behind Thickbox:

require_once(ABSPATH . 'wp-admin/admin.php');
share|improve this answer
    
Brilliant! That was easy... just to be complete for anyone else looking for this, you can do wp_enqueue_style( 'colors' ); and then do_action('admin_print_styles'); directly after that and boom your done. Thanks webaware! –  Ewout Jan 23 '13 at 17:52
add comment

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.