1

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');

2 Answers 2

1
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');
1
  • Using is_super_admin() instead of current_user_can('level_10') would make this code a bit more clear. Commented Apr 6, 2012 at 15:44
0
if (is_super_admin())
{
    add_action('wp_enqueue_scripts', 'load_grid');
}

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

1
  • Thanks but that results in - PHP Fatal error: Call to undefined function wp_get_current_user()
    – Andrew
    Commented Apr 6, 2012 at 10:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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