WordPress current user admin enqueue scripts

I’m having a problem to solve, I need to include a CSS file in my WordPress admin just when the user have a specific role.

I’m having a problem because I don’t know how I can do this, follow my code from now!

Read More
    function RequireBootstrap($current_user){
    global $WP_User;
    if( in_array( $_GET['page'], array("abeta", "custom-user") , TRUE)):
        wp_register_style('Bootstap_CSS', RequireURL('Library/Bootstrap/css/bootstrap.css') );
        wp_enqueue_style( 'Bootstap_CSS');

        wp_register_script( 'Bootstap_JS', RequireURL('Library/Bootstrap/js/bootstrap.min.js'), '1.0.0', true );
        wp_enqueue_script( 'Bootstap_JS' );
    endif;

    $current_user = wp_get_current_user();
    if('associado' == $current_user->caps):
        wp_register_style( 'CSSPrincipal', RequireURL('Admin/CSS/Style.css'), '1.0.0', true );
        wp_enqueue_style( 'CSSPrincipal' );
    endif;
}
add_action('admin_enqueue_scripts',  'RequireBootstrap', 10, 3);

I hope you can help me!

Thanks!

Related posts

1 comment

  1. You should use the current_user_canfunction.

    Then pass in a parameter of the role you want.

    e.g:

    current_user_can('Administrator')
    

Comments are closed.