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 made a little plugin that enqueues 1 .js file and 1 .css file into a theme's front-end. All it does it load a grid on top of the theme so I can visualise the design.

If this plugin was activated on a live site, is it possible that only I (the super admin) can see the JS and CSS files included onto the front-end?

All I have inside the plugin file is this:

function load_grid() {
    wp_enqueue_style('grid_css', plugins_url('/lib/css/grid.css', __FILE__) );
    wp_enqueue_script('grid_js', plugins_url('/lib/js/grid.js', __FILE__), array('jquery') );
}
add_action('wp_enqueue_scripts', 'load_grid');
share|improve this question
add comment

2 Answers

up vote 1 down vote accepted
function load_grid() {
    if ( current_user_can( 'level_10' ) ) {
        wp_enqueue_style('grid_css', plugins_url('/lib/css/grid.css', __FILE__) );
        wp_enqueue_script('grid_js', plugins_url('/lib/js/grid.js', __FILE__), array('jquery') );
    }
}
add_action('wp_enqueue_scripts', 'load_grid');
share|improve this answer
    
Thanks this worked –  Andrew Apr 6 '12 at 10:33
    
Using is_super_admin() instead of current_user_can('level_10') would make this code a bit more clear. –  Sam Margulies Apr 6 '12 at 15:44
add comment
if (is_super_admin())
{
    add_action('wp_enqueue_scripts', 'load_grid');
}

http://codex.wordpress.org/Function_Reference/is_super_admin

share|improve this answer
    
Thanks but that results in - PHP Fatal error: Call to undefined function wp_get_current_user() –  Andrew Apr 6 '12 at 10:32
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.